Getting Serial Value
Posted in 1997
In the web application I am currently working on, I use tables that include an Informix SERIAL data type as the primary key. Whenever I add a row to these tables, it automatically increments to the next available number. This is great since I am guaranteed a good and unique value each time and I do not have to keep track of ID numbers manually. But I have a problem I can't seem to figure out how to solve. When a visitor enters the web application for the first time, I would like to add a record to my Customers table and assign the primary key of that table to a cookie. I do not know any information about the customer yet, so the row is added with all Null values except for the primary key (the SERIAL column). Since the database is generating this number, not something in my code, I am not able to figure out what value is the primary key is being set to. Am I missing something? Is there a way to return the value that the SERIAL column gets set to? Or is there a way to at least return the ROWID of the newly inserted column? I'm using an "INSERT INTO customers" statement to insert a new row will all null values except the primary key. Can I get the info I need if I use an updatable cursor? Is there some way to get either the ROWID or the value of the inserted primary key column by using a stored procedure? Any suggestions on what the procedure would look like? I have considered creating some random, unique identifier and inserting it so that I can query on it to get the primary key value. But if I do that, I might as well just use the random, unique identifier as the primary key. So do I have to resort to custom code to increment and keep track of primary keys manually? Any info or suggestions would be really appreciated... By the way, I'm using the Netscape Livewire development environment, running Enterprise 3.0 on Sun Solaris 2.5.1 with Informix OWG 7.1.2.UC1. Thanks, Tauren tauren@groovee.com