Syntax
INT = dbGetPrev(hstmt as INT)
Description
Gets the previous record from a result set.
Parameters
hstmt - A statement handle returned by dbExecSQL or dbPrepareSQL
Return value
TRUE if the record was retrieved and any bound variables filled in with column data. FALSE if the beginning of the result set was reached or there were no records in the result set.
Remarks
dbGetNext and dbGetPrev may not work with all database drivers, some text based drivers only support sequential access with the dbGet command. A column that is nullable and currently set to NULL can be determined by dbIsNull after a dbGet operation. A NULL value can also be determined by checking the optional 'pReturn' variable used when binding the column with dbBindVariable.
See Also: dbGetNext, dbExecSQL, dbPrepareSQL, dbGet
Example usage
hstmt = dbExecSQL(pdb,"SELECT * FROM Addresses")
error = dbGetErrorCode(hstmt)
IF LEN(error)
PRINT
PRINT "Error Code: ", error
PRINT "Error Text: ", dbGetErrorText(hstmt)
PRINT
ENDIF
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)
dbBindVariable(hstmt,4,street)
dbBindVariable(hstmt,5,city)
dbBindVariable(hstmt,6,state)
dbBindVariable(hstmt,7,zip)
'dbGetNext returns TRUE if data has been retrieved and stored
'in the bound variables. Or FALSE if the end of data has been reached or an error occured
WHILE dbGetNext(hstmt)
PRINT "ID:",Address_ID
PRINT first," ",last
PRINT street
IF dbIsNull(hStmt,5) = FALSE
PRINT city, "," ,state, " ", zip
ENDIF
PRINT
ENDWHILE
'Now print them in reverse order
WHILE dbGetPrev(hstmt)
PRINT "ID:",Address_ID
PRINT first," ",last
PRINT street
IF dbIsNull(hStmt,5) = FALSE
PRINT city, "," ,state, " ", zip
ENDIF
PRINT
ENDWHILE
dbFreeSQL(hstmt)
ENDIF
|