added CodeBlocks Project

current state: menu, insert category, show categories
This commit is contained in:
Benjamin Petsch
2017-03-18 00:27:05 +01:00
parent 50a5ee31c5
commit 2ba7cb25ee
8 changed files with 331 additions and 0 deletions

Binary file not shown.

151
project/dbclient.cpp Normal file
View 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');
}

102
project/dbclient.pgc Normal file
View File

@@ -0,0 +1,102 @@
#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(){
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');
}

Binary file not shown.

Binary file not shown.

50
project/project.cbp Normal file
View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="project" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/project" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/project" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add directory="../postgresql-9.6.2-3-windows-binaries/pgsql/include" />
</Compiler>
<Linker>
<Add option="-lecpg" />
<Add directory="../postgresql-9.6.2-3-windows-binaries/pgsql/bin" />
<Add directory="../postgresql-9.6.2-3-windows-binaries/pgsql/lib" />
</Linker>
<Unit filename="dbclient.pgc">
<Option compile="1" />
</Unit>
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

13
project/project.depend Normal file
View File

@@ -0,0 +1,13 @@
# depslib dependency file v1.0
1489738282 source:c:\users\s_seedorf\desktop\cpp\project\dbclient.pgc
<iostream>
<stdlib.h>
1489771116 source:f:\postgrachelor\project\dbclient.pgc
<iostream>
<stdlib.h>
1489768344 source:f:\postgrachelor\postgrachelorcppapplication\project\dbclient.pgc
<iostream>
<stdlib.h>

15
project/project.layout Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="dbclient.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3617" topLine="112" />
</Cursor>
</File>
<File name="dbclient.pgc" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1253" topLine="46" />
</Cursor>
</File>
</CodeBlocks_layout_file>