/** * Populate SQLite database table(s) and export to CSV */ #include "DB.h" #include using namespace std; static const char USAGE_MESSAGE[] = "usage:\ \nabyss-db-csv SQLite_repository table_name(s)\ \nabyss-db-csv SQLite_repository --all\n"; static const char TABLE_LIST[] = "select name from sqlite_master where type='table';"; typedef vector vs; static bool existFile(const char* f) { return (bool)ifstream(f); } template static bool existTable( D& db, const string& t) { dbVec v = db.readSqlToVec(TABLE_LIST); unsigned i = 0; while (i static string createCSV( D& db, const string& t, const string& csv) { ofstream csvf(csv.c_str()); stringstream ps, ss, msg; string pstr, sstr; dbVec head, val; ps << "pragma table_info (" << t << ");"; pstr = ps.str(); head = db.readSqlToVec(pstr.c_str()); for (unsigned i=0; i static void populateOneTable( D& db, const string& repo, const string& t) { string tt(db.getProperTableName(t)); stringstream csv; csv << "db." << tt << ".csv"; if (!existTable(db, tt)) { cout << "Table " << "'" << tt << "' doesn't exist in " << repo << "." << endl; cout << USAGE_MESSAGE; exit(EXIT_FAILURE); } cout << createCSV(db, tt, csv.str()); } template static void populateAll( D& db, const string& repo) { dbVec v = db.readSqlToVec(TABLE_LIST); for (unsigned i=0; i