Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Databases
»
Select last insert row id
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Register global hotkey
by
cdbc
[
Today
at 12:24:59 am]
Perlin Map 3D
by
Boleeman
[
Today
at 12:04:05 am]
would multi threading hel...
by
speter
[January 21, 2026, 10:53:30 pm]
X11Libre, finally and for...
by
Fred vS
[January 21, 2026, 10:20:53 pm]
Difference in formatting ...
by
Bart
[January 21, 2026, 09:49:01 pm]
What's wrong with my appl...
by
bourbon
[January 21, 2026, 09:04:40 pm]
TRichMemo install shows "...
by
rvk
[January 21, 2026, 07:47:30 pm]
How to observe the value ...
by
nouzi
[January 21, 2026, 06:26:13 pm]
Anti "churning" in solita...
by
TBMan
[January 21, 2026, 04:30:05 pm]
Lazarus for Windows on aa...
by
msintle
[January 21, 2026, 03:11:13 pm]
Perlin Noise Map With BGR...
by
Boleeman
[January 21, 2026, 01:36:13 pm]
Strange Error when I use ...
by
Thaddy
[January 21, 2026, 01:33:23 pm]
Strange Mail from memo.mi...
by
Thaddy
[January 21, 2026, 01:27:19 pm]
[Solved] Lazreport. Sorti...
by
Petrus Vorster
[January 21, 2026, 11:39:09 am]
Regarding the issue of de...
by
Martin_fr
[January 21, 2026, 11:16:29 am]
[Windows] UTF8 encoding w...
by
Thaddy
[January 21, 2026, 10:42:15 am]
Pleas help, Synapse / Ind...
by
patyit
[January 21, 2026, 10:25:29 am]
Default, Manual Initializ...
by
Okoba
[January 21, 2026, 09:17:22 am]
Cannot see unit text - ed...
by
lorenzo
[January 21, 2026, 04:05:13 am]
AdvancedHTTPServer: A Go-...
by
egsuh
[January 21, 2026, 01:44:33 am]
ThemeServices.OnThemeChan...
by
440bx
[January 21, 2026, 12:16:35 am]
Cross Compile for Dos on ...
by
PascalDragon
[January 20, 2026, 10:54:36 pm]
Feature announcement: Fun...
by
PascalDragon
[January 20, 2026, 09:50:39 pm]
Access violation during d...
by
PascalDragon
[January 20, 2026, 09:49:09 pm]
IStringList...
by
PascalDragon
[January 20, 2026, 09:35:54 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Select last insert row id (Read 475 times)
LemonParty
Sr. Member
Posts: 393
Select last insert row id
«
on:
November 05, 2025, 05:41:20 pm »
I have this code:
Code: Pascal
[Select]
[+]
[-]
function
TdmSQLite
.
Insert
(
Path
:
String
;
Archive
:
TByteDynArray
)
:
SizeInt
;
begin
Result
:
=
-
1
;
Query
.
Close
;
Query
.
SQL
.
Text
:
=
'INSERT INTO Backup(Path, Archive) VALUES (:Path, :Archive)'
;
Query
.
ParamByName
(
'Path'
)
.
AsString
:
=
Path
;
Query
.
ParamByName
(
'Archive'
)
.
AsBlob
:
=
Archive
;
Query
.
ExecSQL
;
Tran
.
Commit
;
Query
.
SQL
.
Text
:
=
'SELECT last_insert_rowid()'
;
Query
.
Open
;
Result
:
=
Query
.
Fields
[
0
]
.
AsInteger
;
end
;
And I have a doubt. Should I put Transaction.Commit after or before "SELECT last_insert_rowid()"?
Logged
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11
Sieben
Sr. Member
Posts: 384
Re: Select last insert row id
«
Reply #1 on:
November 05, 2025, 06:30:03 pm »
Before - insert action has to be finalized to produce a valid ID. And you might as well use TSQLite3Connection.GetInsertID instead of your Query.
Logged
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7
LemonParty
Sr. Member
Posts: 393
Re: Select last insert row id
«
Reply #2 on:
November 05, 2025, 06:37:52 pm »
Thank you.
Logged
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11
Zvoni
Hero Member
Posts: 3230
Re: Select last insert row id
«
Reply #3 on:
November 05, 2025, 06:58:40 pm »
Or implement a Callback like described here:
http://sqlite.org/c3ref/update_hook.html
The it's basically like an Event
Logged
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Databases
»
Select last insert row id
TinyPortal
© 2005-2018