in reply to Getting first unused integer from a sqlite integer column

You don't want to do that, that would cause race conditions. Use a sequence or an automatically incrementing column, for the latter in SQLite, see http://www.sqlite.org/autoinc.html.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re: Getting first unused integer from a sqlite integer column

Replies are listed 'Best First'.
Re^2: Getting first unused integer from a sqlite integer column
by mhearse (Chaplain) on Oct 21, 2010 at 19:32 UTC
    I agree about the race condition. I like the idea of using an autoincrement for the externalPort. Now I just need to figure out if I can set min and max bounds
    min: 1024 max: 65535

    Wait a minute... wouldn't redefining the table, making externalPort autoincrement, then creating a dummy record with externalPort = 1023 work? I'll give it a try.