Solved

Sqlite last_insert_rowid() Help!

Posted on 2010-09-02
5
1,903 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

861 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