Skip to content

Instantly share code, notes, and snippets.

@psarna
Last active October 2, 2022 11:15
Show Gist options
  • Save psarna/d546e327d1c431d3b5e035858441af5e to your computer and use it in GitHub Desktop.
Save psarna/d546e327d1c431d3b5e035858441af5e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include "sqlite3.h"
int main(void) {
sqlite3 *db;
sqlite3_stmt *stmt;
sqlite3_open("/tmp/test.db", &db);
// This query assumes that a table was already created manually: CREATE TABLE t(id int)
sqlite3_prepare_v2(db, "insert into t(id) values (42)", -1, &stmt, NULL);
int rc = SQLITE_OK;
while ((rc = sqlite3_step(stmt)) != SQLITE_DONE) {
fprintf(stderr, "Got %s\n", sqlite3_errstr(rc));
}
fprintf(stderr, "Final: %s\n", sqlite3_errstr(rc));
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment