Solved

How do you interpret Oracle SQLCA Error

Posted on 2008-10-22
4
755 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
  • 2
4 Comments
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
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 47

Accepted Solution

by:
schwertner earned 500 total points
Comment Utility
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
Comment Utility
Implemented.  Worked well.
0
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
Thank you so much!
Good luck!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now