diff --git a/project/bin/Debug/project.exe b/project/bin/Debug/project.exe index e39a6d5..b040703 100644 Binary files a/project/bin/Debug/project.exe and b/project/bin/Debug/project.exe differ diff --git a/project/bin/Release/project.exe b/project/bin/Release/project.exe index 9184e25..53e0d18 100644 Binary files a/project/bin/Release/project.exe and b/project/bin/Release/project.exe differ diff --git a/project/bin/Release/release.zip b/project/bin/Release/release.zip deleted file mode 100644 index 92d031a..0000000 Binary files a/project/bin/Release/release.zip and /dev/null differ diff --git a/project/dbclient.cpp b/project/dbclient.cpp index 2fe4080..0961dfb 100644 --- a/project/dbclient.cpp +++ b/project/dbclient.cpp @@ -38,163 +38,163 @@ int main() char choice; int exit = 0; for(;!exit;){ - choice = 0; - cout << endl << endl << endl << "Was wollen Sie tun?:" << endl; - cout << "(e): Daten eingeben" << endl; - cout << "(a): Daten anzeigen" << endl; - cout << "(n): Daten aendern" << endl; - cout << "(l): Daten loeschen" << endl; - cout << "(s): schliessen" << endl; - cin >> choice; - switch(choice){ - case 'e': - menuInsert(); - break; - case 'a': - menuSelect(); - break; - case 'n': - menuUpdate(); - break; - case 'l': - menuDelete(); - break; - case 's': - exit = 1; - break; - } - } + choice = 0; + cout << endl << endl << endl << "Was wollen Sie tun?:" << endl; + cout << "(e): Daten eingeben" << endl; + cout << "(a): Daten anzeigen" << endl; + cout << "(n): Daten aendern" << endl; + cout << "(l): Daten loeschen" << endl; + cout << "(s): schliessen" << endl; + cin >> choice; + switch(choice){ + case 'e': + menuInsert(); + break; + case 'a': + menuSelect(); + break; + case 'n': + menuUpdate(); + break; + case 'l': + menuDelete(); + break; + case 's': + exit = 1; + break; + } + } } void initdb(){ - { ECPGconnect(__LINE__, 0, "CSDB@lamp.wlan.hwr-berlin.de" , "gr2" , "2Au-R2n-cQN-uuG" , NULL, 0); } + { ECPGconnect(__LINE__, 0, "CSDB@lamp.wlan.hwr-berlin.de" , "gr2" , "2Au-R2n-cQN-uuG" , NULL, 0); } #line 62 "F:\\postgrachelor\\project\\dbclient.pgc" - cout << "state: " << sqlca.sqlstate << endl; + cout << "state: " << sqlca.sqlstate << endl; { ECPGtrans(__LINE__, NULL, "commit");} #line 64 "F:\\postgrachelor\\project\\dbclient.pgc" } void menuInsert(){ - char choice = 0; - cout << "Welche Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - insertCategory(); - break; - case 'f': - insertQuestion(); - break; - } + char choice = 0; + cout << "Welche Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + insertCategory(); + break; + case 'f': + insertQuestion(); + break; + } } void menuSelect(){ - char choice = 0; - cout << "Welche Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - selectCategory(); - break; - case 'f': - selectQuestion(); - break; - } + char choice = 0; + cout << "Welche Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + selectCategory(); + break; + case 'f': + selectQuestion(); + break; + } } void menuUpdate(){ - char choice = 0; - cout << "In welcher Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - updateCategory(); - break; - case 'f': - updateQuestion(); - break; - } + char choice = 0; + cout << "In welcher Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + updateCategory(); + break; + case 'f': + updateQuestion(); + break; + } } void menuDelete(){ - char choice = 0; - cout << "Aus welcher Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - deleteCategory(); - break; - case 'f': - deleteQuestion(); - break; - } + char choice = 0; + cout << "Aus welcher Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + deleteCategory(); + break; + case 'f': + deleteQuestion(); + break; + } } void insertCategory(){ - /* exec sql begin declare section */ + /* exec sql begin declare section */ #line 133 "F:\\postgrachelor\\project\\dbclient.pgc" - char eingna [ 51 ] ; + char eingna [ 4001 ] ; /* exec sql end declare section */ #line 134 "F:\\postgrachelor\\project\\dbclient.pgc" string h = ""; - cout << "Eingabe Name: "; - getline(cin, h); - getline(cin, h); + cout << "Eingabe Name: "; + ws(cin); + getline(cin, h); - //cout << h << endl; - if (!(h.empty()||!strcmp(h.c_str(),"\n"))) - { - strcpy(eingna, h.c_str()); - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into gr2 . test ( name ) values ( $1 )", - ECPGt_char,(eingna),(long)51,(long)1,(51)*sizeof(char), + //cout << h << endl; + if (!(h.empty()||!strcmp(h.c_str(),"\n"))) + { + strcpy(eingna, h.c_str()); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into gr2 . \"Categories\" ( name ) values ( $1 )", + ECPGt_char,(eingna),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} #line 145 "F:\\postgrachelor\\project\\dbclient.pgc" - if (!strcmp(sqlca.sqlstate, "23505")) cout << "GIBT'S SCHON" << endl; - cout << "state: " << sqlca.sqlstate << endl; - { ECPGtrans(__LINE__, NULL, "commit");} + if (!strcmp(sqlca.sqlstate, "23505")) cout << "GIBT'S SCHON" << endl; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; + { ECPGtrans(__LINE__, NULL, "commit");} #line 148 "F:\\postgrachelor\\project\\dbclient.pgc" - } + } } void insertQuestion(){ - /* exec sql begin declare section */ - - - - - - - + /* exec sql begin declare section */ + + + + + + + #line 154 "F:\\postgrachelor\\project\\dbclient.pgc" - char question [ 181 ] ; + char question [ 4001 ] ; #line 155 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans0 [ 181 ] ; + char ans0 [ 4001 ] ; #line 156 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans1 [ 181 ] ; + char ans1 [ 4001 ] ; #line 157 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans2 [ 181 ] ; + char ans2 [ 4001 ] ; #line 158 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans3 [ 181 ] ; + char ans3 [ 4001 ] ; #line 159 "F:\\postgrachelor\\project\\dbclient.pgc" int category ; @@ -202,78 +202,90 @@ void insertQuestion(){ #line 160 "F:\\postgrachelor\\project\\dbclient.pgc" - cout << "Frage: "; - cin >> question; - cout << "Richtige Antwort: "; - cin >> ans0; - cout << "1. Falsche Antwort: "; - cin >> ans1; - cout << "2. Falsche Antwort: "; - cin >> ans2; - cout << "3. Falsche Antwort: "; - cin >> ans3; - cout << "ID der Kategorie:" << endl << "moegliche "; - selectCategory(); - cin >> category; - if(category){ - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into gr2 . testquestions ( question , answer0 , answer1 , answer2 , answer3 , category ) values ( $1 , $2 , $3 , $4 , $5 , $6 )", - ECPGt_char,(question),(long)181,(long)1,(181)*sizeof(char), + cout << "Frage: "; + ws(cin); + cin.getline(question, sizeof(question)); + cout << "Richtige Antwort: "; + ws(cin); + cin.getline(ans0, sizeof(ans0)); + cout << "1. Falsche Antwort: "; + ws(cin); + cin.getline(ans1, sizeof(ans1)); + cout << "2. Falsche Antwort: "; + ws(cin); + cin.getline(ans2, sizeof(ans2)); + cout << "3. Falsche Antwort: "; + ws(cin); + cin.getline(ans3, sizeof(ans3)); + cout << "ID der Kategorie:" << endl << "moegliche "; + selectCategory(); + cin >> category; + if(category){ + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into gr2 . \"Questions\" ( question , answer0 , answer1 , answer2 , answer3 , category ) values ( $1 , $2 , $3 , $4 , $5 , $6 )", + ECPGt_char,(question),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans0),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans0),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans1),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans1),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans2),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans2),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans3),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans3),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(category),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 176 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 181 "F:\\postgrachelor\\project\\dbclient.pgc" - if(!strcmp(sqlca.sqlstate, "23503")) cout << "Das ist keine gueltige Kategorie!" << endl; - cout << "state: " << sqlca.sqlstate << endl; - { ECPGtrans(__LINE__, NULL, "commit");} -#line 179 "F:\\postgrachelor\\project\\dbclient.pgc" + if(!strcmp(sqlca.sqlstate, "23503")) cout << "Das ist keine gueltige Kategorie!" << endl; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; + cout << "state: " << sqlca.sqlstate << endl; + { ECPGtrans(__LINE__, NULL, "commit");} +#line 185 "F:\\postgrachelor\\project\\dbclient.pgc" - } + } } void selectCategory(){ - //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! - /* exec sql begin declare section */ - - - -#line 186 "F:\\postgrachelor\\project\\dbclient.pgc" + //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! + /* exec sql begin declare section */ + + + +#line 192 "F:\\postgrachelor\\project\\dbclient.pgc" int id ; -#line 187 "F:\\postgrachelor\\project\\dbclient.pgc" - char name [ 51 ] ; -/* exec sql end declare section */ -#line 188 "F:\\postgrachelor\\project\\dbclient.pgc" - - - cout << "Kategorien:" << endl; - - /* declare xxx cursor for select \"ID\" , name from gr2 . test order by \"ID\" */ -#line 192 "F:\\postgrachelor\\project\\dbclient.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare xxx cursor for select \"ID\" , name from gr2 . test order by \"ID\"", ECPGt_EOIT, ECPGt_EORT);} #line 193 "F:\\postgrachelor\\project\\dbclient.pgc" + char name [ 4001 ] ; +/* exec sql end declare section */ +#line 194 "F:\\postgrachelor\\project\\dbclient.pgc" - int residl; - residl = id; + cout << "Kategorien:" << endl; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch first from xxx", ECPGt_EOIT, - ECPGt_int,&(id),(long)1,(long)1,sizeof(int), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(name),(long)51,(long)1,(51)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} + /* declare xxx cursor for select \"ID\" , name from gr2 . \"Categories\" order by \"ID\" */ #line 198 "F:\\postgrachelor\\project\\dbclient.pgc" - if(!strcmp(sqlca.sqlstate, "00000")) cout << id << " " << name << endl; + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare xxx cursor for select \"ID\" , name from gr2 . \"Categories\" order by \"ID\"", ECPGt_EOIT, ECPGt_EORT);} +#line 199 "F:\\postgrachelor\\project\\dbclient.pgc" + + + int residl; + residl = id; + + string hName = ""; + + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch first from xxx", ECPGt_EOIT, + ECPGt_int,&(id),(long)1,(long)1,sizeof(int), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_char,(name),(long)4001,(long)1,(4001)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 206 "F:\\postgrachelor\\project\\dbclient.pgc" + + if(!strcmp(sqlca.sqlstate, "00000")){ + hName = name; + hName.erase(hName.find_last_not_of(" \n\r\t")+1); + cout << id << " " << hName << endl; + } else if(!strcmp(sqlca.sqlstate, "02000")) cout << "Die Tabelle ist leer!"; while(id != residl) @@ -282,104 +294,132 @@ void selectCategory(){ { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch next from xxx", ECPGt_EOIT, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(name),(long)51,(long)1,(51)*sizeof(char), + ECPGt_char,(name),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 205 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 217 "F:\\postgrachelor\\project\\dbclient.pgc" - if(!strcmp(sqlca.sqlstate, "00000")) cout << id << " " << name << endl; + if(!strcmp(sqlca.sqlstate, "00000")){ + hName = name; + hName.erase(hName.find_last_not_of(" \n\r\t")+1); + cout << id << " " << hName << endl; + } } { ECPGtrans(__LINE__, NULL, "commit");} -#line 208 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 224 "F:\\postgrachelor\\project\\dbclient.pgc" } void selectQuestion(){ - //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! - /* exec sql begin declare section */ - - - - - - - - -#line 214 "F:\\postgrachelor\\project\\dbclient.pgc" + //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! + /* exec sql begin declare section */ + + + + + + + + + + +#line 230 "F:\\postgrachelor\\project\\dbclient.pgc" int id ; -#line 215 "F:\\postgrachelor\\project\\dbclient.pgc" - char question [ 181 ] ; +#line 231 "F:\\postgrachelor\\project\\dbclient.pgc" + char question [ 4001 ] ; -#line 216 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans0 [ 181 ] ; +#line 232 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans0 [ 4001 ] ; -#line 217 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans1 [ 181 ] ; +#line 233 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans1 [ 4001 ] ; -#line 218 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans2 [ 181 ] ; +#line 234 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans2 [ 4001 ] ; -#line 219 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans3 [ 181 ] ; +#line 235 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans3 [ 4001 ] ; -#line 220 "F:\\postgrachelor\\project\\dbclient.pgc" - char cat [ 51 ] ; +#line 236 "F:\\postgrachelor\\project\\dbclient.pgc" + char cat [ 4001 ] ; + +#line 237 "F:\\postgrachelor\\project\\dbclient.pgc" + int sites ; + +#line 238 "F:\\postgrachelor\\project\\dbclient.pgc" + int offset ; /* exec sql end declare section */ -#line 221 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 239 "F:\\postgrachelor\\project\\dbclient.pgc" - string hQuestion = "", hAns0 = "", hAns1 = "", hAns2 = "", hAns3 = "", hCat = ""; + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select ceil ( count ( * ) / 5.0 ) from gr2 . \"Questions\"", ECPGt_EOIT, + ECPGt_int,&(sites),(long)1,(long)1,sizeof(int), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 241 "F:\\postgrachelor\\project\\dbclient.pgc" - cout << "Fragen:" << endl << endl; + cout << "Es gibt " << sites << " Seiten. Welche soll angezeigt werden?" << endl; + cin >> offset; + while(offset > sites || offset < 1){ + cout << "Diese Seite gibt es nicht. Bitte gueltige Seitenzahl eingeben!" << endl; + cin >> offset; + } + offset = (offset-1)*5; - /* declare yyy cursor for select q . \"ID\" , q . question , q . answer0 , q . answer1 , q . answer2 , q . answer3 , c . name from gr2 . testquestions q join gr2 . test c on q . \"ID\" = c . \"ID\" order by c . \"ID\" */ -#line 227 "F:\\postgrachelor\\project\\dbclient.pgc" + string hQuestion = "", hAns0 = "", hAns1 = "", hAns2 = "", hAns3 = "", hCat = ""; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare yyy cursor for select q . \"ID\" , q . question , q . answer0 , q . answer1 , q . answer2 , q . answer3 , c . name from gr2 . testquestions q join gr2 . test c on q . \"ID\" = c . \"ID\" order by c . \"ID\"", ECPGt_EOIT, ECPGt_EORT);} -#line 228 "F:\\postgrachelor\\project\\dbclient.pgc" + cout << "Fragen:" << endl << endl; + + ECPGset_var( 0, &( offset ), __LINE__);\ + /* declare yyy cursor for select q . \"ID\" , q . question , q . answer0 , q . answer1 , q . answer2 , q . answer3 , c . name from gr2 . \"Questions\" q join gr2 . \"Categories\" c on q . category = c . \"ID\" order by c . \"ID\" limit 5 offset $1 */ +#line 254 "F:\\postgrachelor\\project\\dbclient.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare yyy cursor for select q . \"ID\" , q . question , q . answer0 , q . answer1 , q . answer2 , q . answer3 , c . name from gr2 . \"Questions\" q join gr2 . \"Categories\" c on q . category = c . \"ID\" order by c . \"ID\" limit 5 offset $1 ", + ECPGt_int,&(offset),(long)1,(long)1,sizeof(int), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} +#line 255 "F:\\postgrachelor\\project\\dbclient.pgc" - int residl; + int residl; residl = id; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch first from yyy", ECPGt_EOIT, + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch first from yyy", ECPGt_EOIT, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(question),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(question),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans0),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans0),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans1),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans1),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans2),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans2),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans3),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans3),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(cat),(long)51,(long)1,(51)*sizeof(char), + ECPGt_char,(cat),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 233 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 260 "F:\\postgrachelor\\project\\dbclient.pgc" if(!strcmp(sqlca.sqlstate, "00000")){ - hQuestion = question; - hAns0 = ans0; - hAns1 = ans1; - hAns2 = ans2; - hAns3 = ans3; - hCat = cat; - hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); - hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); - hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); - hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); - hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); - hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); - cout << "Schema:" << endl; - cout << "Frage: Kategorie" << endl << "\tRichtige Antwort" << endl << "\tFalsche Antwort 1" << endl << "\tFalsche Antwort 2" << endl << "\tFalsche Antwort 3" << endl << endl << endl; - cout << hQuestion << ": " << hCat << endl; - cout << "\t" << hAns0 << endl; - cout << "\t" << hAns1 << endl; - cout << "\t" << hAns2 << endl; - cout << "\t" << hAns3 << endl; - } + hQuestion = question; + hAns0 = ans0; + hAns1 = ans1; + hAns2 = ans2; + hAns3 = ans3; + hCat = cat; + hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); + hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); + hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); + hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); + hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); + hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); + cout << "Schema:" << endl; + cout << "Frage: Kategorie" << endl << " Richtige Antwort" << endl << " Falsche Antwort 1" << endl << " Falsche Antwort 2" << endl << " Falsche Antwort 3" << endl << endl << endl; + cout << hQuestion << ": " << hCat << endl; + cout << " " << hAns0 << endl; + cout << " " << hAns1 << endl; + cout << " " << hAns2 << endl; + cout << " " << hAns3 << endl; + } else if(!strcmp(sqlca.sqlstate, "02000")) cout << "Die Tabelle ist leer!"; while(id != residl) @@ -388,42 +428,42 @@ void selectQuestion(){ { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch next from yyy", ECPGt_EOIT, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(question),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(question),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans0),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans0),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans1),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans1),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans2),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans2),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(ans3),(long)181,(long)1,(181)*sizeof(char), + ECPGt_char,(ans3),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(cat),(long)51,(long)1,(51)*sizeof(char), + ECPGt_char,(cat),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 260 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 287 "F:\\postgrachelor\\project\\dbclient.pgc" if(!strcmp(sqlca.sqlstate, "00000")){ - hQuestion = question; - hAns0 = ans0; - hAns1 = ans1; - hAns2 = ans2; - hAns3 = ans3; - hCat = cat; - hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); - hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); - hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); - hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); - hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); - hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); - cout << hQuestion << ": " << hCat << endl; - cout << "\t" << hAns0 << endl; - cout << "\t" << hAns1 << endl; - cout << "\t" << hAns2 << endl; - cout << "\t" << hAns3 << endl; - } + hQuestion = question; + hAns0 = ans0; + hAns1 = ans1; + hAns2 = ans2; + hAns3 = ans3; + hCat = cat; + hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); + hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); + hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); + hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); + hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); + hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); + cout << hQuestion << ": " << hCat << endl; + cout << " " << hAns0 << endl; + cout << " " << hAns1 << endl; + cout << " " << hAns2 << endl; + cout << " " << hAns3 << endl; + } } { ECPGtrans(__LINE__, NULL, "commit");} -#line 281 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 308 "F:\\postgrachelor\\project\\dbclient.pgc" } @@ -432,30 +472,32 @@ void updateCategory(){ -#line 286 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 313 "F:\\postgrachelor\\project\\dbclient.pgc" int id ; -#line 287 "F:\\postgrachelor\\project\\dbclient.pgc" - char name [ 51 ] ; +#line 314 "F:\\postgrachelor\\project\\dbclient.pgc" + char name [ 4001 ] ; /* exec sql end declare section */ -#line 288 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 315 "F:\\postgrachelor\\project\\dbclient.pgc" cout << "Welche Kategorie soll bearbeitet werden? (ID eingeben):" << endl; selectCategory(); cin >> id; cout << "Welchen neuen Namen soll die Kategorie bekommen?" << endl; - cin >> name; + ws(cin); + cin.getline(name, sizeof(name)); if(id){ - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . test set name = $1 where \"ID\" = $2 ", - ECPGt_char,(name),(long)51,(long)1,(51)*sizeof(char), + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . \"Categories\" set name = $1 where \"ID\" = $2 ", + ECPGt_char,(name),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 295 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 323 "F:\\postgrachelor\\project\\dbclient.pgc" if(!strcmp(sqlca.sqlstate, "02000")) cout << "Kein derartiger Datensatz gefunden!"; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; { ECPGtrans(__LINE__, NULL, "commit");} -#line 297 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 326 "F:\\postgrachelor\\project\\dbclient.pgc" } } @@ -464,34 +506,34 @@ void updateQuestion(){ /* exec sql begin declare section */ - - - - - + + + + + -#line 303 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 332 "F:\\postgrachelor\\project\\dbclient.pgc" int id ; -#line 304 "F:\\postgrachelor\\project\\dbclient.pgc" - char question [ 181 ] ; +#line 333 "F:\\postgrachelor\\project\\dbclient.pgc" + char question [ 4001 ] ; -#line 305 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans0 [ 181 ] ; +#line 334 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans0 [ 4001 ] ; -#line 306 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans1 [ 181 ] ; +#line 335 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans1 [ 4001 ] ; -#line 307 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans2 [ 181 ] ; +#line 336 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans2 [ 4001 ] ; -#line 308 "F:\\postgrachelor\\project\\dbclient.pgc" - char ans3 [ 181 ] ; +#line 337 "F:\\postgrachelor\\project\\dbclient.pgc" + char ans3 [ 4001 ] ; -#line 309 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 338 "F:\\postgrachelor\\project\\dbclient.pgc" int cat ; /* exec sql end declare section */ -#line 310 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 339 "F:\\postgrachelor\\project\\dbclient.pgc" char choice = 0; cout << "Welche Frage soll bearbeitet werden? (ID eingeben):" << endl; @@ -502,74 +544,81 @@ void updateQuestion(){ switch(choice){ case 'f': cout << "Neue Fragenstellung: "; - cin >> question; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . testquestions set question = $1 where \"ID\" = $2 ", - ECPGt_char,(question),(long)181,(long)1,(181)*sizeof(char), + ws(cin); + cin.getline(question, sizeof(question)); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . \"Questions\" set question = $1 where \"ID\" = $2 ", + ECPGt_char,(question),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 321 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 351 "F:\\postgrachelor\\project\\dbclient.pgc" break; case '0': cout << "Neue richtige Antwort: "; - cin >> ans0; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . testquestions set answer0 = $1 where \"ID\" = $2 ", - ECPGt_char,(ans0),(long)181,(long)1,(181)*sizeof(char), + ws(cin); + cin.getline(ans0, sizeof(ans0)); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . \"Questions\" set answer0 = $1 where \"ID\" = $2 ", + ECPGt_char,(ans0),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 326 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 357 "F:\\postgrachelor\\project\\dbclient.pgc" break; case '1': cout << "Neue falsche Antwort: "; - cin >> ans1; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . testquestions set answer1 = $1 where \"ID\" = $2 ", - ECPGt_char,(ans1),(long)181,(long)1,(181)*sizeof(char), + ws(cin); + cin.getline(ans1, sizeof(ans1)); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . \"Questions\" set answer1 = $1 where \"ID\" = $2 ", + ECPGt_char,(ans1),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 331 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 363 "F:\\postgrachelor\\project\\dbclient.pgc" break; case '2': cout << "Neue falsche Antwort: "; - cin >> ans2; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . testquestions set answer2 = $1 where \"ID\" = $2 ", - ECPGt_char,(ans2),(long)181,(long)1,(181)*sizeof(char), + ws(cin); + cin.getline(ans2, sizeof(ans2)); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . \"Questions\" set answer2 = $1 where \"ID\" = $2 ", + ECPGt_char,(ans2),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 336 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 369 "F:\\postgrachelor\\project\\dbclient.pgc" break; case '3': cout << "Neue falsche Antwort: "; - cin >> ans3; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . testquestions set answer3 = $1 where \"ID\" = $2 ", - ECPGt_char,(ans3),(long)181,(long)1,(181)*sizeof(char), + ws(cin); + cin.getline(ans3, sizeof(ans3)); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . \"Questions\" set answer3 = $1 where \"ID\" = $2 ", + ECPGt_char,(ans3),(long)4001,(long)1,(4001)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 341 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 375 "F:\\postgrachelor\\project\\dbclient.pgc" break; case 'k': cout << "Neue Kategorie (ID):" << endl; selectCategory(); cin >> cat; - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . testquestions set category = $1 where \"ID\" = $2 ", + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update gr2 . \"Questions\" set category = $1 where \"ID\" = $2 ", ECPGt_int,&(cat),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 347 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 381 "F:\\postgrachelor\\project\\dbclient.pgc" break; } + if(!strcmp(sqlca.sqlstate, "02000")) cout << "Kein derartiger Datensatz gefunden!"; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; { ECPGtrans(__LINE__, NULL, "commit");} -#line 350 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 386 "F:\\postgrachelor\\project\\dbclient.pgc" } } @@ -578,24 +627,24 @@ void deleteCategory(){ /* exec sql begin declare section */ -#line 356 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 392 "F:\\postgrachelor\\project\\dbclient.pgc" int id ; /* exec sql end declare section */ -#line 357 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 393 "F:\\postgrachelor\\project\\dbclient.pgc" cout << "Welche Kategorie? (ID)" << endl; selectCategory(); cin >> id; if(id){ - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "delete from gr2 . test where \"ID\" = $1 ", + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "delete from gr2 . \"Categories\" where \"ID\" = $1 ", ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 362 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 398 "F:\\postgrachelor\\project\\dbclient.pgc" if(!strcmp(sqlca.sqlstate, "23503")) cout << "Kategorie kann nicht geloescht werden! (Existieren noch Fragen mit der Kategorie?)" << endl; else if(!strcmp(sqlca.sqlstate, "02000")) cout << "Kategorie existiert nicht!" << endl; { ECPGtrans(__LINE__, NULL, "commit");} -#line 365 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 401 "F:\\postgrachelor\\project\\dbclient.pgc" } } @@ -604,25 +653,25 @@ void deleteQuestion(){ /* exec sql begin declare section */ -#line 371 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 407 "F:\\postgrachelor\\project\\dbclient.pgc" int id ; /* exec sql end declare section */ -#line 372 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 408 "F:\\postgrachelor\\project\\dbclient.pgc" cout << "Welche Frage? (ID)" << endl; selectCategory(); cin >> id; if(id){ - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "delete from gr2 . testquestions where \"ID\" = $1 ", + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "delete from gr2 . \"Questions\" where \"ID\" = $1 ", ECPGt_int,&(id),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 377 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 413 "F:\\postgrachelor\\project\\dbclient.pgc" if(!strcmp(sqlca.sqlstate, "02000")) cout << "Frage existiert nicht!" << endl; { ECPGtrans(__LINE__, NULL, "commit");} -#line 379 "F:\\postgrachelor\\project\\dbclient.pgc" +#line 415 "F:\\postgrachelor\\project\\dbclient.pgc" - } + } } void cinClear() { diff --git a/project/dbclient.pgc b/project/dbclient.pgc index 7099021..08278ad 100644 --- a/project/dbclient.pgc +++ b/project/dbclient.pgc @@ -30,228 +30,255 @@ int main() char choice; int exit = 0; for(;!exit;){ - choice = 0; - cout << endl << endl << endl << "Was wollen Sie tun?:" << endl; - cout << "(e): Daten eingeben" << endl; - cout << "(a): Daten anzeigen" << endl; - cout << "(n): Daten aendern" << endl; - cout << "(l): Daten loeschen" << endl; - cout << "(s): schliessen" << endl; - cin >> choice; - switch(choice){ - case 'e': - menuInsert(); - break; - case 'a': - menuSelect(); - break; - case 'n': - menuUpdate(); - break; - case 'l': - menuDelete(); - break; - case 's': - exit = 1; - break; - } - } + choice = 0; + cout << endl << endl << endl << "Was wollen Sie tun?:" << endl; + cout << "(e): Daten eingeben" << endl; + cout << "(a): Daten anzeigen" << endl; + cout << "(n): Daten aendern" << endl; + cout << "(l): Daten loeschen" << endl; + cout << "(s): schliessen" << endl; + cin >> choice; + switch(choice){ + case 'e': + menuInsert(); + break; + case 'a': + menuSelect(); + break; + case 'n': + menuUpdate(); + break; + case 'l': + menuDelete(); + break; + case 's': + exit = 1; + break; + } + } } void initdb(){ - EXEC SQL CONNECT TO "CSDB@lamp.wlan.hwr-berlin.de" USER gr2 IDENTIFIED BY "2Au-R2n-cQN-uuG"; - cout << "state: " << sqlca.sqlstate << endl; + EXEC SQL CONNECT TO "CSDB@lamp.wlan.hwr-berlin.de" USER gr2 IDENTIFIED BY "2Au-R2n-cQN-uuG"; + cout << "state: " << sqlca.sqlstate << endl; EXEC SQL COMMIT; } void menuInsert(){ - char choice = 0; - cout << "Welche Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - insertCategory(); - break; - case 'f': - insertQuestion(); - break; - } + char choice = 0; + cout << "Welche Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + insertCategory(); + break; + case 'f': + insertQuestion(); + break; + } } void menuSelect(){ - char choice = 0; - cout << "Welche Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - selectCategory(); - break; - case 'f': - selectQuestion(); - break; - } + char choice = 0; + cout << "Welche Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + selectCategory(); + break; + case 'f': + selectQuestion(); + break; + } } void menuUpdate(){ - char choice = 0; - cout << "In welcher Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - updateCategory(); - break; - case 'f': - updateQuestion(); - break; - } + char choice = 0; + cout << "In welcher Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + updateCategory(); + break; + case 'f': + updateQuestion(); + break; + } } void menuDelete(){ - char choice = 0; - cout << "Aus welcher Tabelle?:" << endl; - cout << "(k): Kategorien" << endl; - cout << "(f): Fragen" << endl; - cin >> choice; - switch(choice){ - case 'k': - deleteCategory(); - break; - case 'f': - deleteQuestion(); - break; - } + char choice = 0; + cout << "Aus welcher Tabelle?:" << endl; + cout << "(k): Kategorien" << endl; + cout << "(f): Fragen" << endl; + cin >> choice; + switch(choice){ + case 'k': + deleteCategory(); + break; + case 'f': + deleteQuestion(); + break; + } } void insertCategory(){ - EXEC SQL BEGIN DECLARE SECTION; - char eingna[51]; + EXEC SQL BEGIN DECLARE SECTION; + char eingna[4001]; EXEC SQL END DECLARE SECTION; string h = ""; - cout << "Eingabe Name: "; - getline(cin, h); - getline(cin, h); + cout << "Eingabe Name: "; + ws(cin); + getline(cin, h); - //cout << h << endl; - if (!(h.empty()||!strcmp(h.c_str(),"\n"))) - { - strcpy(eingna, h.c_str()); - EXEC SQL INSERT INTO gr2.test(name) VALUES (:eingna); - if (!strcmp(sqlca.sqlstate, "23505")) cout << "GIBT'S SCHON" << endl; - cout << "state: " << sqlca.sqlstate << endl; - EXEC SQL COMMIT; - } + //cout << h << endl; + if (!(h.empty()||!strcmp(h.c_str(),"\n"))) + { + strcpy(eingna, h.c_str()); + EXEC SQL INSERT INTO gr2."Categories"(name) VALUES (:eingna); + if (!strcmp(sqlca.sqlstate, "23505")) cout << "GIBT'S SCHON" << endl; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; + EXEC SQL COMMIT; + } } void insertQuestion(){ - EXEC SQL BEGIN DECLARE SECTION; - char question[181]; - char ans0[181]; - char ans1[181]; - char ans2[181]; - char ans3[181]; - int category; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + char question[4001]; + char ans0[4001]; + char ans1[4001]; + char ans2[4001]; + char ans3[4001]; + int category; + EXEC SQL END DECLARE SECTION; - cout << "Frage: "; - cin >> question; - cout << "Richtige Antwort: "; - cin >> ans0; - cout << "1. Falsche Antwort: "; - cin >> ans1; - cout << "2. Falsche Antwort: "; - cin >> ans2; - cout << "3. Falsche Antwort: "; - cin >> ans3; - cout << "ID der Kategorie:" << endl << "moegliche "; - selectCategory(); - cin >> category; - if(category){ - EXEC SQL INSERT INTO gr2.testquestions(question,answer0,answer1,answer2,answer3,category) VALUES (:question,:ans0,:ans1,:ans2,:ans3,:category); - if(!strcmp(sqlca.sqlstate, "23503")) cout << "Das ist keine gueltige Kategorie!" << endl; - cout << "state: " << sqlca.sqlstate << endl; - EXEC SQL COMMIT; - } + cout << "Frage: "; + ws(cin); + cin.getline(question, sizeof(question)); + cout << "Richtige Antwort: "; + ws(cin); + cin.getline(ans0, sizeof(ans0)); + cout << "1. Falsche Antwort: "; + ws(cin); + cin.getline(ans1, sizeof(ans1)); + cout << "2. Falsche Antwort: "; + ws(cin); + cin.getline(ans2, sizeof(ans2)); + cout << "3. Falsche Antwort: "; + ws(cin); + cin.getline(ans3, sizeof(ans3)); + cout << "ID der Kategorie:" << endl << "moegliche "; + selectCategory(); + cin >> category; + if(category){ + EXEC SQL INSERT INTO gr2."Questions"(question,answer0,answer1,answer2,answer3,category) VALUES (:question,:ans0,:ans1,:ans2,:ans3,:category); + if(!strcmp(sqlca.sqlstate, "23503")) cout << "Das ist keine gueltige Kategorie!" << endl; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; + cout << "state: " << sqlca.sqlstate << endl; + EXEC SQL COMMIT; + } } void selectCategory(){ - //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! - EXEC SQL BEGIN DECLARE SECTION; - int id; - char name[51]; - EXEC SQL END DECLARE SECTION; + //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! + EXEC SQL BEGIN DECLARE SECTION; + int id; + char name[4001]; + EXEC SQL END DECLARE SECTION; - cout << "Kategorien:" << endl; + cout << "Kategorien:" << endl; - EXEC SQL DECLARE xxx CURSOR FOR SELECT "ID",name FROM gr2.test ORDER BY "ID"; + EXEC SQL DECLARE xxx CURSOR FOR SELECT "ID",name FROM gr2."Categories" ORDER BY "ID"; EXEC SQL OPEN xxx; - int residl; + int residl; residl = id; - EXEC SQL FETCH FIRST FROM xxx INTO :id, :name; - if(!strcmp(sqlca.sqlstate, "00000")) cout << id << " " << name << endl; + string hName = ""; + + EXEC SQL FETCH FIRST FROM xxx INTO :id, :name; + if(!strcmp(sqlca.sqlstate, "00000")){ + hName = name; + hName.erase(hName.find_last_not_of(" \n\r\t")+1); + cout << id << " " << hName << endl; + } else if(!strcmp(sqlca.sqlstate, "02000")) cout << "Die Tabelle ist leer!"; while(id != residl) { residl = id; EXEC SQL FETCH NEXT FROM xxx INTO :id, :name; - if(!strcmp(sqlca.sqlstate, "00000")) cout << id << " " << name << endl; + if(!strcmp(sqlca.sqlstate, "00000")){ + hName = name; + hName.erase(hName.find_last_not_of(" \n\r\t")+1); + cout << id << " " << hName << endl; + } } EXEC SQL COMMIT; } void selectQuestion(){ - //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! - EXEC SQL BEGIN DECLARE SECTION; - int id; - char question[181]; - char ans0[181]; - char ans1[181]; - char ans2[181]; - char ans3[181]; - char cat[51]; - EXEC SQL END DECLARE SECTION; + //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! + EXEC SQL BEGIN DECLARE SECTION; + int id; + char question[4001]; + char ans0[4001]; + char ans1[4001]; + char ans2[4001]; + char ans3[4001]; + char cat[4001]; + int sites; + int offset; + EXEC SQL END DECLARE SECTION; - string hQuestion = "", hAns0 = "", hAns1 = "", hAns2 = "", hAns3 = "", hCat = ""; + EXEC SQL SELECT ceil(count(*)/5.0) INTO :sites FROM gr2."Questions"; + cout << "Es gibt " << sites << " Seiten. Welche soll angezeigt werden?" << endl; + cin >> offset; + while(offset > sites || offset < 1){ + cout << "Diese Seite gibt es nicht. Bitte gueltige Seitenzahl eingeben!" << endl; + cin >> offset; + } + offset = (offset-1)*5; - cout << "Fragen:" << endl << endl; + string hQuestion = "", hAns0 = "", hAns1 = "", hAns2 = "", hAns3 = "", hCat = ""; - EXEC SQL DECLARE yyy CURSOR FOR SELECT q."ID",q.question,q.answer0,q.answer1,q.answer2,q.answer3,c.name FROM gr2.testquestions q JOIN gr2.test c ON q."ID" = c."ID" ORDER BY c."ID"; + cout << "Fragen:" << endl << endl; + + EXEC SQL DECLARE yyy CURSOR FOR SELECT q."ID",q.question,q.answer0,q.answer1,q.answer2,q.answer3,c.name FROM gr2."Questions" q JOIN gr2."Categories" c ON q.category = c."ID" ORDER BY c."ID" LIMIT 5 OFFSET :offset; EXEC SQL OPEN yyy; - int residl; + int residl; residl = id; - EXEC SQL FETCH FIRST FROM yyy INTO :id,:question, :ans0, :ans1, :ans2, :ans3, :cat; + EXEC SQL FETCH FIRST FROM yyy INTO :id,:question, :ans0, :ans1, :ans2, :ans3, :cat; if(!strcmp(sqlca.sqlstate, "00000")){ - hQuestion = question; - hAns0 = ans0; - hAns1 = ans1; - hAns2 = ans2; - hAns3 = ans3; - hCat = cat; - hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); - hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); - hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); - hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); - hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); - hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); - cout << "Schema:" << endl; - cout << "Frage: Kategorie" << endl << "\tRichtige Antwort" << endl << "\tFalsche Antwort 1" << endl << "\tFalsche Antwort 2" << endl << "\tFalsche Antwort 3" << endl << endl << endl; - cout << hQuestion << ": " << hCat << endl; - cout << "\t" << hAns0 << endl; - cout << "\t" << hAns1 << endl; - cout << "\t" << hAns2 << endl; - cout << "\t" << hAns3 << endl; - } + hQuestion = question; + hAns0 = ans0; + hAns1 = ans1; + hAns2 = ans2; + hAns3 = ans3; + hCat = cat; + hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); + hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); + hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); + hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); + hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); + hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); + cout << "Schema:" << endl; + cout << "Frage: Kategorie" << endl << " Richtige Antwort" << endl << " Falsche Antwort 1" << endl << " Falsche Antwort 2" << endl << " Falsche Antwort 3" << endl << endl << endl; + cout << hQuestion << ": " << hCat << endl; + cout << " " << hAns0 << endl; + cout << " " << hAns1 << endl; + cout << " " << hAns2 << endl; + cout << " " << hAns3 << endl; + } else if(!strcmp(sqlca.sqlstate, "02000")) cout << "Die Tabelle ist leer!"; while(id != residl) @@ -259,24 +286,24 @@ void selectQuestion(){ residl = id; EXEC SQL FETCH NEXT FROM yyy INTO :id,:question, :ans0, :ans1, :ans2, :ans3, :cat; if(!strcmp(sqlca.sqlstate, "00000")){ - hQuestion = question; - hAns0 = ans0; - hAns1 = ans1; - hAns2 = ans2; - hAns3 = ans3; - hCat = cat; - hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); - hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); - hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); - hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); - hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); - hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); - cout << hQuestion << ": " << hCat << endl; - cout << "\t" << hAns0 << endl; - cout << "\t" << hAns1 << endl; - cout << "\t" << hAns2 << endl; - cout << "\t" << hAns3 << endl; - } + hQuestion = question; + hAns0 = ans0; + hAns1 = ans1; + hAns2 = ans2; + hAns3 = ans3; + hCat = cat; + hQuestion.erase(hQuestion.find_last_not_of(" \n\r\t")+1); + hAns0.erase(hAns0.find_last_not_of(" \n\r\t")+1); + hAns1.erase(hAns1.find_last_not_of(" \n\r\t")+1); + hAns2.erase(hAns2.find_last_not_of(" \n\r\t")+1); + hAns3.erase(hAns3.find_last_not_of(" \n\r\t")+1); + hCat.erase(hCat.find_last_not_of(" \n\r\t")+1); + cout << hQuestion << ": " << hCat << endl; + cout << " " << hAns0 << endl; + cout << " " << hAns1 << endl; + cout << " " << hAns2 << endl; + cout << " " << hAns3 << endl; + } } EXEC SQL COMMIT; } @@ -284,16 +311,18 @@ void selectQuestion(){ void updateCategory(){ EXEC SQL BEGIN DECLARE SECTION; int id; - char name[51]; + char name[4001]; EXEC SQL END DECLARE SECTION; cout << "Welche Kategorie soll bearbeitet werden? (ID eingeben):" << endl; selectCategory(); cin >> id; cout << "Welchen neuen Namen soll die Kategorie bekommen?" << endl; - cin >> name; + ws(cin); + cin.getline(name, sizeof(name)); if(id){ - EXEC SQL UPDATE gr2.test SET name = :name WHERE "ID" = :id; + EXEC SQL UPDATE gr2."Categories" SET name = :name WHERE "ID" = :id; if(!strcmp(sqlca.sqlstate, "02000")) cout << "Kein derartiger Datensatz gefunden!"; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; EXEC SQL COMMIT; } } @@ -301,12 +330,12 @@ void updateCategory(){ void updateQuestion(){ EXEC SQL BEGIN DECLARE SECTION; int id; - char question[181]; - char ans0[181]; - char ans1[181]; - char ans2[181]; - char ans3[181]; - int cat; + char question[4001]; + char ans0[4001]; + char ans1[4001]; + char ans2[4001]; + char ans3[4001]; + int cat; EXEC SQL END DECLARE SECTION; char choice = 0; cout << "Welche Frage soll bearbeitet werden? (ID eingeben):" << endl; @@ -317,36 +346,43 @@ void updateQuestion(){ switch(choice){ case 'f': cout << "Neue Fragenstellung: "; - cin >> question; - EXEC SQL UPDATE gr2.testquestions SET question = :question WHERE "ID" = :id; + ws(cin); + cin.getline(question, sizeof(question)); + EXEC SQL UPDATE gr2."Questions" SET question = :question WHERE "ID" = :id; break; case '0': cout << "Neue richtige Antwort: "; - cin >> ans0; - EXEC SQL UPDATE gr2.testquestions SET answer0 = :ans0 WHERE "ID" = :id; + ws(cin); + cin.getline(ans0, sizeof(ans0)); + EXEC SQL UPDATE gr2."Questions" SET answer0 = :ans0 WHERE "ID" = :id; break; case '1': cout << "Neue falsche Antwort: "; - cin >> ans1; - EXEC SQL UPDATE gr2.testquestions SET answer1 = :ans1 WHERE "ID" = :id; + ws(cin); + cin.getline(ans1, sizeof(ans1)); + EXEC SQL UPDATE gr2."Questions" SET answer1 = :ans1 WHERE "ID" = :id; break; case '2': cout << "Neue falsche Antwort: "; - cin >> ans2; - EXEC SQL UPDATE gr2.testquestions SET answer2 = :ans2 WHERE "ID" = :id; + ws(cin); + cin.getline(ans2, sizeof(ans2)); + EXEC SQL UPDATE gr2."Questions" SET answer2 = :ans2 WHERE "ID" = :id; break; case '3': cout << "Neue falsche Antwort: "; - cin >> ans3; - EXEC SQL UPDATE gr2.testquestions SET answer3 = :ans3 WHERE "ID" = :id; + ws(cin); + cin.getline(ans3, sizeof(ans3)); + EXEC SQL UPDATE gr2."Questions" SET answer3 = :ans3 WHERE "ID" = :id; break; case 'k': cout << "Neue Kategorie (ID):" << endl; selectCategory(); cin >> cat; - EXEC SQL UPDATE gr2.testquestions SET category = :cat WHERE "ID" = :id; + EXEC SQL UPDATE gr2."Questions" SET category = :cat WHERE "ID" = :id; break; } + if(!strcmp(sqlca.sqlstate, "02000")) cout << "Kein derartiger Datensatz gefunden!"; + else if(!strcmp(sqlca.sqlstate, "22021")) cout << "Umlaute bitte umschreiben (z.B. als \"ue\")!"; EXEC SQL COMMIT; } } @@ -359,7 +395,7 @@ void deleteCategory(){ selectCategory(); cin >> id; if(id){ - EXEC SQL DELETE FROM gr2.test WHERE "ID" = :id; + EXEC SQL DELETE FROM gr2."Categories" WHERE "ID" = :id; if(!strcmp(sqlca.sqlstate, "23503")) cout << "Kategorie kann nicht geloescht werden! (Existieren noch Fragen mit der Kategorie?)" << endl; else if(!strcmp(sqlca.sqlstate, "02000")) cout << "Kategorie existiert nicht!" << endl; EXEC SQL COMMIT; @@ -374,10 +410,10 @@ void deleteQuestion(){ selectCategory(); cin >> id; if(id){ - EXEC SQL DELETE FROM gr2.testquestions WHERE "ID" = :id; + EXEC SQL DELETE FROM gr2."Questions" WHERE "ID" = :id; if(!strcmp(sqlca.sqlstate, "02000")) cout << "Frage existiert nicht!" << endl; EXEC SQL COMMIT; - } + } } void cinClear() { diff --git a/project/obj/Debug/dbclient.o b/project/obj/Debug/dbclient.o index 9d93772..235c6f0 100644 Binary files a/project/obj/Debug/dbclient.o and b/project/obj/Debug/dbclient.o differ diff --git a/project/obj/Release/dbclient.o b/project/obj/Release/dbclient.o index 75f4e0f..4eeaa59 100644 Binary files a/project/obj/Release/dbclient.o and b/project/obj/Release/dbclient.o differ diff --git a/project/project.depend b/project/project.depend index c4ac310..5135845 100644 --- a/project/project.depend +++ b/project/project.depend @@ -1 +1,6 @@ # depslib dependency file v1.0 +1489999930 source:f:\postgrachelor\project\dbclient.pgc + + + + diff --git a/project/project.layout b/project/project.layout index 100c1f2..927bc93 100644 --- a/project/project.layout +++ b/project/project.layout @@ -1,15 +1,15 @@ - + - + - +