Move sqlite example into sqlite directory
This commit is contained in:
parent
cd4f1433a3
commit
538a9987e0
1 changed files with 0 additions and 0 deletions
46
sqlite/sqlite.c
Normal file
46
sqlite/sqlite.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <sqlite3.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* See: https://zetcode.com/db/sqlitec/
|
||||
* Build with:
|
||||
* gcc -o version version.c -lsqlite3 -std=c99
|
||||
*/
|
||||
|
||||
int main(void) {
|
||||
printf("%s\n", sqlite3_libversion());
|
||||
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
|
||||
int rc = sqlite3_open(":memory:", &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = sqlite3_prepare_v2(db, "SELECT SQLITE_VERSION()", -1, &res, 0);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
if (rc == SQLITE_ROW) {
|
||||
printf("%s\n", sqlite3_column_text(res, 0));
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue