7 #include <postgresql_db.h> |
7 #include <postgresql_db.h> |
8 #else |
8 #else |
9 #include <mysql_db.h> |
9 #include <mysql_db.h> |
10 #endif |
10 #endif |
11 |
11 |
|
12 #include <cstdlib> |
|
13 |
|
14 void usage (std::string progname) |
|
15 { |
|
16 std::cout << "Benutzung: " << progname << " [-r <remotehost>] [-u <user>] [-p <password>] [-h] DATABASE\n" << std:: |
|
17 endl; |
|
18 std::cout << "Berichten Sie Fehler oder Anregungen an mbroeker@largo.homelinux.org" << std::endl; |
|
19 exit (0); |
|
20 } |
|
21 |
12 int main (int argc, char **argv) |
22 int main (int argc, char **argv) |
13 { |
23 { |
14 Abstract_DB *db; |
24 Abstract_DB *db; |
15 |
25 |
16 Abstract_DB::DB_ROW vec; |
26 Abstract_DB::DB_ROW vec; |
17 Abstract_DB::DB_RESULT result; |
27 Abstract_DB::DB_RESULT result; |
18 unsigned int i, j; |
28 unsigned int i, j; |
|
29 char c; |
|
30 |
|
31 std::string host, user, pass, database; |
|
32 std::string sql_statement; |
|
33 |
|
34 while ((c = getopt (argc, argv, "r:u:p:d:h")) >= 0) { |
|
35 switch (c) { |
|
36 case 'r': |
|
37 host = optarg; |
|
38 break; |
|
39 case 'u': |
|
40 user = optarg; |
|
41 break; |
|
42 case 'p': |
|
43 pass = optarg; |
|
44 break; |
|
45 case 'h': |
|
46 usage (argv[0]); |
|
47 break; |
|
48 } |
|
49 } |
|
50 if (optind < argc) |
|
51 database = argv[optind]; |
|
52 else |
|
53 usage (argv[0]); |
19 |
54 |
20 #ifdef WITH_POSTGRESQL |
55 #ifdef WITH_POSTGRESQL |
21 db = new PostgreSQL_DB ("", "largo", "", "clubstatistik"); |
56 db = new PostgreSQL_DB (host, user, pass, database); |
22 #else |
57 #else |
23 db = new MySQL_DB ("localhost", "dbuser", "dbpasswd", "datenbank"); |
58 db = new MySQL_DB (host, user, pass, database); |
24 #endif |
59 #endif |
25 |
60 |
26 if (db->connect () == false) { |
61 if (db->connect () == false) { |
27 std::cerr << "Kann mich nicht zur Datenbank verbinden. Passwoerter falsch?" << std::endl; |
62 std::cerr << "Kann mich nicht zur Datenbank verbinden. Passwoerter falsch?" << std::endl; |
28 return EXIT_FAILURE; |
63 return EXIT_FAILURE; |
29 } |
64 } |
30 |
65 |
31 result = db->query ("select * from euroleague"); |
66 for (;;) { |
|
67 // std::getline(std::cin, sql_statement); |
|
68 std::cout << "DB_BRIDGE # "; |
|
69 std::getline (std::cin, sql_statement); |
32 |
70 |
33 for (i = 0; i < result.size (); i++) { |
71 if (sql_statement == "quit" || sql_statement == "exit" || sql_statement == "") { |
34 vec = result[i]; |
72 std::cout << std::endl; |
35 for (j = 0; j < vec.size (); j++) { |
73 break; |
36 std::cout << vec[j] << " "; |
|
37 } |
74 } |
38 std::cout << std::endl; |
75 result = db->query (sql_statement); |
|
76 |
|
77 for (i = 0; i < result.size (); i++) { |
|
78 vec = result[i]; |
|
79 for (j = 0; j < vec.size (); j++) { |
|
80 std::cout << vec[j] << " "; |
|
81 } |
|
82 std::cout << std::endl; |
|
83 } |
39 } |
84 } |
40 |
85 |
41 delete db; |
86 delete db; |
42 |
87 |
43 return EXIT_SUCCESS; |
88 return EXIT_SUCCESS; |