Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Informix Topics / November 2003

Tip: Looking for answers? Try searching our database.

How can I obtain SQLCODE in SPL ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marek Radzewicz - 26 Nov 2003 12:53 GMT
How can I obtain SQLCODE (and sql error message) inside SPL code in Informix
?

dbinfo('sqlca.sqlcode') doesn't work ...
Art S. Kagel - 26 Nov 2003 13:56 GMT
> How can I obtain SQLCODE (and sql error message) inside SPL code in Informix ?
> dbinfo('sqlca.sqlcode') doesn't work ...
You have to use EXCEPTION handling to retrieve the SQLCODE and ISAM error code:

create procedure some_proc( arg1 int, ... )
returning int, int, int;

 DEFINE rtnsql  INT;       -- place holder for exception sqlcode setting
 DEFINE rtnisam INT;    -- isam error code. Should be onpload exit status
 DEFINE final_result INT;

 ON EXCEPTION SET rtnsql, rtnisam
    ROLLBACK WORK;
    RETURN -1, rtnsql, rtnisam;
 END EXCEPTION;

 BEGIN WORK;
 LET final_result = 0;
 .....
 COMMIT WORK;
 RETURN final_result, 0, 0;

 END PROCEDURE;

If you prefer the EXCEPTION handler can simply do nothing other than set the
variables and fall back to the mainline code where you can test them and handle
the results yourself;

Art S. Kagel
Marek Radzewicz - 26 Nov 2003 14:23 GMT
Thanks, it works !
I have one more question: is it possible to find error description as text,
inside SPL ?

Marek Radzewicz

> > How can I obtain SQLCODE (and sql error message) inside SPL code in Informix ?
> > dbinfo('sqlca.sqlcode') doesn't work ...
[quoted text clipped - 25 lines]
>
> Art S. Kagel
rkusenet - 26 Nov 2003 14:49 GMT
> Thanks, it works !
> I have one more question: is it possible to find error description as text,
> inside SPL ?

yes and no.

ON EXCEPTION SET rtnsql, rtnisam, rterrmsg

rterrmsg is a char field of possibly char(80) length.

will set the reason of the error, usually the column name table name
or missing constraint name. But not the full error.

For e.g. if you are inserting a null value into a column date_of_birth
which has been declared as NOT NULL, then the above EXCEPTION will
be set as follows:-

rtnsql = -391
rtnisam = 0
rterrmsg = 'date_of_birth'

finderr -391

-391    Cannot insert a null into column column-name.

This statement tries to put a null value in the noted column. However,
that column has been defined as NOT NULL. Roll back the current
transaction. If this is a program, review the definition of the table,
and change the program logic to not use null values for columns that
cannot accept them.

No u can construct from the above that you are trying to insert null
into date_of_birth column.

In ESQL/C one can do sprintf and construct an error string which can
look like this:

Cannot insert a null into column data_of_birth which is definitely more
readable.

For me, even the SP way is good enuf to find out the cause.

However it is to be noted that if you don't have an exception block
and let the server return any error, then the server always returns full
error string as described above for ESQL/C. I don't know how the same
can be achieved using EXCEPTION block.
Andy Kent - 27 Nov 2003 09:28 GMT
... provided you actually wanted the calling routine to receive it as
a return value, and not to catch it as an error. If you want to do
both you'll have to issue a RAISE EXCEPTION.

Otherwise just let the code fall out on its own.

Andy
Francisco Roldan - 26 Nov 2003 14:50 GMT
BTW, how can i make a system call from SPL and get back the
result from the executed system command ?

Thanks in advance

-----Mensaje original-----
De: Art S. Kagel [mailto:kagel@bloomberg.net]
Enviado el: Mi?rcoles, 26 de Noviembre de 2003 07:56 a.m.
Para: informix-list@iiug.org
Asunto: Re: How can I obtain SQLCODE in SPL ?

> How can I obtain SQLCODE (and sql error message) inside SPL code in
> Informix ?
> dbinfo('sqlca.sqlcode') doesn't work ...
You have to use EXCEPTION handling to retrieve the SQLCODE and ISAM error
code:

create procedure some_proc( arg1 int, ... )
returning int, int, int;

 DEFINE rtnsql  INT;       -- place holder for exception sqlcode setting
 DEFINE rtnisam INT;    -- isam error code. Should be onpload exit status
 DEFINE final_result INT;

 ON EXCEPTION SET rtnsql, rtnisam
    ROLLBACK WORK;
    RETURN -1, rtnsql, rtnisam;
 END EXCEPTION;

 BEGIN WORK;
 LET final_result = 0;
 .....
 COMMIT WORK;
 RETURN final_result, 0, 0;

 END PROCEDURE;

If you prefer the EXCEPTION handler can simply do nothing other than set the
variables and fall back to the mainline code where you can test them and
handle the results yourself;

Art S. Kagel

sending to informix-list
Jean Sagi - 26 Nov 2003 18:52 GMT
I can't remember the syntax but it is something like:

RUN

or

SYSTEM

But getting the result us another  history... maybe in the documentation...

Chucho!

Francisco Roldan wrote:

> BTW, how can i make a system call from SPL and get back the
> result from the executed system command ?
[quoted text clipped - 43 lines]
>
> sending to informix-list

Signature

Atte,

Jesus Antonio Santos Giraldo
-----------------------------------
jeansagi@myrealbox.com
jeansagi@netscape.net

sending to informix-list

Francisco Roldan - 27 Nov 2003 16:29 GMT
What about using a SYSTEM call, to the dbload command,
after creating the dbload file ...

-----Mensaje original-----
De: Doug Lawry [mailto:lawry@nildram.co.uk]
Enviado el: Jueves, 27 de Noviembre de 2003 06:09 a.m.
Para: informix-list@iiug.org
Asunto: Re: How can I obtain SQLCODE in SPL ?

You would have thought that the following was possible:

CREATE PROCEDURE system_call (command CHAR(500)) RETURNING CHAR(80);
   DEFINE result CHAR(80);
   LET result = '/tmp/' || 'system_call.' || DBINFO('sessionid');
   SYSTEM command || ' > ' || result || ' 2>&1';
   CREATE TEMP TABLE system_call (result CHAR(80));
   LOAD FROM result INSERT INTO system_call;
   SYSTEM "rm " || result;
   FOREACH SELECT * INTO result FROM system_call END FOREACH;
   DROP TABLE system_call;
   RETURN result;
END PROCEDURE;

However, LOAD is not available in SPL with IDS 9.30. Why is this?

Regards,
Doug Lawry
www.douglawry.webhop.org

> On Wed, 26 Nov 2003 09:50:31 -0500, Francisco Roldan wrote:
>
> You really cannot.  Remember that SPL was never intended as a general
purpose
> programming language, just a way to can pre-optimized SQL or add some
basic flow
> control to SQL.  Unlike the other major databases Informix has always
> had several excellent development tools (ace/perform, 4GL, ESQL/C,
> JDBC, etc.)
so
> there was no need for a more generic programming facility in the
> engine as
the
> big 'O' once required.  The external program will have to put its
> results
into a
> table for the SPL to retrieve.  If this is more than trivial then
> likely
it
> should be an ESQL/C program/library function rather than an SPL.  If
> it is business rule related and you MUST have it available through the
> database
AND
> you have 9.xx consider writing the procedure/function as a Java or C
> UDF
instead
> then you will have access to any system calls or external program
> pipes
that you
> need.
>
> Art S. Kagel
>
> > BTW, how can i make a system call from SPL and get back the result
> > from
the
> > executed system command ?
> >
[quoted text clipped - 3 lines]
> > De: Art S. Kagel [mailto:kagel@bloomberg.net] Enviado el: Mi?rcoles,
> > 26
de
> > Noviembre de 2003 07:56 a.m. Para: informix-list@iiug.org Asunto:
> > Re:
How can
> > I obtain SQLCODE in SPL ?
> >
> > On Wed, 26 Nov 2003 07:53:53 -0500, Marek Radzewicz wrote:
> >
> >> How can I obtain SQLCODE (and sql error message) inside SPL code in
Informix
> >> ?
> >> dbinfo('sqlca.sqlcode') doesn't work ...
> > You have to use EXCEPTION handling to retrieve the SQLCODE and ISAM
error
> > code:
> >
> > create procedure some_proc( arg1 int, ... ) returning int, int, int;
> >
> >   DEFINE rtnsql  INT;       -- place holder for exception sqlcode
setting
> >   DEFINE rtnisam INT;    -- isam error code. Should be onpload exit
status
> >   DEFINE final_result INT;
> >
[quoted text clipped - 13 lines]
> > If you prefer the EXCEPTION handler can simply do nothing other than
> > set
the
> > variables and fall back to the mainline code where you can test them
> > and handle the results yourself;
> >
> > Art S. Kagel
> >
> > sending to informix-list

sending to informix-list
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.