Solved

Sqlite last_insert_rowid() Help!

Posted on 2010-09-02
5
1,917 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

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. …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

730 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