Skip to content

Commit

Permalink
Initial import, now just a hello world C/sqlite program
Browse files Browse the repository at this point in the history
Use it as:

./hailo hailo.brn "SELECT count(*) FROM expr;
  • Loading branch information
avar committed Mar 21, 2010
0 parents commit ffe34da
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
hailo
*.brn
*.trn
2 changes: 2 additions & 0 deletions Makefile
@@ -0,0 +1,2 @@
all:
gcc -Wall -lsqlite3 hailo.c -o hailo
34 changes: 34 additions & 0 deletions hailo.c
@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.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(const int argc, const char **argv) {
sqlite3 *db;
char *zErrMsg = NULL;
int rc;

rc = sqlite3_open(argv[1], &db);
if ( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}

rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);

return 0;
}

0 comments on commit ffe34da

Please sign in to comment.