why sometimes does 'last insert id' return 0

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
top1
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 22.11.2015, 18:11

why sometimes does 'last insert id' return 0

Post by top1 »

As the above question
Why sometimes does last insert id retuning 0

After i call another procedure to insert , its works again after i fire the another insert by another procedure

I'm creating tzquery object every time when procedure runs with the same connection
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: why sometimes does 'last insert id' return 0

Post by EgonHugeist »

:?: :?:

Which compiler, database and which protocol? An example to support you would be nice!
My crystal balls don't tell anything here..
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
top1
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 22.11.2015, 18:11

Re: why sometimes does 'last insert id' return 0

Post by top1 »

I'm using Delphi7 as compiler with MariaDB-10 protocal and MariaDB-10 in xampp as sql server , here below is my sql text

Code: Select all

SELF_QUERY.Close;
SELF_QUERY.SQL.Clear;
SELF_QUERY.SQL.Add('insert into xxx (uid, itemid, C0, tempo, DATE_RECEIVE, DATE_END) values (' + QuotedStr(inttostr(Client[i].uid)) + ',' + QuotedStr(inttostr(ITEM_TYPEID)) + ', ' + QuotedStr(inttostr(QTY)) + ' , ' + QuotedStr(IntToStr(Temp)) + ' , ' + QuotedStr(FormatDateTime('yyyy-mm-dd tt',Now())) +'  , ' + QuotedStr(FormatDateTime('yyyy-mm-dd tt',DateEnd)) +') ');
SELF_QUERY.ExecSQL;

Code: Select all

// get last insert id
SELF_QUERY.SQL.Clear;
SELF_QUERY.SQL.Text := 'SELECT LAST_INSERT_ID()';
SELF_QUERY.Open;
ITEM_IDI := SELF_QUERY.FieldByName('LAST_INSERT_ID()').AsInteger;
I always use the new TZQuery with the same connections

I got my data inserted but sometimes the LAST_INSERT_ID is zero for awhile.
top1
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 22.11.2015, 18:11

Re: why sometimes does 'last insert id' return 0

Post by top1 »

I faced this problem again and again

i have to truncate table every time for get last last_insert_id works again :evil:

Edited...

when AutoIncreasement reached to 59 it will be return 0 at 60

and come back work again at 100

and will be 0 again at 600

every time i try it will be like this

pictures are below
1.jpg
2.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: why sometimes does 'last insert id' return 0

Post by EgonHugeist »

Don't know why your making it so complicated.

If you're using the TZQuery for the fetches and you insert a row ... zeos automalicaly returns the last inserted id into the field.
Is there a spezial reason whay you want to do everthing manually?

In addition stop working with pascal quoted strings, this is not supported by MySQL this way. Use Parameters instead. And zeos is doing the escape stuff for your. Just look at: https://xkcd.com/327/ funny isn't it?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: why sometimes does 'last insert id' return 0

Post by EgonHugeist »

I DON'T KNOW what you're doing, dude.
This way nobody can help you. Note Last_Inserted_id depends to last update smt. Are you using a pure sequential code or do you play with threads oslt

Did you read my last post? Why did you drop your last post?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
top1
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 22.11.2015, 18:11

Re: why sometimes does 'last insert id' return 0

Post by top1 »

Do you have a example page please ?

I'm quite confused about the component i must use.

ps. i'm out of thread for awhile call direct from socket.read
top1
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 22.11.2015, 18:11

Re: why sometimes does 'last insert id' return 0

Post by top1 »

finally after 2 day , I nailed it by below code

Code: Select all

    with zqry1 do begin

    sql.Clear;
    SQL.Add('select idi,uid,itemid from py_itens where 1=1');
    Open;

    Insert;
    fieldbyname('uid').AsInteger := 1;
    fieldbyname('itemid').AsInteger := 188905095;
    Post;
    chklst1.Items.Add( IntToStr( fieldbyname('idi').AsInteger )) ;
    end;
Post Reply