The ITCursor class

Base class: ITErrorManager

Manages database cursors.

This class provides the following methods.
Method Description
ITCursor(const ITConnection &) Creates a cursor object for a connection.
ITBool Prepare(const ITString &, int nargs = 0, const ITString *typeNames = 0, ITEssential **outerunkns = 0); Prepare() prepares the SQL statement and creates a list of null-valued parameters. Prepare() takes as an argument an ITString object, which must be a single valid SQL statement. See The ITStatement class.
ITBool Drop() Drops the prepared statement and removes the parameter list.
int NumParams() const Returns the number of parameters in a prepared statement. It returns -1 if the statement has not been successfully prepared.
ITValue *Param(int) Allows the application to return the ITValue of a parameter . The argument is a zero-based parameter number. Param() returns NULL if there are no parameters or if the parameter number is out of bounds.
ITBool SetParam(int parmno, ITDatum *) Sets the cursor parameter with the number equal to parmno to be the value object passed as the second argument. Returns TRUE if successful, FALSE if it fails. Supports binding parameters in both binary and text mode. For more information, see the example in Usage.
const ITString &QueryText() const Returns the query text. Returns ITString::Null if the statement has not been successfully prepared.
ITBool IsReadOnly() const Returns TRUE if the cursor is read only, otherwise returns FALSE.
ITBool Open(int flags = 0, const ITString &tableName = ITString::Null) Opens a cursor with the flags taken from the sum of the Open() flag values. Flag values can be the sum of:
  • ITCursor::Sensitive
  • ITCursor::ReadOnly
  • ITCursor::Scrollable
  • ITCursor::Reopt
  • ITCursor::Hold

Calling Open() without arguments opens a nonscrollable cursor. Open() returns TRUE on success, FALSE otherwise. It is an error for a cursor to be both scrollable and can be updated. If updates are performed by using the cursor, tableName must be passed as the second argument.

ITBool Close() Closes the cursor. After calling Close(), the application can modify parameters and open a new cursor.
const ITString &Command() const Returns the command verb.
const ITString &Name() const Returns the name of the cursor. Returns ITString::Null if the cursor has not been opened successfully.
ITRow *NextRow(ITEssential **outerunkn = NULL, enum ITPosition pos = ITPositionNext, long jump = 0) Fetches the next row and returns the pointer to the ITRow interface of the row object. Returns NULL if the row cannot be fetched. Until the cursor row is modified or deleted, a new instance of that row can be fetched again by specifying fetch position ITPositionCurrent even if the cursor is not scrollable.
ITBool UpdateCurrent() Executes the SQL statement UPDATE WHERE CURRENT OF using the values of the updated columns in the current row. Returns TRUE if the update was successful and FALSE if it was not. It is an error for the application to call UpdateCurrent() if NextRow() or a fetch function fails.
ITBool DeleteCurrent() Executes the SQL statement DELETE WHERE CURRENT OF. Returns TRUE if the deletion was successful and FALSE if it was not. It is an error for the application to call DeleteCurrent() if NextRow() or a fetch function fails.
ITValue *Fetch(ITEssential **outerunkn = NULL, enum ITPosition pos = ITPositionNext, long jump = 0) Fetches a row from the cursor and returns the pointer to its ITValue interface.
const ITTypeInfo *RowType() const Returns server type information about the row to be fetched. Can be called after Prepare() to get row type information before opening the cursor.
ITBool IsScrollable() const Returns TRUE if the cursor is opened as scrollable, otherwise returns FALSE.

Usage

ITCursor can pass binary data as parameters in prepared SQL SELECT statements. In addition, ITStatement can pass binary data as parameters in prepared SQL DML statements DELETE, INSERT, UPDATE, and SELECT. For an example showing how can be used to set a parameter to binary data in a prepared INSERT statement, see Usage