dbBindVariable

Top  Previous  Next

Syntax

INT = dbBindVariable(hstmt as INT,column as INT,variable as ANYTYPE,opt pReturn as POINTER,opt cbSize as INT)

Description

Binds a variable to a column in a result set.

Parameters

hstmt - A statement handle returned by dbExecSQL.

column - The ones based column to bind.

variable - The variable that will receive the data from the bound column.

pReturn - Optional. Pointer to an INT.

cbSize - Optional. For strings and binary data specifies maximum length.

Return value

TRUE if variable successfully bound to column. FALSE on error.

Remarks

The variable passed to the optional pReturn value will contain an indicator of the operation after each dbGet, dbGetNext or dbGetPrev operation.  The variable can then be checked against SQL_NULL_DATA or SQL_NO_TOTAL.  It is easier to use the dbIsNull function for checking for a NULL column. Some database drivers won't allow using dbIsNull against bound columns and this provides an alternative.

Each bound variable will be filled in with the data contained in the record retrieved with dbGet, dbGetNext or dbGetPrev.

cbSize defaults to 255.  Binary data can be retrieved by using a UDT and setting cbSize to the length of the UDT.

See Also: dbBindTime, dbBindDate, dbBindTimeStamp

Example usage

DEF first,last as STRING
DEF Address_ID as INT
...
hstmt = dbExecSQL(pdb,"SELECT * FROM Addresses")
IF hStmt
    'bind the columns in the table to appropriate variables
    'column numbers start at 1 starting from the left.
 
    dbBindVariable(hstmt,1,Address_ID)
    dbBindVariable(hstmt,2,first)
    dbBindVariable(hstmt,3,last)
    WHILE dbGet(hstmt)
        PRINT "ID:",Address_ID
        PRINT "Name:",first,last
    ENDWHILE
ENDIF