Created
October 26, 2012 01:00
-
-
Save psyomn/3956399 to your computer and use it in GitHub Desktop.
Creating a table in SQLite3 + C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sqlite3.h> | |
static int | |
print_table_variables | |
( | |
void * NotUsed | |
, int rows_affected | |
, char ** field_value | |
, char ** column_name | |
) | |
{ | |
int i; | |
for(i=0; i<rows_affected; ++i) | |
{ | |
printf("%s = %s\n", column_name[i], field_value[i] ? field_value[i] : "NULL"); | |
} | |
return 0; | |
} | |
int main() | |
{ | |
int ret; | |
sqlite3 * connection; | |
char ** errmsg; | |
const char * create_table_sql = | |
"CREATE TABLE person" | |
"(" | |
" id INTEGER PRIMARY KEY " | |
" , name VARCHAR(50)" | |
" , date INTEGER" | |
");" | |
; | |
ret = sqlite3_open("database.db", &connection); | |
if (SQLITE_OK==ret) | |
{ | |
printf("Everything is ok\n"); | |
ret = | |
sqlite3_exec | |
( | |
connection | |
, create_table_sql | |
, 0 | |
, 0 | |
, 0 | |
); | |
if (SQLITE_OK!=ret) | |
{ | |
perror("error"); | |
} | |
} | |
else | |
{ | |
perror("error"); | |
} | |
sqlite3_close(connection); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment