Re: ESQL: modify next SERIAL value
Posted in 2000
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Data Types & Schema Design
Jens Schacherl <js@jschacherl.de> ''''' ' ''''''''':3A103CB5.70F29E32@jschacherl.de... > Hello all, > > I've read all postings about this topic I found with deja but still it's > not working. > I'm trying to reset the SERIAL column 'lfdnr' after deleting a > consecutive number of rows using this code: > > int d_basiszahlen(xdate* pdtVon) > { > EXEC SQL BEGIN DECLARE SECTION; > date dateVon; > long max_nr; > EXEC SQL END DECLARE SECTION; > int rc; > > dateVon = XDateToLong(pdtVon); > > EXEC SQL DELETE FROM basiszahlen WHERE gueltig_von = :dateVon; > rc = sqlca.sqlcode; > > if (rc == 0) > { > EXEC SQL SELECT MAX(lfdnr) INTO :max_nr FROM basiszahlen; > rc = sqlca.sqlcode; > > if (rc == 0) > { > max_nr++; > EXEC SQL ALTER TABLE basiszahlen MODIFY lfdnr SERIAL(max_nr); This must looks like: EXEC SQL ALTER TABLE basiszahlen MODIFY lfdnr SERIAL(:max_nr); ( But if lfdnr is primary key, and there are any table references to it, all constraints will be dropped ) Sergey > rc = sqlca.sqlcode; > } > } > > return rc; > } > > > The ESQL compiler gives me a syntax error in the ALTER TABLE statement: > Error -33051: esqlc - Syntax error on identifier or symbol 'max_nr'. > > All examples I found were about modifying the serial column using a > constant serial value but not a variable. Also I've read that 'serial' > is a separate data type but I cannot declare 'max_nr' as serial or > SERIAL (gives another syntax error). > > adTHANKSvance, Jens
"Sergey E. Volkov" schrieb: > >> [..] > > EXEC SQL ALTER TABLE basiszahlen MODIFY lfdnr SERIAL(max_nr); > > This must looks like: > > EXEC SQL ALTER TABLE basiszahlen MODIFY lfdnr SERIAL(:max_nr); > > ( But if lfdnr is primary key, and there are any table references to it, all > constraints will be dropped ) > > Sergey > Thanks Sergey for your answer. I should have mentioned that I've tried this before (since it's the normal syntax) but this gives me the error: Error -33051: esqlc - Syntax error on identifier or symbol ':'. It seems to me that I can only use constant numbers here (this compiles w/o error). Any other ideas? Jens