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

You almost never want to “re-use” such a number ... even though it is technically possible.   In fact, I don’t even (typically) use autoincrement fields any more.   I use randomly-generated strings, long enough to allow me to basically say that every value will be unique.   No matter what.   No matter many times I run the program or how I slog-up my database.

“All integers look alike,” and y’know, that’s really not such a good thing, after all.   But if you now attempt to re-use them, you have just introduced an inherent ambiguity that can never be proofed.   The data may become inconsistent, through programmer-error or by any other means, and you can never explain how or when it happened.   The data may be incorrect, and it is impossible to (algorithmically) detect it.   These are not wise properties for a production system to have.

“Each town ... is very like another when your head’s down over the pieces, brother ...”
-- One Night In Bangkok   (from “Chess”)

Replies are listed 'Best First'.
Re^2: Getting first unused integer from a sqlite integer column
by aquarium (Curate) on Oct 22, 2010 at 03:59 UTC
    totally agree with that sort of position. you probably want to stat the interface/IP for what ports are currently in use, and then pick a random one that's not in well-known ranges, e.g. port 8000, 8005 or 8080 etc can typically be used. you can dig up the table of unassigned port numbers that aren't going to interfere with most apps.
    keeping track of live connections (port numbers used) in a database, as a way of picking next ones to use, is probably not a great thing.
    the hardest line to type correctly is: stty erase ^H