diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-04-13 03:09:03 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-04-13 03:09:03 +0300 |
commit | 0168c10023f0040ae2fa31a212eb6d2e411eefb3 (patch) | |
tree | 4d9565bd30d392ee84c97af324ce56df9fbd0e42 /src/main.c | |
parent | ef16959b92ff9bd6a88e21536e48f9946170d4a2 (diff) | |
download | ck-0168c10023f0040ae2fa31a212eb6d2e411eefb3.tar.gz ck-0168c10023f0040ae2fa31a212eb6d2e411eefb3.tar.bz2 ck-0168c10023f0040ae2fa31a212eb6d2e411eefb3.zip |
Find sqlite3 and some tests
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 87 |
1 files changed, 83 insertions, 4 deletions
@@ -1,6 +1,85 @@ -#include "stdio.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sqlite3.h> -int main() -{ - printf("Hello World\n"); +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; +} + +void initDb(sqlite3 *db) { + char *zErrMsg = 0; + char *sql; + int rc; + + /* Create SQL statement */ + sql = "CREATE TABLE PROGRAM(" \ + "id INT PRIMARY KEY NOT NULL," \ + "name TEXT NOT NULL);"; + + /* Execute SQL statement */ + 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"); + } + sql = "CREATE TABLE CONFIG(" \ + "id INT PRIMARY KEY NOT NULL," \ + "path TEXT NOT NULL," \ + "secret INT NOT NULL," \ + "prime INT NOT NULL);"; + + /* Execute SQL statement */ + 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"); + } + sql = "CREATE TABLE REL(" \ + "pId INT NOT NULL," \ + "cId INT NOT NULL);"; + + /* Execute SQL statement */ + 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"); + } +} + + int main(int argc, char* argv[]) { + sqlite3 *db; + int rc; + + /* Open database */ + rc = sqlite3_open("ckdb", &db); + + if (rc) { + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + return(0); + } + else { + fprintf(stdout, "Opened database successfully\n"); + } + + if (strcmp("init", argv[1]) == 0) { + initDb(db); + } + + sqlite3_close(db); + return 0; } |