Is there a simple way to get the integer primary key of a new record inserted in a SQLite table

Jan Schenkel janschenkel at yahoo.com
Mon Oct 27 08:21:59 EDT 2008


--- Reinhold Venzl-Schubert
<r.venzl-schubert at macbay.de> wrote:
> Hi!
> 
> I'm looking for a simple way to get the integer
> primery key of a new  
> record (row) in a table that is created
> automatically by SQLite.
> 
> I store text and images in different tables and the
> primery key of  
> the text-record (row) is the reference to find the
> corresponding  
> images in the image-table.
> 
> When I select a text-record (row) it is easy to get
> the primery key.  
> But when I just created a new text-record (row) I
> don't know the  
> primery key to store the images.
> 
> Is there any easy way, or do I have to store the new
> text first,  
> select the new text then again to get the primery
> key and after all  
> to use the primery key to store the images?
> 
> Thanks
> Reinhold
> 

Hi Reinhold,

Since you're working in single-user modus, you don't
need to worry about record insterions by multiple
users; so if your primary key is just an
auto-incrementing integer field, you may as well issue
a query "SELECT MAX(text_Id) FROM Text" after
inserting the Text record, and then use that in your
Image insert command.

Jan Schenkel.

Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)


      



More information about the use-livecode mailing list