#include <stdio.h>
#include <sqlite3.h>
//sqlite3 needs to be compiled if you don't have ubuntu
//if you have ubuntu use
//sudo apt install libsqlite3-dev 
//INSTALLS sqlite3.h headers without having to compile below
//then run using 
// gcc hello-world-sqlite-3.c -lsqlite3 -o hello-world-sqlite3.out
// ./hello-world-sqlite3.out
//to compile manually need to get source
//since programming in c, can use amalgamation source file sqlite3.c
//grab shell.c sqlite3.c and sqlite3.h from tarball
//gcc shell.c sqlite3.c -lpthread -ldl
//pthread library  multi thread
//dl dynamic loading
//full -lreadline -lncurses -o sqlite3
//o = output file name
//sudo apt install libreadline-dev libncurses-dev

 
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(int argc, char **argv){
  sqlite3 *db;
  char *zErrMsg = 0;
  int rc;

  
  rc = sqlite3_open("barcodes.sqlite3", &db);
  if( rc ){
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return(1);
  }
  rc = sqlite3_exec(db, "SELECT * FROM barcodes;", callback, 0, &zErrMsg);
  if( rc!=SQLITE_OK ){
    fprintf(stderr, "SQL error: %s\n", zErrMsg);
    sqlite3_free(zErrMsg);
  }
  sqlite3_close(db);
  return 0;
}

