fixed bug in accessing null pointer
fixed double call to sqlite3_close()
fixed initialisation of random ids