Solved

Sqlite last_insert_rowid() Help!

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

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 60

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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