Dynamic SQL Support, Placeholders, and Bind Parameters

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";
}
Note: The Perl driver supports the '?' style parameter, but not ':1' placeholder types. You cannot use placeholders to bind a text or image datatype.

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.

This is another example showing dynamic SQL support:
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);
Note: The last statement throws an extended error information (EED) as the date is invalid. In the Perl script, set dbh->{syb_show_eed} = 1 before execution to write the Adaptive Server error message in the dbh->errstr.

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);