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
Need help to build FPC fo...
by
link4electronics
[
Today
at 02:45:33 am]
Recomendations for conver...
by
egsuh
[
Today
at 02:36:32 am]
Hints in TTrayIcon
by
dbannon
[
Today
at 02:11:20 am]
Need help converting a C+...
by
MathMan
[
Today
at 12:45:02 am]
Possible LMAX Disruptor (...
by
jamie
[
Today
at 12:41:14 am]
Just Curious: When has an...
by
Martin_fr
[December 04, 2025, 11:28:44 pm]
[SOLVED] Assembler error ...
by
yurets_z
[December 04, 2025, 11:18:23 pm]
Cannot find Online Packag...
by
dseligo
[December 04, 2025, 10:57:42 pm]
TMSSQLConnection in MacOS...
by
zeljko
[December 04, 2025, 10:29:17 pm]
Compiled package
by
Ed78z
[December 04, 2025, 10:26:14 pm]
ddebian 12 input err!
by
PascalDragon
[December 04, 2025, 09:39:53 pm]
unusual static FPC
by
PascalDragon
[December 04, 2025, 09:38:46 pm]
How to load read large CS...
by
Nimbus
[December 04, 2025, 08:29:24 pm]
Lazarus IDE problem?
by
BrunoK
[December 04, 2025, 05:52:48 pm]
Qt6 / X11: problem with G...
by
zeljko
[December 04, 2025, 04:18:33 pm]
How to use nested classes
by
440bx
[December 04, 2025, 01:59:08 pm]
Qt6 / X11 session: strang...
by
AlexTP
[December 04, 2025, 01:04:31 pm]
TShellListView empty spac...
by
jamie
[December 04, 2025, 12:20:14 pm]
Tool to create Windos set...
by
marcov
[December 04, 2025, 11:35:30 am]
IDE Watch Window colors (...
by
Martin_fr
[December 04, 2025, 11:23:38 am]
Anchoring controls with d...
by
Martin_fr
[December 04, 2025, 11:20:42 am]
Why this code is working ...
by
Martin_fr
[December 04, 2025, 11:07:08 am]
BalloonHint in Trayicons ...
by
CM630
[December 04, 2025, 10:59:42 am]
[Solved]Lazreport Labels
by
Petrus Vorster
[December 04, 2025, 09:42:38 am]
MouseAndKeyInput ---> To ...
by
n7800
[December 04, 2025, 08:43:08 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Select last insert row id (Read 412 times)
LemonParty
Sr. Member
Posts: 388
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: 383
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: 388
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: 3161
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