On 7/28/06, Mario Frasca <[EMAIL PROTECTED]> wrote:
On 2006-0728 16:07:47, Nemanja Corlija wrote:
> You can insert default value like this:
>  insert into test (f) values (NULL);
>
> Inserting NULL into autoincrement field just increments it. While
> omitting value for any other field uses default for that field, if one
> is defined.

next question: is there a way to ask which was the last (autoincremented)
value inserted in the table?  or is there a guarantee that this works,
as it seems...

select max(f) from test;

You can get that with this query:
 select seq from sqlite_sequence where name='test'

'test' is the name of your table and "seq" field keeps the
last/highest value that was inserted in AUTOINCREMENT field.

This will only work if you define your table to use true AUTOINCREMENT
field, like we did in this example. If you use just INTEGER PRIMARY
KEY, without AUTOINCREMENT, that  table doesn't have a record in
sqlite_sequence table. For the later case "select max(f) from test;"
would work. Though that's not what we have here.

There is also a last_insert_rowid() function that is like an alias for
sqlite_last_insert_rowid() API function and it works per db
connection. I don't think this this is very useful with true
AUTOINCREMENT fields, so sqlite_sequence is really the way to go.

--
Nemanja Corlija <[EMAIL PROTECTED]>

Reply via email to