Anda harus mendapatkan ID sekaligus
SQLQry := TSQLQuery.Create(self);
with SQLQry do begin
SQLConnection := SQLCon;
SQL.Add('INSERT INTO Sample_Table ');
SQL.Add('(mobile_number, message_body) VALUES');
SQL.Add(format('(%s, %s);',[QuotedStr('989121011689'), QuotedStr('Text1')]));
SQL.Add('SELECT LAST_INSERT_ID() EngineRefNo;');
Open;
ListBox1.items.Add(FieldByName('EngineRefNo').AsString);
Close;
end;
SQLCon.Close;
dan Anda harus berpikir tentang menggunakan parameter untuk mencegah injeksi sql
SQLQry := TSQLQuery.Create(self);
with SQLQry do begin
SQLConnection := SQLCon;
SQL.Add('INSERT INTO Sample_Table ');
SQL.Add('( mobile_number, message_body ) VALUES');
SQL.Add('( :mobile_number, :message_body );');
SQL.Add('SELECT LAST_INSERT_ID() EngineRefNo;');
ParamByName( 'mobile_number' ).Value := '989121011689';
ParamByName( 'message_body' ).Value := 'Text1';
Open;
ListBox1.items.Add(FieldByName('EngineRefNo').AsString);
Close;
end;
SQLCon.Close;