Solved

Sqlite last_insert_rowid() Help!

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

832 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