SQLitening Support Forum

Please login or register.

Login with username, password and session length
Advanced search  


Welcome to the SQLitening support forums!

Author Topic: Error Handling  (Read 4736 times)

Fred Meier

  • Master Geek
  • ****
  • Posts: 806
    • View Profile
Error Handling
« on: December 01, 2009, 02:07:40 PM »

Many of SQLitening commands are functions which return zero if they worked
OK or non zero if they failed.  If they failed in SQLite then the return
value will be positive;  if it failed in SQLitening the value  will be negative. 
The error codes are listed at the end of this post. 

Most of the errors are severe -- that is neither your code nor your user
can fix the problem and try again.  Therefore the default SQLitening
action for error handling is to display a message and then exit the
process by calling the WinAPI ExitProcess.  This is the same API that is
called when your program ends it Main function.  There is the following
comment in the MS documentation which is just saying that your application
program will not be able to do any shutdown processing when SQLitening
does the ExitProcess. 
Calling ExitProcess in a DLL can lead to unexpected application or system
errors.  Be sure to call ExitProcess from a DLL only if you know which
applications or system components will load the DLL and that it is safe to
call ExitProcess in this context. 

This is the way I code all my programs, allowing SQLitening to handle all
errors.  There are two main advantages in letting SQLitening handle the
errors: 1) You don't have to write code to handle them and 2) You know
that all errors will be caught and stopped (VERY IMPORTANT--I have
reviewed many snippets of code where errors are being returned but there
is no code to catch them). 

If you have a good reason for not wanting SQLitening to handle the errors
then you can request to have the errors returned to your program for
processing.  There are three levels you can choose from:

   1. You can have some of the commands return the error and let SQLitening
   handle the other commands.  This is done by adding the "E" ModChar to the
   commands you want errors returned.

   2. You can change the default error processing to return errors by doing the
   slSetProcessMods "E" command.  Now all commands will return errors.  If there
   is a command that you want SQLitening to handle the error then add the "e"
   ModChar to that command.
   3. You can re-compile SQLitening, setting the conditional compile flag
   %ReturnAllErrors to %True.  This will change the default error processing to
   return all errors, just like 2 above, but without having to call slSetProcessMods
   each time.  Note: This will set the default to E0, if you want E1 or E2 then
   you would have to be add that code to SQLitening.

Once you decide to not use the default error processing then you must decide to
use E0(same as plan E) or E1 or E2. 
   E0 = No message is displayed.  Error is returned immediately. This is the default.
         Note that E and E0 are the same.
   E1 = Display a warning message with OK button.  Error is returned when OK pressed.
   E2 = Display a question message with OK and Cancel buttons. If they press OK,
         error is returned.  If they press Cancel, will exit process.

Error Codes
Code: [Select]
=====================<[ SQLitening Error Codes ]>=====================
%SQLitening_NoOpenDatabase          =  -7 - No open database
%SQLitening_AccessDenied            =  -8 - Access denied
                                             -- Connect was able to do Tcp Open but was unable to "talk"
                                                to SQLitening service. Probable caused by some type of
                                                firewall setting or an exit has denied connection.
                                             -- Open, Attach, GetFile, or PutFile password check failed or
                                                the file is protected.
%SQLitening_FileDoesNotExist        =  -9 - File does not exist
%SQLitening_FileOpenGetPutError     = -10 - File error doing open, get, or put
%SQLitening_LockTimeout             = -11 - Timeout occurred trying to lock an object or database
%SQLitening_NochangedRows           = -12 - No changed rows
%SQLitening_InvalidColumnNameNumber = -13 - Invalid column name or number
%SQLitening_InvalidSetNumber        = -14 - Invalid set number
%SQLitening_AttachIsInvalid         = -15 - Can not use SQL Attach
%SQLitening_CanNotConnect           = -16 - Can not connect
                                             -- Tcp Open failed.
%SQLitening_InvalidKeyOrNotFound    = -17 - Invalid key or key not found
                                             -- Ini GetFile section or entity not found.
                                             -- Ini PutFile WritePrivateProfileString winapi failed.
                                             -- Encrypt key must be set and must be 16, 24, or 32 bytes.
%SQLitening_SendOrReceiveError      = -18 - Error sending or receiving message"
                                             -- Prior connect failed, server went away, TCP time-out, or message length error
%SQLitening_InvalidStringOrRequest  = -19 - Invalid string or request
                                             -- Uncompressing string which is not compressed.
                                             -- String is too big to compress.
                                             -- BindDat is invalid.
                                             -- RunProc is invalid library or entry.
%SQLitening_ErrorAtServer           = -20 - An error occured at server -- check server log.

=======================<[ SQLite Error Codes ]>=======================
     0 = Successful result
     1 = SQL error or missing database
     2 = Internal logic error in SQLite
     3 = Access permission denied
     4 = Callback routine requested an abort
     5 = The database file is locked
     6 = A table in the database is locked
     7 = A malloc() failed
     8 = Attempt to write a readonly database
     9 = Operation terminated by sqlite3_interrupt()
    10 = Some kind of disk I/O error occurred
    11 = The database disk image is malformed
    12 = NOT USED. Table or record not found
    13 = Insertion failed because database is full
    14 = Unable to open the database file
    15 = NOT USED. Database lock protocol error
    16 = Database is empty
    17 = The database schema changed
    18 = String or BLOB exceeds size limit
    19 = Abort due to constraint violation
         ' Normally caused by trying to add a non unique key
         ' to an index during an Insert or Update.
    20 = Data type mismatch
    21 = Library used incorrectly
    22 = Uses OS features not supported on host
    23 = Authorization denied
    24 = Auxiliary database format error
    25 = 2nd parameter to sqlite3_bind out of range
    26 = File opened that is not a database file
   100 = sqlite_step() has another row ready
   101 = sqlite_step() has finished executing