| 39 | |
| 40 | template <typename D> |
| 41 | static string createCSV( |
| 42 | D& db, const string& t, const string& csv) |
| 43 | { |
| 44 | ofstream csvf(csv.c_str()); |
| 45 | stringstream ps, ss, msg; |
| 46 | string pstr, sstr; |
| 47 | dbVec head, val; |
| 48 | |
| 49 | ps << "pragma table_info (" << t << ");"; |
| 50 | pstr = ps.str(); |
| 51 | head = db.readSqlToVec(pstr.c_str()); |
| 52 | |
| 53 | for (unsigned i=0; i<head.size(); i++) |
| 54 | csvf << head[i][1] << ((i == (head.size()-1)) ? "" : ","); |
| 55 | csvf << endl; |
| 56 | |
| 57 | ss << "select * from " << t << ";"; |
| 58 | sstr = ss.str(); |
| 59 | val = db.readSqlToVec(sstr.c_str()); |
| 60 | |
| 61 | for (unsigned i=0; i<val.size(); i++) { |
| 62 | for (unsigned j=0; j<val[i].size(); j++) |
| 63 | csvf << val[i][j] << ((j == (val[i].size()-1)) ? "" : ","); |
| 64 | csvf << endl; |
| 65 | } |
| 66 | msg << csv << " has been created.\n"; |
| 67 | return msg.str(); |
| 68 | } |
| 69 | |
| 70 | template <typename D> |
| 71 | static void populateOneTable( |
no test coverage detected