5. Working with a Database : Handling Database Errors : How You Can Handle DataStream Errors
 
Share this page                  
How You Can Handle DataStream Errors
All DataStream methods that access the database return status information. These methods are:
Method
Objects Returning Status Information
Open
SQLSelect and QueryObject objects
SetCols
SQLSelect objects
Close
SQLSelect and QueryObject objects (this method accesses the database only when the object was opened in QY_CURSOR or QY_DIRECT mode)
NextRow
SQLSelect and QueryObject objects (this method accesses the database only when the object was opened in QY_CURSOR or QY_DIRECT mode)
DBInsert
QueryObject objects
DBUpdate
QueryObject objects
DBDelete
QueryObject objects
Two methods are exceptions to the general descriptions of return status. One is the Close method, which does not return a status. The other is the NextRow method, which returns either ER_OK when successful, if no breaks have been set, or a number that represents the break level if breaks have been added to the DataStream. If the NextRow method is unsuccessful, it returns ‑1 and sets the ErrorNo attribute either to the error that was encountered, or 0 if there is no next row to retrieve.
If a database operation was successful, the value of the returned status and DataStream's ErrorNo attribute is ER_OK. If the operation was unsuccessful, the ErrorNo attribute contains the triggering error number. Because the ErrorNo attribute can be set by operations that fail in the client and the DBMS, use the value in the IsDBError attribute to determine whether the error occurred in the DBMS.
In addition to the ErrorNo and IsDBError attributes available to all DataStream objects, the QueryObject subclass provides the ZeroRowIsError parameter to the methods that access the DBMS (DBInsert, DBUpdate, and DBDelete).
By default, not finding any rows that satisfy an insert, update, or delete query (and therefore not changing the queried table) does not cause an error. If you want this situation to be considered an error, set the ZeroRowIsError parameter to TRUE.
For an example of error-checking while opening a DataStream object, see How You Can Run the SQLSelect Query (see How You Can Run the SQLSelect Query). For an example using the ZeroRowIsError parameter, see How You Can Update Data with a Query Object (see How You Can Update Data with a Query Object).