[In the message "[sqlite] What about with LAST_INSERT_ROWID() ?" on Jun 22, 
15:09, litenoob writes:]
> 
> Hmm.. don't know sed or awk, but I suppose this weekend would be a good time
> to learn!
> 
> Alright, going along with this, is there a better way to get the last row id
> inserted?  This is my (completely inefficient) workaround:
> 
> - - - - -
> 
> sqlite3 $dbfilename << EOF
> 
> INSERT INTO tablename (col1, col2) VALUES ("foovaluoo", 3.14159265);
> 
> .output t_rowid.tmp
> SELECT LAST_INSERT_ROWID() FROM $db_table LIMIT 1;
> 
> .quit
> EOF
> 
> read tehrowish < t_rowid.tmp
> rm t_rowid.tmp
> 
> - - - - -
> 
> Basically, I want to insert something into the DB, then get the row id of
> that insertion.  I know I have to do it in one session, otherwise
> LAST_INSERT_ROWID() returns 0.

Well cut, sed, awk would be usefull if you are to push this idea
further.
For your needs I just tested the following code:

--
#/bin/sh
ROW_ID=`sqlite3 test.db <<END
insert into t values(1,2);
select last_insert_rowid() from t limit 1;
END
`
echo ROW_ID=$ROW_ID
--

And it worked just fine. I am sure bash is compatible with Bourne shel.

Thanks,
Nikola

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to