Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sqlite3.h>
- should contain sqlite3_prepare_v2 and struct sqlite3. Make sure you're including the right sqlite3.h file.
- Also in sqlite3_prepare_v2 the 3rd arg can be (and should be in your case) -1 so the sql is read to the first null terminator.
- Working bare-metal sample using sqlite 3.7.11:
- #include <sqlite3.h>
- int test()
- {
- sqlite3* pDb = NULL;
- sqlite3_stmt* query = NULL;
- int ret = 0;
- do // avoid nested if's
- {
- // initialize engine
- if (SQLITE_OK != (ret = sqlite3_initialize()))
- {
- printf("Failed to initialize library: %d\n", ret);
- break;
- }
- // open connection to a DB
- if (SQLITE_OK != (ret = sqlite3_open_v2("test.db", &pDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)))
- {
- printf("Failed to open conn: %d\n", ret);
- break;
- }
- // prepare the statement
- if (SQLITE_OK != (ret = sqlite3_prepare_v2(pDb, "SELECT 2012", -1, &query, NULL)))
- {
- printf("Failed to prepare insert: %d, %s\n", ret, sqlite3_errmsg(pDb));
- break;
- }
- // step to 1st row of data
- if (SQLITE_ROW != (ret = sqlite3_step(query))) // see documentation, this can return more values as success
- {
- printf("Failed to step: %d, %s\n", ret, sqlite3_errmsg(pDb));
- break;
- }
- // ... and print the value of column 0 (expect 2012 here)
- printf("Value from sqlite: %s", sqlite3_column_text(query, 0));
- } while (false);
- // cleanup
- if (NULL != query) sqlite3_finalize(query);
- if (NULL != pDb) sqlite3_close(pDb);
- sqlite3_shutdown();
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement