Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sqlite3.h"
- #include <stdio.h>
- void init_db()
- {
- sqlite3* db;
- sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
- sqlite3_exec(db, "CREATE TABLE test (a INTEGER);", 0, 0, 0);
- sqlite3_close(db);
- }
- void handle_result(const char* tag, int result)
- {
- if (result != SQLITE_OK)
- printf("%s - %d\n", tag, result);
- }
- void insert(sqlite3* db)
- {
- int result = sqlite3_exec(db, "INSERT INTO test VALUES (42);", 0, 0, 0);
- handle_result("insert", result);
- }
- void select(sqlite3* db)
- {
- int result = sqlite3_exec(db, "SELECT * FROM test;", 0, 0, 0);
- handle_result("select", result);
- }
- int main()
- {
- sqlite3_enable_shared_cache(1);
- init_db();
- sqlite3* dbRead;
- sqlite3_open_v2("test.db", &dbRead, SQLITE_OPEN_READONLY, 0);
- sqlite3* dbWrite;
- sqlite3_open_v2("test.db", &dbWrite, SQLITE_OPEN_READWRITE, 0);
- select(dbRead);
- insert(dbWrite);
- sqlite3_close(dbRead);
- sqlite3_close(dbWrite);
- }
Advertisement
Add Comment
Please, Sign In to add comment