Just a regular commit
[backups/.git] / main.cc
1 #include <iostream>
2 #include <iterator>
3 #include <string>
4 #include <vector>
5 #include <algorithm>
6
7 #include <sqlite3.h>
8
9 using namespace std;
10
11 vector<string> split( const string &line, char c, int limit = -1 ) {
12   string::size_type start = 0, end = 0;
13
14   vector<string> out;
15   while( 0 != limit-- && end != line.size() ) {
16     if( 0 == limit ) {
17       end = line.size();
18     } else {
19       end = line.find( c, start );
20       if( end == string::npos ) {
21         end = line.size();
22       }
23     }
24     out.push_back( line.substr( start, end-start ) );
25     start = end + 1;
26   }
27   return out;
28 }
29
30 int callback( void *NotUsed, int argc, char **argv, char **azColName ) {
31   int i;
32   for( int i = 0; i < argc; ++i ) {
33     cout << azColName[i] << " = " << ( argv[i] ? argv[i] : "NULL" ) << endl;
34   }
35   cout << endl;
36   return 0;
37 }
38
39 void sql_experimenting() {
40   sqlite3 *db;
41   char *sqliteErrMsg = 0;
42   int rc;
43
44   const char *dbname = "test.db";
45   rc = sqlite3_open( dbname, &db );
46   if( SQLITE_OK != rc ) {
47     cerr << "Cannot open database: " << dbname << ".  Error message is..." << endl;
48     cerr << sqlite3_errmsg(db) << endl;
49   }
50
51   rc = sqlite3_exec( db, "select * from filedata;", callback, 0, &sqliteErrMsg );
52   if( SQLITE_OK != rc ) {
53     cerr << "Problem with database.  Message is..." << endl;
54     cerr << sqliteErrMsg << endl;
55   }
56
57   sqlite3_close( db );
58 }
59
60 int main() {
61 //   string file_string;
62 //   do {
63 //     file_string.clear();
64 //     for( int c = cin.get(); 0 != c && ! cin.eof(); c = cin.get() ) {
65 //       file_string.push_back( c );
66 //     }
67 //     if( 0 != file_string.size() ) {
68 //       // Example entry
69 //       // type perms user group size datemodified name (7 total)
70 //       // f 0600 cnb cnb 424 20051015205340 ./.git/index
71 //       vector<string> values = split( file_string, ' ', 7 );
72 //     }
73 //   } while( ! cin.eof() );
74
75   sql_experimenting();
76 }