#include <iostream>
#include "sqlite3.h"

using namespace std;

static int callback(void *unused, int argc, char **argv, char **colName){
	for(int i=0; i<argc; i++){
		cout<<colName[i]<<" = "<< (argv[i] ? argv[i] : "NULL") <<endl;
	}
	cout<<endl;
	return 0;
}

int main(){
	cout<<"Example RM Database Query\n";
	sqlite3 *db;
	int rc = sqlite3_open("test.rmgc", &db);
	if(rc){
		cerr<<"Error opening database file\n";
		return 1;
	}
	cout<<"Database table opened successfully\n";
	const char *sql = "SELECT * FROM NameTable LIMIT 20";
	char *error=NULL;
	rc = sqlite3_exec(db, sql, callback, NULL, &error);
	if(rc){
		cerr<<"Error executing query\n";
		sqlite3_free(error);
	}
	sqlite3_close(db);
	system("PAUSE");
}