The Perl driver supports dynamic SQL, including parameter usage.
For example:
$sth = $dbh->prepare("select * from employee where empno = ?"); # Retrieve rows from employee where empno = 1024: $sth->execute(1024); while($data = $sth->fetch) { print "@$data\n"; } # Now get rows where empno = 2000: $sth->execute(2000); while($data = $sth->fetch) { print "@$data\n"; }
DBD::SybaseASE uses the Open Client ct_dynamic() family of APIs for the prepare() method. See the Sybase Open Client C Programmers guide for information about "?" style placeholder constraints and general dynamic SQL usage.
my $rc; my $dbh; my $sth; # call do() method to execute a SQL statement. # $rc = $dbh->do("create table tt(string1 varchar(20), date datetime, val1 float, val2 numeric(7,2))"); $sth = $dbh->prepare("insert tt values(?, ?, ?, ?)"); $rc = $sth->execute("test12", "Jan 3 2012", 123.4, 222.33); # alternate way, call bind_param() then execute without values in the # execute statement. $rc = $sth->bind_param(1, "another test"); $rc = $sth->bind_param(2, "Jan 25 2012"); $rc = $sth->bind_param(3, 444512.4); $rc = $sth->bind_param(4, 2); $rc = $sth->execute(); # and another execute, with args..... $rc = $sth->execute("test", "Feb 30 2012", 123.4, 222.3334);
Another example that illustrates the "?" style placeholder:
$sth = $dbh->prepare("select * from tt where date > ? and val1 > ?"); $rc = $sth->execute('Jan 1 2012', 120); # go home.... $dbh->disconnect; exit(0);