FreeTDS API
|
Functions called within db-lib
for self-help.
More...
Classes | |
struct | _dblib_error_message |
Typedefs | |
typedef struct _dblib_error_message | DBLIB_ERROR_MESSAGE |
Functions | |
static BYTE * | _dbcoldata (TDSCOLUMN *colinfo) |
Return data from a column. | |
int | _dblib_check_and_handle_interrupt (void *vdbproc) |
check interrupts for libtds. | |
RETCODE | dbcmdrow (DBPROCESS *dbproc) |
See if the current command can return rows. | |
static TDSCOLUMN * | dbcolptr (DBPROCESS *dbproc, int column) |
Sanity checks for column-oriented functions. | |
int | dbcurcmd (DBPROCESS *dbproc) |
Get number of the row just returned. | |
DBINT | dbcurrow (DBPROCESS *dbproc) |
Get number of the row currently being read. | |
DBBOOL | dbdead (DBPROCESS *dbproc) |
Check if dbproc is an ex-parrot. | |
DBINT | dbfirstrow (DBPROCESS *dbproc) |
See if a server response has arrived. | |
int | dbiordesc (DBPROCESS *dbproc) |
Get file descriptor of the socket used by a DBPROCESS to read data coming from the server. (!) | |
int | dbiowdesc (DBPROCESS *dbproc) |
Get file descriptor of the socket used by a DBPROCESS to write data coming to the server. (!) | |
DBINT | dblastrow (DBPROCESS *dbproc) |
Get number of the last row in the row buffer. | |
int | dbperror (DBPROCESS *dbproc, DBINT msgno, long errnum,...) |
Call client-installed error handler. | |
RETCODE | dbrows (DBPROCESS *dbproc) |
Indicate whether a query returned rows. | |
STATUS | dbrowtype (DBPROCESS *dbproc) |
Get returned row's type. | |
void | dbsetavail (DBPROCESS *dbproc) |
Mark a DBPROCESS as "available". | |
RETCODE | dbsetlbool (LOGINREC *login, int value, int which) |
Set a boolean value in a LOGINREC structure. | |
RETCODE | dbsetllong (LOGINREC *login, long value, int which) |
Set an integer value in a LOGINREC structure. | |
RETCODE | dbsetlname (LOGINREC *login, const char *value, int which) |
Set the value of a string in a LOGINREC structure. | |
RETCODE | dbsetlshort (LOGINREC *login, int value, int which) |
Set an integer value in a LOGINREC structure. | |
int | dbtds (DBPROCESS *dbproc) |
Get the TDS version in use for dbproc. | |
static int | default_err_handler (DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) |
default error handler for db-lib (handles library-generated errors) | |
DBPROCESS * | tdsdbopen (LOGINREC *login, const char *server, int msdblib) |
Form a connection with the server. | |
Functions called within db-lib
for self-help.
These functions are of interest only to people hacking on the FreeTDS db-lib implementation.
typedef struct _dblib_error_message DBLIB_ERROR_MESSAGE |
|
static |
Return data from a column.
colinfo | contains information on a result column. |
int _dblib_check_and_handle_interrupt | ( | void * | vdbproc | ) |
check interrupts for libtds.
vdbproc | a DBPROCESS pointer, contains all information needed by db-lib to manage communications with the server. |
RETCODE dbcmdrow | ( | DBPROCESS * | dbproc | ) |
See if the current command can return rows.
dbproc | contains all information needed by db-lib to manage communications with the server. |
SUCCEED | Yes, it can. |
FAIL | No, it can't. |
Sanity checks for column-oriented functions.
dbproc | contains all information needed by db-lib to manage communications with the server. |
pcolinfo | address of pointer to a TDSCOLUMN structure. |
int dbcurcmd | ( | DBPROCESS * | dbproc | ) |
Get number of the row just returned.
dbproc | contains all information needed by db-lib to manage communications with the server. |
DBINT dbcurrow | ( | DBPROCESS * | dbproc | ) |
Get number of the row currently being read.
dbproc | contains all information needed by db-lib to manage communications with the server. |
0 | Always. |
DBBOOL dbdead | ( | DBPROCESS * | dbproc | ) |
Check if dbproc is an ex-parrot.
dbproc | contains all information needed by db-lib to manage communications with the server. |
TRUE | process has been marked dead. |
FALSE | process is OK. |
FALSE
. DBINT dbfirstrow | ( | DBPROCESS * | dbproc | ) |
See if a server response has arrived.
dbproc | contains all information needed by db-lib to manage communications with the server. |
milliseconds | how long to wait for the server before returning:
|
ready_dbproc | output: DBPROCESS for which a response arrived, of NULL . |
return_reason | output:
|
SUCCEED | everything worked. |
FAIL | a server connection died. |
Get number of the first row in the row buffer.
dbproc | contains all information needed by db-lib to manage communications with the server. |
int dbiordesc | ( | DBPROCESS * | dbproc | ) |
Get file descriptor of the socket used by a DBPROCESS
to read data coming from the server. (!)
dbproc | contains all information needed by db-lib to manage communications with the server. |
int dbiowdesc | ( | DBPROCESS * | dbproc | ) |
Get file descriptor of the socket used by a DBPROCESS
to write data coming to the server. (!)
dbproc | contains all information needed by db-lib to manage communications with the server. |
DBINT dblastrow | ( | DBPROCESS * | dbproc | ) |
Get number of the last row in the row buffer.
dbproc | contains all information needed by db-lib to manage communications with the server. |
int dbperror | ( | DBPROCESS * | dbproc, |
DBINT | msgno, | ||
long | errnum, | ||
... | |||
) |
Call client-installed error handler.
dbproc | contains all information needed by db-lib to manage communications with the server. |
msgno | identifies the error message to be passed to the client's handler. |
errnum | identifies the OS error (errno), if any. Use 0 if not applicable. |
If the client-installed handler returns something other than these four INT_* values, or returns timeout-related value for anything but SYBETIME, it's treated here as INT_EXIT (see above).
Instead of sprinkling error text all over db-lib, we consolidate it here, where it can be translated (one day), and where it can be mapped to the TDS error number.
The libraries don't use consistent error numbers or messages, so when libtds has to emit an error message, it can't include the text. It can pass its error number to a client-library function, which will interpret it, add the text, call the application's installed handler (if any) and return the handler's return code back to the caller.
The call stack may look something like this:
The error handling in this case is unambiguous: the caller invokes this function, the client's handler returns its instruction, which the caller receives. Quite often the caller will get INT_CANCEL, in which case it should put its house in order and return FAIL.
The call stack may otherwise look something like this:
Because different client libraries specify their handler semantics differently, and because libtds doesn't know which client library is in charge of any given connection, it cannot interpret the raw return code from a db-lib error handler. For these reasons, libtds calls _dblib_handle_err_message, which translates between libtds and db-lib semantics.
RETCODE dbrows | ( | DBPROCESS * | dbproc | ) |
Indicate whether a query returned rows.
dbproc | contains all information needed by db-lib to manage communications with the server. |
STATUS dbrowtype | ( | DBPROCESS * | dbproc | ) |
Get returned row's type.
dbproc | contains all information needed by db-lib to manage communications with the server. |
void dbsetavail | ( | DBPROCESS * | dbproc | ) |
Mark a DBPROCESS
as "available".
dbproc | contains all information needed by db-lib to manage communications with the server. |
FreeTDS
behaves the way Sybase's implementation does, but so what? db-lib
functions set the DBPROCESS
to "not available", but only dbsetavail() resets it to "available". RETCODE dbsetlbool | ( | LOGINREC * | login, |
int | value, | ||
int | which | ||
) |
Set a boolean value in a LOGINREC
structure.
Called by various macros to populate login.
login | the LOGINREC* to modify. |
value | the value to set it to. |
which | the field to set. |
SUCCEED | the value was set. |
FAIL | invalid value passed for which. |
RETCODE dbsetllong | ( | LOGINREC * | login, |
long | value, | ||
int | which | ||
) |
Set an integer value in a LOGINREC
structure.
Called by various macros to populate login.
login | the LOGINREC* to modify. |
value | the value to set it to. |
which | the field to set. |
SUCCEED | the value was set. |
FAIL | anything other than DBSETPACKET was passed for which. |
RETCODE dbsetlname | ( | LOGINREC * | login, |
const char * | value, | ||
int | which | ||
) |
Set the value of a string in a LOGINREC
structure.
Called by various macros to populate login.
login | the LOGINREC* to modify. |
value | the value to set it to. |
which | the field to set. |
SUCCEED | the value was set. |
FAIL | DBSETHID or other invalid which was tried. |
RETCODE dbsetlshort | ( | LOGINREC * | login, |
int | value, | ||
int | which | ||
) |
Set an integer value in a LOGINREC
structure.
Called by various macros to populate login.
login | the LOGINREC* to modify. |
value | the value to set it to. |
which | the field to set. |
SUCCEED | the value was set. |
FAIL | if invalid field in which or invalid value. |
int dbtds | ( | DBPROCESS * | dbproc | ) |
Get the TDS version in use for dbproc.
dbproc | contains all information needed by db-lib to manage communications with the server. |
DBTDS*
token.
|
static |
default error handler for db-lib (handles library-generated errors)
The default error handler doesn't print anything. If you want to see your messages printed, install an error handler. If you think that should be an optional compile- or run-time default, submit a patch. It could be done.
Form a connection with the server.
Called by the dbopen()
macro, normally. If FreeTDS was configured with --enable-msdblib
, this function is called by (exported) dbopen()
function. tdsdbopen
is so-named to avoid namespace conflicts with other database libraries that use the same function name.
login | LOGINREC* carrying the account information. |
server | name of the dataserver to connect to. |
NULL | insufficient memory, unable to connect for any reason. |
use asprintf()
to avoid buffer overflow.
separate error messages for no-such-server and no-such-user.