Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created October 28, 2016 15:55
Show Gist options
  • Save AndyNovo/3a5d5e76b0472c08227675b8cc96f056 to your computer and use it in GitHub Desktop.
Save AndyNovo/3a5d5e76b0472c08227675b8cc96f056 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(){
sqlite3* db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("mail.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
};
char* sql = "CREATE TABLE USERS( ID INT PRIMARY KEY, NAME TEXT );";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout, "Table created successfully\n");
}
sqlite3_close(db);
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment