Solved

Sqlite last_insert_rowid() Help!

Posted on 2010-09-02
5
1,863 Views
Last Modified: 2012-05-10
I am trying to get a handle on sqlite and adapt from my MS SQL knowledge and having trouble...

When I do this..

insert into tblRecords2(myField) values ('A7962144F9C16EE22672D96C6655063');
select last_insert_rowid();

The select last_insert_rowid(); returns 0 - but this is not true because i can select rowid from tblRecords2 and get the new value.
Can anyone tell me why this is?


I am testing on Windows machine using RazorSQL.
Thank you
0
Comment
Question by:NTGuru705
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:NTGuru705
ID: 33591173
In truth I am trying to use the rowid in an insert statement..

insert into tblRecords2(myField) values ('A7962144F9C16EE22672D96C6655063');
insert into tblRecords3(myField1,myField2) values (last_insert_rowid(),2);
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33592083
This just worked for me from the command line so potentially the RazorSQL is not calling the two statements in the same session and so you are losing the last_insert_rowid().  Can you confirm the table definition for tblRecords2.  For my test, I simply used:

create table tblRecords2(myfield char(40));
create table tblRecords3(myfield1 char(40), myfield2 int);

Then I ran your two statements back to back:

insert into tblRecords2(myField) values ('A7962144F9C16EE22672D96C6655063');
insert into tblRecords3(myField1,myField2) values (last_insert_rowid(),2);

This is the results I have in both tables:

select rowid, myfield from tblRecords2;
1|A7962144F9C16EE22672D96C6655063

select * from tblRecords3;
1|2

Hope that helps at least narrow down where to look.
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 500 total points
ID: 33592092
I also just ran the same test from Firefox plugin and worked also.
0
 
LVL 1

Author Comment

by:NTGuru705
ID: 33593207
Yep problem was the client I was testing with thanks
0
 
LVL 1

Author Closing Comment

by:NTGuru705
ID: 33593209
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now