I'm trying to create a sqlite3 database in Xcode.
Here is the code I'm using:
#include <stdlib.h>
#include <stdio.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
printf("called here");
return 0;
}
int main(int argc, const char * argv[]) {
sqlite3 *db;
char *zErrMsg = 0;
int result = sqlite3_open("noodle.sqlite3", &db);
if (result != SQLITE_OK) {
printf("did not work\n");
exit(0);
}
char *sql = "CREATE TABLE TEST (ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL);";
result = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if (result != SQLITE_OK) {
printf("heya");
exit(0);
}
char *sql2 = "INSERT INTO TEST VALUES (3, 'NEATO');";
result = sqlite3_exec(db, sql2, callback, 0, &zErrMsg);
if (result != SQLITE_OK) {
printf("dangit");
exit(0);
}
const char* data = "Callback function called";
char *sql3 = "SELECT * FROM TEST;";
result = sqlite3_exec(db, sql3, callback, (void *)data, &zErrMsg);
return 0;
}
And I'm following this tutorial. But the directory that I have my main.c
file in never sees the creation of a noodle.sqlite3
file.
What am I doing wrong? I thought sqlite3_open
creates the database if one doesn't exist already.
Aucun commentaire:
Enregistrer un commentaire