General Sql Error Check Sqlca.sqlerrd 2
Contents |
registers. Trapping SQL errors By default, SQL errors stop program execution and display the error message to the standard output. Most SQL statements executed by a program should not return an error and thus do not require error trapping. However, in some cases, a program must keep the control when an SQL error occurs. For example, when connecting to the database, the user might enter an invalid password that will raise a login denied error. The program must trap such SQL connection error to return to the login dialog and let the user enter a new login and password. To trap potential SQL errors, surround the SQL statements to be checked either with a WHENEVER http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_odiagads_046.htm ERROR exception handler or with a TRY / CATCH block:-- WHENEVER ERROR handler WHENENEVER ERROR CONTINUE INSERT INTO orders VALUES ( rec_ord. * ) IF SQLCA.SQLCODE = -75623 THEN ... END IF WHENEVER ERROR STOP -- restore the default -- TRY/CATCH block TRY INSERT INTO orders VALUES ( rec_ord. * ) CATCH IF SQLCA.SQLCODE = -75623 THEN ... END IF END TRY Using SQLCA.SQLCODE SQL error codes are provided in the SQLCA.SQLCODE register. This register always http://www.generomobile.com/techdocs/fjs-fgl-manual/c_fgl_sql_programming_diag.html contains an IBM® Informix® error code, even when connected to a database different from IBM Informix. STATUS is the global language error code register, set for any kind of error (even non-SQL). When an SQL error occurs, the error held in SQLCA.SQLCODE is copied into STATUS. Use SQLCA.SQLCODE for SQL error management, and STATUS to detect errors with other language instructions. When connecting to a database different from IBM Informix, the database driver tries to convert the native SQL error to an IBM Informix error which will be copied into the SQLCA.SQLCODE and STATUS registers. If the native SQL error cannot be converted, SQLCA.SQLCODE and STATUS will be set to -6372 (a general SQL error), you can then check the native SQL error in SQLCA.SQLERRD[2]. The native SQL error code is always available in SQLCA.SQLERRD[2], even if it could not be converted to an IBM Informix error. Using SQLSTATE SQLSTATE contains an error code that follows ISO/ANSI standard error specification, but not all database servers support this register. Using SQLSTATE for SQL error checking should be the preferred way for portable SQL programming, as long as the target databases support this feature. The SQLSTATE codes are defined by the ANSI/ISO standard specification, however not all database types support this standard. Table 1. SQLSTATE error codes support per database server type Database Server Type Supports SQLSTA
an operation succeeded or failed by examining the return value. In an ecpg application, your program is not calling PostgreSQL functions (at least at the source http://etutorials.org/SQL/Postgresql/Part+II+Programming+with+PostgreSQL/Chapter+11.+Embedding+SQL+Commands+in+C+Programs+-+ecpg/Client+2+-+Adding+Error+Checking/ code level), so you can't just examine a return code. The sqlca Structure Instead, the ecpg library uses a special data structure, the sqlca, to communicate failure conditions. Here is the definition of http://4js.com/fjs_forum/index.php?action=recent;start=10 the sqlca structure (from sqlca.h): struct sqlca { char sqlcaid[8]; long sqlabc; long sqlcode; struct { int sqlerrml; char sqlerrmc[SQLERRMC_LEN]; } sqlerrm; char sqlerrp[8]; long sqlerrd[6]; char sqlwarn[8]; char sqlext[8]; }; You don't sql error #include this file as you would with most header files. The ecpg preprocessor offers a special directive that you should use[2]: [2] Starting with PostgreSQL release 7.2, sqlca is automatically included in every ecpg program. You don't have to include it yourself. EXEC SQL INCLUDE sqlca; The difference between a #include and an EXEC SQL INCLUDE is that the ecpg preprocessor can see files that are included general sql error using the second form?ecpg ignores #includes. That doesn't mean that you can't use #include files, just remember that the inclusion occurs after the ecpg preprocess has finished its work. The contents of the sqlca structure might seem a bit weird. Okay, they don't just seem weird?they are weird. Let's walk through the members of the sqlca structure. PostgreSQL won't use many of the fields in the sqlca structure?that structure was inherited from the SQL standard. First, we'll look at the fields that never change. The sqlaid array always contains the string 'SQLCA'. Why? I don't know?history, I suppose. The sqlabc member always contains the size of the sqlca structure. sqlerrp always contains the string 'NOT SET'. Now let's look at the interesting parts of a sqlca. The sqlcode member is an error indicator. If the most recent (ecpg library) operation was completely successful, sqlcode will be set to zero. If the most recent operation succeeded, but it was a query that returned no data, sqlcode will contain the value ECPG_NOT_FOUND[3] (or 100). sqlcode will also be set to ECPG_NOT_FOUND if you execute an UPDATE, INSERT, or DELETE that affects zero rows. If an error occurs, sqlcode wi
| Most recent posts Pages: 1 [2] 3 4 ... 10 11 Discussions by product / Genero BDL / COMMENT attribute at Cell level in a Table on: October 04, 2016, 04:55:17 pm Started by Enrico S. - Last post by Enrico S. Hi, all.Taking a look at the AUI, it seems there is no way to set a comment at cell level in AUI for the fileds of an INPUT/DISPLAY ARRAY driven by a Table widget.It seems not possible with the actual structure of the AUI.This may be useful, for example, when you have an imageColumn representing the status of a row (an order waiting for confirmation as well as waiting for payment, processed ... and so on).Users could easily have the explication of shown symbols by pointing the mouse on each symbol (row by row), without need of a "legenda".I figure that the comment displayed for a table field can be the actual (at column level) only if no cell-level comment has been programmatically set in the AUI for a specific node instead.I would like to know your opinions about.Regards.Enrico 12 Discussions by product / Genero BDL / Detect caps lock? on: October 04, 2016, 02:52:42 pm Started by Snorri B. - Last post by Snorri B. Is there a way in BDL to detect if caps lock is on? It would be useful when prompting for passwords.Regs,-Snorri 13 Discussions by product / Genero BDL / Re: Does BDL provide a means of raising events? on: October 03, 2016, 06:54:47 pm Started by Matthew F. - Last post by Matthew F. Quote from: Sebastien F. on September 28, 2016, 11:19:09 amIf I would have to write such a program that can run in batch mode or with a UI interface, I would implement a unique program with --silent mode, to run the program in batch mode or in interactive mode.In interactive mode, you can then use ui.Interface.refresh() to display information to the end user (show progress bar, reload a table with log records, etc).If your program will be executed as a scheduled job in background, you could write to a log file or to an SQLite database, and have a secondary UI program displaying the progress by reading the log or the db, using ON IDLE 2 or 3 secs, to refresh information displayed to the user... In this UI program you can also implement filters or search facilities to find information in the logs.SebThank you. I'll keep these pointers in mind when modifying the program to run in batch mode. 14 Discussions by product / Genero BDL / Re: Does BDL provide a means of raising events? on: October 03, 2016, 06:51:19 pm Started by Matthew F. - Last post by Ma