$dbproc = &dblogin([$user[, $pwd[, $server]]]) $dbproc1 = &dbopen([$server]) &dbclose($dbproc) $ret = &dbcmd($dbproc, $sql_cmd) $ret = &dbsqlexec($dbproc) $ret = &dbresults($dbproc) @data = &dbnextrow($dbproc [, $doAssoc]) $ret = &dbuse($dbproc, $database) $ret = &dbcancel($dbproc) $ret = &dbcanquery($dbproc) $ret = &dbexit($dbproc) $string = &dbstrcpy($dbproc) $string = &dbsafestr($dbproc,$instring[,$quote_char]) $status = &dbwritetext($dbproc_1, $col_name, $dbproc_2, $select_col, $text) $ret = &dberrhandle($handler) $ret = &dbmsghandle($handler) $SUCCEED $FAIL $NO_MORE_ROWS $NO_MORE_RESULTS $ComputeId $DBstatus $SybperlVer $DBReturnAssoc
The following functions are provided:
$dbproc = &dblogin([$user[, $pwd[, $server]]]) &dbproc1 = &dbopen([$server]) &dbclose($dbproc) $status = &dbcmd($dbproc, $sql_cmd) $status = &dbsqlexec($dbproc) $status = &dbresults($dbproc) @data = &dbnextrow($dbproc [, $doAssoc]) $status = &dbuse($dbproc, $database) $status = &dbcancel($dbproc) $status = &dbcanquery($dbproc) $status = &dbexit($dbproc) $string = &dbstrcpy($dbproc) $string = &dbsafestr($dbproc,$instring[,$quote_char]) $old_handler = &dberrhandle($handler) $old_handler = &dbmsghandle($handler) $status = &dbwritetext($dbproc_1, $col_name, $select_proc, $select_col, $text)
Differences with DB-Library:
&dblogin takes 3 optional arguements (the userid, the password and the server to connect to). These default to the Unix userid, the null password and the default server (from the DSQUERY environment variable).
&dblogin returns a DBPROCESS, not a LOGINREC. This simplifies the call to open a connection to a Sybase dataserver somewhat. If the login fails for any reason &dblogin returns -1. &dblogin can be called multiple times to login to different servers, or to login as several users simultaneously.
Further DBPROCESSes can be opened using &dbopen([$server]), using the login information from the last call to &dblogin(). The number of simultaneous DBPROCESSes is limited to 25 (This can be changed by altering a #define in sybperl.c).
The $dbproc parameter used by most subroutines is optional, and defaults to the DBPROCESS returned by the first call to &dblogin (exceptions: &dbsafestr() and &dbwritetext() require explicit $dbproc parameters.)
&dbnextrow returns an array of formatted data, based on the datatype of the corresponding columns. &dbnextrow sets the variable $ComputeId when the result row is a computed row (the result of a compute by clause). If the optional $doAssoc parameter is non-zero &dbnextrow returns an associative array keyed on the column name of each returned field.
&dbsafestr takes a string literal ' or " as the third [optional] argument and means DBSINGLE or DBDOUBLE, respectively. Omission of the third argument means DBBOTH.
In order to simplify its use somewhat, the calling sequence of &dbwritetext has been changed. $select_procand $select_col are the dbproc and column number of a currently active query. Logging is always off.
The SYBIMAGE data type is not implemented.
&dbfcmd is not implemented, but can be emulated by using sprintf as in &dbcmd($dbproc, sprintf("%d", $num_val));
See the Perl(1) manual page.
Memory usage can become very large in certain conditions when using a version of Perl prior to 4.035. This can be circumvented - see the BUGS file in the Sybperl distribution.
If &dbnextrow encounters a datatype that it does not know about, it tries to convert it to SYBCHAR, and to store it in a 256 byte buffer - without checking for overflow.
The handling of multiple logins isn't really clean. A call to &dblogin sets the values for the User name and Password. These values are remembered - and used in calls to &dbopen - until they are changed in a new call to &dblogin(). It is possible to avoid the use of &dbopen alltogether, and simply call &dblogin each time a new DBPROCESS is required.
$PERLLIB/sybperl.pl should be called in all sybperl scripts to set the correct environment variables used by DB-Library. A sample $PERLLIB/sybdb.ph is provided with sybperl. You may want to use h2ph to add definitions to this file.
Perl(1L), Sybase Open Client DB Library Reference Manual, h2ph(1L).
Michael Peppler, ITF Management SA - mpeppler@itf.ch Brent Milnor (brent@oceania.com) contributed &dbwritetext(). Eric Fifer (egf@sbi.com) contributed corrections to the &dblogin()/&dbopen() sequence Mark Lawrence (mark@drd.com) contributed &dbsafestr().