If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > how to read primary key

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-07-03, 22:03
bzuborski bzuborski is offline
Registered User
 
Join Date: Jun 2002
Posts: 10
how to read primary key

Hi,
i want to write a stored procedure that inserts into a table
which has primary key of type SERIAL8, and then retrieves
this new key (how?) and returns it as returned value.
I cannot use SELECT...WHERE statement since some of the fields
are TEXT etc. Is it possible to get the newly inserted key from DBINFO?
Can I use ROWID perhaps to get primary key?

thnx,
bran
Reply With Quote
  #2 (permalink)  
Old 02-08-03, 03:41
eherber eherber is offline
Registered User
 
Join Date: Aug 2002
Location: Bonn/Germany
Posts: 152
You have to use the dbinfo() function for
this.

create procedure p1() returning int;

define my_serial int;

insert into t_serial values(0);
let my_serial = dbinfo("sqlca.sqlerrd1");

return my_serial;

end procedure


HTH.

Best regards

Eric
--
IT-Consulting Herber
WWW: http://www.herber-consulting.de
Email: eric@herber-consulting.de

***********************************************
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
***********************************************
Reply With Quote
  #3 (permalink)  
Old 02-12-03, 20:41
bzuborski bzuborski is offline
Registered User
 
Join Date: Jun 2002
Posts: 10
I tried this but unfortunatelly on my system (Informix DS 9.3)
DBINFO( "sqlca.sqlerrd1" ) returns 0 always, i.e. stored procedure
inserts correct SERIAL8 primary key but DBINFO always returns 0?!

I traced this with following statements to confirm:

SET DEBUG FILE TO '/tmp/trace';
TRACE OFF;
TRACE 'primary key = ' || DBINFO("sqlca.sqlerrd1");


I dont know what could be wrong??

thanks,,
Reply With Quote
  #4 (permalink)  
Old 02-13-03, 03:23
eherber eherber is offline
Registered User
 
Join Date: Aug 2002
Location: Bonn/Germany
Posts: 152
Hi,

this was my fault.

You need to used dbinfo('serial8') instead of
dbinfo('sqlca.sqlerrd1').

I didn't recognize that it was a serial8, which has a larger
range of values than a normal serial.

Sorry.

Best regards

Eric
--
IT-Consulting Herber
WWW: http://www.herber-consulting.de
Email: eric@herber-consulting.de

***********************************************
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
***********************************************
__________________

Best regards

Eric
--
IT-Consulting Herber
WWW: http://www.herber-consulting.de
Email: eric@herber-consulting.de

***********************************************
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
***********************************************
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On