added test case and fixed sqlite3 bugs