Tips_sql   >   Sql   >   SQL Problem Solving
It's a good idea to add a $sqlerror handler method in your base superclass table class.
The built-in table class method call the $sqlerror method if it hits an error.
The following is the code from my base table superclass $sqlerror method.
Switch pkErrorType
Case kTableSelectError
Calculate ErrType as 'Select Error'
Calculate ErrCode as $cinst.$statementobject.$errorcode
If ErrCode=0
; This just means that the select came up with no records. Not an error.
Quit method kTrue
End If
Case kTableFetchError
Calculate ErrType as 'Fetch Error'
Case kTableUpdateError
Calculate ErrType as 'Update Error'
Case kTableDeleteError
Calculate ErrType as 'Delete Error'
Case kTableInsertError
Calculate ErrType as 'Insert Error'
Case kTableGeneralError
Calculate ErrType as 'General Error'
Default
Calculate ErrType as 'Unknown Error'
End Switch
; Copy the row to a local row variable.
Calculate Row as $cinst
Calculate SQLClassName as $cinst.$sqlclassname
Calculate Mssg as con("SQL Error: ",ErrType,", SQL Class Name: ",SQLClassName)
Calculate Dtls as con("SQL Error: ",$cinst.$statementobject.$nativeerrorcode," - ",$cinst.$statementobject.$nativeerrortext,", SQL Text: ",$cinst.$statementobject.$sqltext)
Breakpoint
; Log the error.
Do errhndlr.$logSQLError($cmethod,Mssg,Dtls)
Quit method kFalse
Fetch only brings back one record into your list variable.
If you are trying to select LastName = O'Sullivan, the single quote character can give you grief. Use of bind variables will eliminate the problem.
A weaker solution is to replace all the single and double quote characters with underscore characters so that LastName = O_Sullivan. In SQL the underscore character is a single character wildcard.You can insert the first record in a table, but you can't insert a second record.
Check the unique index field(s) in the table. You might be trying to insert a second record with the same primary key.You are unable to insert any records into a table.
If you find you can insert records but can't update old records: