Using Delphi 2 to insert a record into
Posted in 1997
Topics: Stored Procedures & SPL, Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Cloud, Docker & Containers
Subject: Using Delphi 2 to insert a record into an Informix database and retrieve the Serial Number allocated by the Informix Server. Author: Mike O'Donnell, GUI Team, MCL Software Ltd., Southport, England. After reading notes on the Web recently concerning "The Informix Serial Number And How To Get It", and contacting Borland Technical Support (Thanks Jon!), I finally found that the SQL driver's DBIGetProp() function drvNATIVESQLCA param is $00030004 (it was not included in BDE.INT). The following quick test works, and brings back the SQLCA structure which contains the Serial Number in the sqlca.sqlerrd[1] LongInt. In this case the main form has a Data Set, a Query object, a label and a button. The Query is used to insert a new record which has zero as its Serial Number. When the button is clicked the record is inserted, and the DBIGetProp() function used to retrieve the SQLCA structure from the server. The Serial Number that the server allocated to the newly inserted row can then be retrieved. One odd thing; the last parameter is supposed to be a pointer to UINT16, but the function will not accept a pointer. procedure TForm1.Button1Click(Sender: TObject); const drvNATIVESQLCA = $00030004; { INFORMIX 'Pass SQLCA Structure' param } type { SQLCA Structure } sqlcaw_s = record sqlwarn0 : Char; sqlwarn1 : Char; sqlwarn2 : Char; sqlwarn3 : Char; sqlwarn4 : Char; sqlwarn5 : Char; sqlwarn6 : Char; sqlwarn7 : Char; end; sqlca_s = record sqlcode : LongInt; sqlerrm : array [0..71] of Char; sqlerrp : array [0..7] of Char; sqlerrd : array [0..5] of LongInt; sqlcaws : sqlcaw_s; end; var sqlca : sqlca_s; sqlca_ptr : ^sqlca_s; len : Word; begin with Query1 do begin { INSERT record into table with Serial Number as zero } SQL.Assign(Memo1.Lines); Prepare; ExecSQL; { Get INFORMIX SQLCA structure } sqlca_ptr := @sqlca; DBIGetProp(hDBIObj(Database1.Handle), drvNATIVESQLCA, sqlca_ptr, SizeOf(sqlca), len); { Fetch Serial Number from SQLCA structure and display it } SerialLabel.Caption := IntToStr(sqlca.sqlerrd[1]); end; end;