-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
47 lines (37 loc) · 1.03 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// File used to test things
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
int i;
for (i = 0; i < argc; i++) {
if (strcmp(azColName[i], "id") == 0 || strcmp(azColName[i], "badges") == 0) {
printf("%s = %d\n", azColName[i], argv[i] ? atoi(argv[i]) : 0);
} else if (strcmp(azColName[i], "username") == 0) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
}
printf("\n");
return 0;
}
int main() {
sqlite3 *db;
char *err_msg = 0;
int rc = sqlite3_open("/data/hello.db", &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
char *sql = "SELECT * FROM user;";
rc = sqlite3_exec(db, sql, callback, 0, &err_msg);
if (rc != SQLITE_OK ) {
fprintf(stderr, "SQL error: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
return 1;
}
sqlite3_close(db);
return 0;
}