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

how about just
select min(port_num)+1 from table_name
if you need the values of other columns, since this is a aggregate select statement, you'd use a "first" or "max" or similar to get the desired values from those other columns. in other words if you use any aggregate sql function on any column, you'll need to use aggregate functions on all columns, which provides a proper set of rows that makes sense.
the hardest line to type correctly is: stty erase ^H