diff --git a/project/bin/Debug/project.exe b/project/bin/Debug/project.exe new file mode 100644 index 0000000..bce9039 Binary files /dev/null and b/project/bin/Debug/project.exe differ diff --git a/project/dbclient.cpp b/project/dbclient.cpp new file mode 100644 index 0000000..62fd719 --- /dev/null +++ b/project/dbclient.cpp @@ -0,0 +1,151 @@ +/* Processed by ecpg (4.12.0) */ +/* These include files are added by the preprocessor */ +#include +#include +#include +/* End of automatic include section */ + +#line 1 "F:\\postgrachelor\\project\\dbclient.pgc" +#include +#include + +using namespace std; + +void initdb(); +void insertCategory(); +void menuInsert(); +void select(); +void cinClear(); + +int main() +{ + initdb(); + + 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 << "" << endl; + cout << "(s): schliessen" << endl; + cin >> choice; + switch(choice){ + case 'e': + insertCategory(); + break; + case 'a': + select(); + break; + case 's': + exit = 1; + break; + } + } +} + +void initdb(){ + { ECPGconnect(__LINE__, 0, "CSDB@lamp.wlan.hwr-berlin.de" , "gr2" , "2Au-R2n-cQN-uuG" , NULL, 0); } +#line 41 "F:\\postgrachelor\\project\\dbclient.pgc" + + cout << "state: " << sqlca.sqlstate << endl; + { ECPGtrans(__LINE__, NULL, "commit");} +#line 43 "F:\\postgrachelor\\project\\dbclient.pgc" + +} + +void menuInsert(){ + insertCategory(); +} + +void insertCategory(){ + /* exec sql begin declare section */ + + +#line 52 "F:\\postgrachelor\\project\\dbclient.pgc" + char eingna [ 51 ] ; +/* exec sql end declare section */ +#line 53 "F:\\postgrachelor\\project\\dbclient.pgc" + + + cout << "Eingabe Name: "; + cin >> eingna; + if (!cin) cinClear(); + + if (eingna) + { + { 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), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} +#line 61 "F:\\postgrachelor\\project\\dbclient.pgc" + + if (!strcmp(sqlca.sqlstate, "23505")) cout << "GIBT'S SCHON" << endl; + cout << "state: " << sqlca.sqlstate << endl; + { ECPGtrans(__LINE__, NULL, "commit");} +#line 64 "F:\\postgrachelor\\project\\dbclient.pgc" + + } +} + +void select(){ + //Die Ausgabe funktioniert nur dann korrekt, wenn die ids eindeutig sind!!! + /* exec sql begin declare section */ + + + +#line 71 "F:\\postgrachelor\\project\\dbclient.pgc" + int id ; + +#line 72 "F:\\postgrachelor\\project\\dbclient.pgc" + char name [ 51 ] ; +/* exec sql end declare section */ +#line 73 "F:\\postgrachelor\\project\\dbclient.pgc" + + + cout << endl << "Ausgabe Tabelle: " << endl; + + /* declare xxx cursor for select \"ID\" , name from gr2 . test order by \"ID\" */ +#line 77 "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 78 "F:\\postgrachelor\\project\\dbclient.pgc" + + + int residl; + residl = id; + + { 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);} +#line 83 "F:\\postgrachelor\\project\\dbclient.pgc" + + if(!strcmp(sqlca.sqlstate, "00000")) cout << id << " " << name << endl; + else if(!strcmp(sqlca.sqlstate, "02000")) cout << "Die Tabelle ist leer!"; + + while(id != residl) + { + residl = id; + { 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_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 90 "F:\\postgrachelor\\project\\dbclient.pgc" + + if(!strcmp(sqlca.sqlstate, "00000")) cout << id << " " << name << endl; + } + { ECPGtrans(__LINE__, NULL, "commit");} +#line 93 "F:\\postgrachelor\\project\\dbclient.pgc" + +} + +void cinClear() { + char Muell; + cin.clear(); + do { + cin.get(Muell); + } while (Muell != '\n'); +} diff --git a/project/dbclient.pgc b/project/dbclient.pgc new file mode 100644 index 0000000..31e9064 --- /dev/null +++ b/project/dbclient.pgc @@ -0,0 +1,102 @@ +#include +#include + +using namespace std; + +void initdb(); +void insertCategory(); +void menuInsert(); +void select(); +void cinClear(); + +int main() +{ + initdb(); + + 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 << "" << endl; + cout << "(s): schliessen" << endl; + cin >> choice; + switch(choice){ + case 'e': + insertCategory(); + break; + case 'a': + select(); + 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 COMMIT; +} + +void menuInsert(){ + insertCategory(); +} + +void insertCategory(){ + EXEC SQL BEGIN DECLARE SECTION; + char eingna[51]; + EXEC SQL END DECLARE SECTION; + + cout << "Eingabe Name: "; + cin >> eingna; + if (!cin) cinClear(); + + if (eingna) + { + 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; + } +} + +void select(){ + //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; + + cout << endl << "Ausgabe Tabelle: " << endl; + + EXEC SQL DECLARE xxx CURSOR FOR SELECT "ID",name FROM gr2.test ORDER BY "ID"; + EXEC SQL OPEN xxx; + + int residl; + residl = id; + + EXEC SQL FETCH FIRST FROM xxx INTO :id, :name; + if(!strcmp(sqlca.sqlstate, "00000")) cout << id << " " << name << 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; + } + EXEC SQL COMMIT; +} + +void cinClear() { + char Muell; + cin.clear(); + do { + cin.get(Muell); + } while (Muell != '\n'); +} diff --git a/project/obj/Debug/dbclient.o b/project/obj/Debug/dbclient.o new file mode 100644 index 0000000..a65eb7c Binary files /dev/null and b/project/obj/Debug/dbclient.o differ diff --git a/project/obj/Release/dbclient.o b/project/obj/Release/dbclient.o new file mode 100644 index 0000000..8f72e9b Binary files /dev/null and b/project/obj/Release/dbclient.o differ diff --git a/project/project.cbp b/project/project.cbp new file mode 100644 index 0000000..e200f02 --- /dev/null +++ b/project/project.cbp @@ -0,0 +1,50 @@ + + + + + + diff --git a/project/project.depend b/project/project.depend new file mode 100644 index 0000000..917aae7 --- /dev/null +++ b/project/project.depend @@ -0,0 +1,13 @@ +# depslib dependency file v1.0 +1489738282 source:c:\users\s_seedorf\desktop\cpp\project\dbclient.pgc + + + +1489771116 source:f:\postgrachelor\project\dbclient.pgc + + + +1489768344 source:f:\postgrachelor\postgrachelorcppapplication\project\dbclient.pgc + + + diff --git a/project/project.layout b/project/project.layout new file mode 100644 index 0000000..5e835ab --- /dev/null +++ b/project/project.layout @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +