Usando GetLastautogenValue.
-
22-12-2019 - |
Domanda
Sto usando FireDac TFDQuery per inserire valori nel database Informix, utilizzando il basso Snippet di codice:
with QHeaderQuery do
begin
if not (Prepared) then
begin
{DatabaseName := Sessions.CurrentSession.Databases[0].DatabaseName;
SessionName := Sessions.CurrentSession.SessionName;}
Connection := FDManager.Connections[0];
SQL.Clear;
SQL.Add('insert into asptheade ( ');
SQL.Add('theade_trans, theade_store, theade_register, theade_location, ');
SQL.Add('theade_date, theade_cashier, theade_type, theade_name, ');
SQL.Add('theade_salesperson, theade_group, theade_group_disc, ');
SQL.Add('theade_comm_flag, theade_comm_price, theade_cust_code, ');
SQL.Add('theade_sub_total, ');
SQL.Add('theade_tax_total, theade_disc_total, theade_grand_total, ');
SQL.Add('theade_change_amt, theade_drawertime, theade_posted_date, theade_gratuity) ');
SQL.Add('values ( :d0, :d1, :s2, :s3, ');
SQL.Add(' current year to second, :s4, :s5, :s6, ');
SQL.Add(':s7, :s8, :f9, ');
SQL.Add(':s10, :s11, :s12, :f13, ');
SQL.Add(':f14, :f15, :f16, :f17, :f18, :f19, :f20 ) ');
Prepared := True;
end;
{SQL.Add( Format( 'values ( %d, %d, "%s", "%s", ', }
Params[0].AsInteger := FTrans;
Params[1].AsInteger := FStore;
Params[2].AsString := FRegister;
Params[3].AsString := FLocation;
{SQL.Add( Format( ' current, "%s", "%s", "%s", ', }
Params[4].AsString := FCashier;
Params[5].AsString := FTransType;
Params[6].AsString := FStatementText;
{SQL.Add( Format( '"%s", "%s", %f, ',}
Params[7].AsString := FSalesPerson;
Params[8].AsString := FDiscGroup;
Params[9].AsFloat := FDiscRate * 100;
{SQL.Add( Format( '"%s", "%s", "%s", %f, ',}
Params[10].AsString := FCommFlag;
Params[11].AsString := FCommPrice;
Params[12].AsString := FCustCode;
Params[13].AsFloat := FSubTotal;
{SQL.Add( Format( '%f, %f, %f, %f ) ',}
Params[14].AsFloat := FTaxTotal;
Params[15].AsFloat := FDiscTotal;
Params[16].AsFloat := FGrandTotal;
Params[17].AsFloat := FChangeAmt;
Params[18].AsDateTime := FDrawerTime;
Params[19].AsDateTime := FServiceDate;
Params[20].AsFloat := FGratuity;
Execute;
FValid := True;
end;
FTrans := FDManager.Connections[0].GetLastAutoGenValue('asptheade');
QHeaderQuery.Close;
.
Sto ricevendo capacità non supportate.Ho anche provato una corda vuota anziché ma di nuovo lo stesso errore.Puoi per favore guidarmi con il corretto utilizzo di GetLastautogenValue?Sto usando dbexpress bridge driver.
Soluzione 3
L'ho fatto funzionare usando la seguente query nel mio Proct memorizzato:
SELECT DBINFO('sqlca.sqlerrd1') FROM SYSTABLES WHERE tabname = '<tablename>'
.
e restituisce lo stesso valore in Proc.
Altri suggerimenti
GetLastautogenValue supporta il ritorno di:
- .
- L'ultimo valore di campo incrementale automatico utilizzato a Insert / Post per tutte le fonti di dati;
- L'ultimo valore incrementale automatico utilizzato su ExecSQL / Execproc per i driver di FireDac nativi;
- L'ultimo valore della sequenza / generatore per i driver di FireDac nativi.L'argomento GetLastautogenValue è un nome generatore / sequenza.
FireDac XE5 non ha autista nativo per informix.Quindi, (2) e (3) non sono supportati per Informix.Il tuo codice è inserito con Execute, quindi (1) non è supportato anche.Di conseguenza, stai ricevendo "capacità non supportate".
È possibile soluzione alternativa eseguendo la seguente query subito dopo la query di insert:
SELECT DBINFO('sqlca.sqlerrd1') FROM SYSTABLES WHERE tabname = 'systables'
.