Solved

How do you interpret Oracle SQLCA Error

Posted on 2008-10-22
4
766 Views
Last Modified: 2013-12-18
Using Pro *C/C++ in unix environment.  How do you display and print and interpret this structure?
0
Comment
Question by:sdruss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 22783047
It's defined in

 $ORACLE_HOME/precomp/public/sqlca.h

I've copied the structure itself from the file here.

You can display and print it's fields like you would any other struct.

What do you want to "interpret" about it?

struct   sqlca
         {
         /* ub1 */ char    sqlcaid[8];
         /* b4  */ int     sqlabc;
         /* b4  */ int     sqlcode;
         struct
           {
           /* ub2 */ unsigned short sqlerrml;
           /* ub1 */ char           sqlerrmc[70];
           } sqlerrm;
         /* ub1 */ char    sqlerrp[8];
         /* b4  */ int     sqlerrd[6];
         /* ub1 */ char    sqlwarn[8];
         /* ub1 */ char    sqlext[8];
         };

Open in new window

0
 
LVL 48

Accepted Solution

by:
schwertner earned 500 total points
ID: 22786324
It is explained here:
http://www.cs.ubc.ca/~ramesh/cpsc304/tutorial/EmbeddedSQL/embeddedSQL2.html

If you started doing some programming already, then you might have encountered some seemingly unexplainable problems, as all programmers experience every now and then.  For example, you might have tried to insert a tuple into a relation which violated an integrity constraint. When conditions such as these arise, Oracle returns an error code which specifically indicates the cause of the problem. This error code is returned in a structure:  the  SQLCA  (SQL Communications Area), in your program.  Instead of/in addition to using the SQLCA structure, Oracle also allows you to declare status variables:  SQLSTATE and SQLCODE that you can check after each SQL statement (SQLSTATE is preferred over SQLCODE).  This tutorial will cover only the SQLCA structure.
Besides error codes, the SQLCA structure also contains warning messages and various other administrative variables which can come in fairly handy when debugging your program. The structure definition of SQLCA is:

struct sqlca
{
  char sqlcaid[8];
  long sqlabc;
  long sqlcode;
  struct
    {
      unsigned short sqlerrml;
      char           sqlerrmc[70];
    } sqlerrm;
  char sqlerrp[8];
  long sqlerrd[6];
  char sqlwarn[8];
  char sqlext[8];
};
The values of the structure are updated by Oracle after every SQL statement. The variable which we will find most useful in the SQLCA structure is sqlca.sqlcode (not the same as the SQLCODE status variable), which holds function return status information. After a function call, if sqlca.sqlcode is:
 
0, this implies a successful operation
 
negative, an ORACLE ERROR was encountered.  Such errors are usually fatal, so the current transaction should be rolled back.  An example of an error is an update or insert statement that attempted to insert a duplicate key.  This returns an error code of -1.
 
positive, execution was successful and a status code is returned, but an exception was detected.  See below for an example of such a situation.
 
100 or 1403 (this depends on the precompiler's settings), all rows have been fetched or no rows were returned.

Another useful variable is sqlca.sqlerrm.sqlerrmc, which is a 70 character string holding Oracle error messages.

To use the SQLCA structure, we need to include the following line near the beginning of any program which uses the structure:
 

EXEC SQL INCLUDE sqlca;

..........................................
0
 
LVL 1

Author Comment

by:sdruss
ID: 22790457
Implemented.  Worked well.
0
 
LVL 48

Expert Comment

by:schwertner
ID: 22794190
Thank you so much!
Good luck!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question