diff --git a/db_bridge/main.cpp b/db_bridge/main.cpp --- a/db_bridge/main.cpp +++ b/db_bridge/main.cpp @@ -9,6 +9,16 @@ #include #endif +#include + +void usage (std::string progname) +{ + std::cout << "Benutzung: " << progname << " [-r ] [-u ] [-p ] [-h] DATABASE\n" << std:: + endl; + std::cout << "Berichten Sie Fehler oder Anregungen an mbroeker@largo.homelinux.org" << std::endl; + exit (0); +} + int main (int argc, char **argv) { Abstract_DB *db; @@ -16,11 +26,36 @@ Abstract_DB::DB_ROW vec; Abstract_DB::DB_RESULT result; unsigned int i, j; + char c; + + std::string host, user, pass, database; + std::string sql_statement; + + while ((c = getopt (argc, argv, "r:u:p:d:h")) >= 0) { + switch (c) { + case 'r': + host = optarg; + break; + case 'u': + user = optarg; + break; + case 'p': + pass = optarg; + break; + case 'h': + usage (argv[0]); + break; + } + } + if (optind < argc) + database = argv[optind]; + else + usage (argv[0]); #ifdef WITH_POSTGRESQL - db = new PostgreSQL_DB ("", "largo", "", "clubstatistik"); + db = new PostgreSQL_DB (host, user, pass, database); #else - db = new MySQL_DB ("localhost", "dbuser", "dbpasswd", "datenbank"); + db = new MySQL_DB (host, user, pass, database); #endif if (db->connect () == false) { @@ -28,14 +63,24 @@ return EXIT_FAILURE; } - result = db->query ("select * from euroleague"); + for (;;) { + // std::getline(std::cin, sql_statement); + std::cout << "DB_BRIDGE # "; + std::getline (std::cin, sql_statement); - for (i = 0; i < result.size (); i++) { - vec = result[i]; - for (j = 0; j < vec.size (); j++) { - std::cout << vec[j] << " "; + if (sql_statement == "quit" || sql_statement == "exit" || sql_statement == "") { + std::cout << std::endl; + break; } - std::cout << std::endl; + result = db->query (sql_statement); + + for (i = 0; i < result.size (); i++) { + vec = result[i]; + for (j = 0; j < vec.size (); j++) { + std::cout << vec[j] << " "; + } + std::cout << std::endl; + } } delete db;