Lots of rearranging. Source now found in the trunk/src folder.
[asgard.git] / database / sqlite3.cpp
blobfdaecefbe01a12eb82807f9eafd90aab271d3b15
1 #include <iostream>
2 #include <string>
3 #include <fstream>
4 #include <sqlite3.h>
5 #include <sstream>
7 using std::cout;
8 using std::string;
9 using std::ifstream;
10 using std::stringstream;
11 using std::endl;
14 /*static int callback(void *NotUsed, int argc, char ** argv, char **azColName)
16 return 0;
17 }*/
19 int main(int argc, char **argv)
21 sqlite3 *db;
22 char *zErrMsg = 0;
23 int rc;
24 char line[1024];
25 ifstream sqlite_script;
26 string query;
28 if (argc >= 1 && argc < 3)
30 cout << "usage: querydb <database> <sqlite_script>\n";
31 return 0;
35 query = "";
36 sqlite_script.open(argv[2]);
37 while (!sqlite_script.eof())
39 sqlite_script.getline(line,1024);
40 query += string(line) + "\n";
43 sqlite_script.close();
45 rc = sqlite3_open(argv[1], &db);
46 rc = sqlite3_exec(db, query.c_str(), 0, 0, &zErrMsg);
48 if (rc > 0)
50 cout << "Error " << rc << endl;
51 cout << sqlite3_errmsg(db);
52 cout << endl;
54 else
55 cout << "Ok." << endl;
57 sqlite3_close(db);
59 return 0;