added CodeBlocks Project
current state: menu, insert category, show categories
This commit is contained in:
151
project/dbclient.cpp
Normal file
151
project/dbclient.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
/* Processed by ecpg (4.12.0) */
|
||||
/* These include files are added by the preprocessor */
|
||||
#include <ecpglib.h>
|
||||
#include <ecpgerrno.h>
|
||||
#include <sqlca.h>
|
||||
/* End of automatic include section */
|
||||
|
||||
#line 1 "F:\\postgrachelor\\project\\dbclient.pgc"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
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');
|
||||
}
|
||||
Reference in New Issue
Block a user