So ... based on all your expert advises, I decided to use SQLite3 - at least look into it, and do some experiments.
And it's all fine - until this...
function TrackAntal(aSamling : integer) : integer;
var
SQL3conn : TSQLite3Connection;
Query : TSQLQuery;
qry : string;
res : integer;
begin
res := -1;
SQL3conn := DBConnect;
try
Query := TSQLQuery.Create(nil);
qry := 'SELECT MAX(idx) AS "ant" FROM sam_num WHERE samling="'+IntToStr(aSamling)+'"';
Query.SQL.Text := qry;
Query.Database := SQL3conn;
Query.Open;
res := 0;
while not Query.Eof do begin
res := Query.FieldByName('ant').AsInteger;
Query.Next;
end;
Query.Close;
finally
SQL3conn.Close;
SQL3conn.Destroy;
end;
TrackAntal := res; // -1 hvis fejl, 0 hvis ingen og ellers det største idx (største track-nummer) Det er ikek nødvendigvis det samme som antallet...
end;
... it raises an exception in line 18:
"... class EConvertException with message: "" is an invalid integer"
This seems to be a problem in TSQLQuery; using lazarus's lazdatadesktop.exe, the SQL (line 12) executes just fine.
Problem probably is, that there are no records containing the asked for "samling"...
So TSQLQuery should return noting (Eof should be true immediately - like it does with other SELECT queries, that return no results).
Any thoughts or suggestions?