Re: Getting SERIAL value when inserted with 0
Posted in 1992
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I got several replies which I will summarize: The most obvious solution was to add a row and get max(SERIAL_FIELD) to determine which row I added. The problem with this is that if two people both add records almost simultaneous, the first person's max query might return the second person's number (assuming both inserts happened before either max), so this could be a problem. The best solution was to do max before adding the row, increment that value and try to add the row using max + 1 as the SERIAL value. Two people could try this at the same time too, so if you get a SERIAL value exists error, just keep incrementing it until you don't get the error. This seems to work, though I can't be sure what will happen when people enter several records simultaneously but I suspect it will work as expected. Thanks to all those who responded. >I am working on a new UI for an Informix database. I need to be able to >add rows to a table with SERIAL fields and get the next available serial >value. I can do an insert with 0 in the serial field but then I need to >get the number that was actually used so that I can add data to other >tables that reference this row. I cannot use ESQL with this interface >so I can't get the value of sqlca.sqlerrd[1]. Is there any way, using SQL >statements with Informix Online 4.0 to get the automatically generated Serial >value back? <=================================Q=================================> Chris Evans | Internet: evans@cayman.com Technical Support, GatorMaster | Phone: 617-494-1999 Cayman Systems | FAX: 617-494-5760 26 Landsdowne Street | AppleLink: CAYMAN.TECH Cambridge MA 02139 | or evans@cayman.com@internet#