int main(int argc, char **argv) { sqlite3 *db; int rc; char *sql; int is_fine = 1; if (access("demo.db", R_OK|W_OK)) { is_fine = 0; } rc = sqlite3_open("demo.db", &db); if(rc) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); goto quit; } /* initialize db */ if (!is_fine) { rc = _db_init(db); if (rc) { goto quit; } } _db_show_all(db); char name[32]; db_get_account_name_by_id(db, name, 2); fprintf(stdout, "name of id %d is %s\n", 2, name); /* register hooks */ char *data = "this is a hook test"; sqlite3_commit_hook(db, _db_commit_hook, data); sqlite3_update_hook(db, _db_update_hook, data); sqlite3_set_authorizer(db, _db_auth_hook, data); puts("insert"); sql = "insert into account (name,rank) values ('guest',2);"; rc = sqlite3_exec(db, sql, NULL, NULL, NULL); _db_show_all(db); puts("update"); sql = "update account set name='test' where id=4;"; rc = sqlite3_exec(db, sql, NULL, NULL, NULL); _db_show_all(db); puts("delete"); sql = "delete from account where name='test';"; rc = sqlite3_exec(db, sql, NULL, NULL, NULL); _db_show_all(db); quit: sqlite3_close(db); return 0; }
void* Utility::eventHookRegister(sqlite3* pDB, CommitCallbackType callbackFn, void* pParam) { return sqlite3_commit_hook(pDB, callbackFn, pParam); }
void database::set_commit_handler(commit_handler h) { ch_ = h; sqlite3_commit_hook(db_, ch_ ? commit_hook_impl : 0, &ch_); }
__declspec(dllexport) void * WINAPI sqlite3_commit_hook_interop(sqlite3 *pDb, SQLITECOMMITHOOK func) { return sqlite3_commit_hook(pDb, sqlite3_commit_callback, func); }
/** @SYMTestCaseID SYSLIB-SQLITE3-UT-4004 @SYMTestCaseDesc Database handle SQLITE3 tests. List of called SQLITE3 functions: - sqlite3_config; - sqlite3_initialize; - sqlite3_threadsafe; - sqlite3_vfs_find; - sqlite3_open; - sqlite3_db_config; - sqlite3_libversion; - sqlite3_libversion_number; - sqlite3_set_authorizer; - sqlite3_commit_hook; - sqlite3_rollback_hook; - sqlite3_update_hook; - sqlite3_close; - sqlite3_shutdown; @SYMTestPriority High @SYMTestActions Database handle SQLITE3 tests. @SYMTestExpectedResults Test must not fail @SYMREQ REQ8782 */ static void TestSqliteApi() { void* prev = 0; const char* libverstr = 0; int libvernum = 0; int err; int threadSafe = -1; sqlite3_vfs* vfs = 0; TEST(!TheDb); TestStart("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4004: Test \"sqlite3_config()\""); err = sqlite3_config(SQLITE_CONFIG_MEMSTATUS, 0); TEST2(err, SQLITE_OK); TestNext("Test \"sqlite3_initialize()\""); err = sqlite3_initialize(); TEST2(err, SQLITE_OK); TestNext("Test \"sqlite3_threadsafe()\""); threadSafe = sqlite3_threadsafe(); PrintI("SQLITE_THREADSAFE=%d\r\n", threadSafe); vfs = sqlite3_vfs_find(0); TEST(vfs != NULL); PrintS("Vfs name=\"%s\"\r\n", vfs->zName); err = sqlite3_open(TheTestDbName, &TheDb); TEST2(err, SQLITE_OK); TEST(TheDb != 0); err = sqlite3_db_config(TheDb, SQLITE_DBCONFIG_LOOKASIDE, 0, 128, 100); TEST2(err, SQLITE_OK); libverstr = sqlite3_libversion(); libvernum = sqlite3_libversion_number(); PrintSI("SQLITE version: \"%s\", Number: %d\r\n", libverstr, libvernum); err = sqlite3_set_authorizer(TheDb, &authorizer_callback, 0); TEST2(err, SQLITE_OK); prev = sqlite3_commit_hook(TheDb, &commit_hook, 0); TEST(!prev); prev = sqlite3_rollback_hook(TheDb, &rollback_hook, 0); TEST(!prev); prev = sqlite3_update_hook(TheDb, &update_hook, 0); TEST(!prev); TestNext("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4001: Test \"sqlite3\" handle API"); TestExec(); TestNext("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4002: Test \"sqlite3_stmt\" handle API-1"); TestStatement1(); TestNext("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4003: Test \"sqlite3_stmt\" handle API-2"); TestStatement2(); TestNext("@SYMTestCaseID:PDS-SQLITE3-UT-4038: Test more sqlite3 API"); TestSqliteApi2(); TestNext("@SYMTestCaseID:PDS-SQLITE3-UT-4039: Test blob API"); TestSqliteBlobApi(); TestNext("@SYMTestCaseID:PDS-SQLITE3-UT-4040: Test mutex API"); TestSqliteMutexApi(); err = sqlite3_close(TheDb); TEST2(err, SQLITE_OK); TheDb = 0; TestNext("Test \"sqlite3_shutdown()\""); err = sqlite3_shutdown(); TEST2(err, SQLITE_OK); err = remove(TheTestDbName); TEST2(err, 0); }