in reply to Finding the next avaliable id in a SQLite database

As long as you declare your ID as INTEGER PRIMARY KEY , and insert a NULL value into it, it will autoincrement, and you can get the value it had through $dbh->func('last_insert_rowid')

That is the best way to do it. If you find the largest value, increment it by one and write a record with it, you will introduce a race condition - and that will bite you when you least expect it (probably once you've gone into production).

  • Comment on Re: Finding the next avaliable id in a SQLite database