summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/test')
-rw-r--r--src/interfaces/ecpg/test/Makefile18
-rw-r--r--src/interfaces/ecpg/test/Ptest1.c77
-rw-r--r--src/interfaces/ecpg/test/header_test.h2
-rw-r--r--src/interfaces/ecpg/test/mm.sql0
-rw-r--r--src/interfaces/ecpg/test/perftest.pgc2
-rw-r--r--src/interfaces/ecpg/test/test1.c72
-rw-r--r--src/interfaces/ecpg/test/test1.pgc63
-rw-r--r--src/interfaces/ecpg/test/test2.pgc20
8 files changed, 83 insertions, 171 deletions
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile
index 50768a6541b..8a7f1f69df4 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -1,14 +1,18 @@
-all: test2 perftest
+all: test1 test2 perftest
+
+LDFLAGS=-g -I ../include -I ../../libpq -L../lib -lecpg -L../../libpq -lpq -lcrypt --static
+
+test1: test1.c
+test1.c: test1.pgc
+ ../preproc/ecpg $?
test2: test2.c
- gcc -g -I ../include -I ../../libpq -o test2 test2.c -L../lib -lecpg -L../../libpq -lpq -lcrypt --static
test2.c: test2.pgc
- ../preproc/ecpg test2.pgc
+ ../preproc/ecpg $?
perftest: perftest.c
- gcc -g -I ../include -I ../../libpq -o perftest perftest.c -L../lib -lecpg -L../../libpq -lpq -lcrypt --static
-perftest.c: perftest.pgc
- ../preproc/ecpg perftest.pgc
+perftest.c:perftest.pgc
+ ../preproc/ecpg $?
clean:
- /bin/rm test2 test2.c perftest perftest.c log
+ /bin/rm test1 test2 perftest *.c log
diff --git a/src/interfaces/ecpg/test/Ptest1.c b/src/interfaces/ecpg/test/Ptest1.c
deleted file mode 100644
index 5418e2c1a40..00000000000
--- a/src/interfaces/ecpg/test/Ptest1.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/* These two include files are added by the preprocessor */
-#include <ecpgtype.h>
-#include <ecpglib.h>
-/* exec sql begin declare section */
-
- /* VARSIZE */ struct varchar_uid
-{
- int len;
- char arr[200];
-} uid;
-struct varchar_name
-{
- int len;
- char arr[200];
-} name;
-short value;
-
-/* exec sql end declare section */
-
-
-#include "sqlca.h"
-
-#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr)
-#define LENFIX(x) x.len=strlen(x.arr)
-#define STRFIX(x) x.arr[x.len]='\0'
-#define SQLCODE sqlca.sqlcode
-
-void
-db_error(char *msg)
-{
- sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
- printf("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc);
- exit(1);
-}
-
-int
-main()
-{
- strcpy(uid.arr, "test/test");
- LENFIX(uid);
-
- ECPGconnect("kom");
- if (SQLCODE)
- db_error("connect");
-
- strcpy(name.arr, "opt1");
- LENFIX(name);
-
- ECPGdo(__LINE__, "declare cur cursor for select name , value from pace_test ", ECPGt_EOIT, ECPGt_EORT);
- if (SQLCODE)
- db_error("declare");
-
-
- if (SQLCODE)
- db_error("open");
-
- while (1)
- {
- ECPGdo(__LINE__, "fetch in cur ", ECPGt_EOIT, ECPGt_varchar, &name, 200, 0, sizeof(struct varchar_name), ECPGt_short, &value, 0, 0, sizeof(short), ECPGt_EORT);
- if (SQLCODE)
- break;
- STRFIX(name);
- printf("%s\t%d\n", name.arr, value);
- }
-
- if (SQLCODE < 0)
- db_error("fetch");
-
- ECPGdo(__LINE__, "close cur ", ECPGt_EOIT, ECPGt_EORT);
- if (SQLCODE)
- db_error("close");
- ECPGcommit(__LINE__);
- if (SQLCODE)
- db_error("commit");
-
- return (0);
-}
diff --git a/src/interfaces/ecpg/test/header_test.h b/src/interfaces/ecpg/test/header_test.h
index 2494a61dd74..cc84aed778f 100644
--- a/src/interfaces/ecpg/test/header_test.h
+++ b/src/interfaces/ecpg/test/header_test.h
@@ -1,4 +1,4 @@
exec sql include sqlca;
-exec sql whenever not found do set_not_found();
+exec sql whenever not found do break;
exec sql whenever sqlerror sqlprint;
diff --git a/src/interfaces/ecpg/test/mm.sql b/src/interfaces/ecpg/test/mm.sql
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/src/interfaces/ecpg/test/mm.sql
+++ /dev/null
diff --git a/src/interfaces/ecpg/test/perftest.pgc b/src/interfaces/ecpg/test/perftest.pgc
index 8183bf99368..f56d814dd98 100644
--- a/src/interfaces/ecpg/test/perftest.pgc
+++ b/src/interfaces/ecpg/test/perftest.pgc
@@ -121,5 +121,7 @@ exec sql end declare section;
exec sql commit;
+ exec sql disconnect;
+
return (0);
}
diff --git a/src/interfaces/ecpg/test/test1.c b/src/interfaces/ecpg/test/test1.c
deleted file mode 100644
index f2533d544d9..00000000000
--- a/src/interfaces/ecpg/test/test1.c
+++ /dev/null
@@ -1,72 +0,0 @@
-exec sql begin declare section;
-VARCHAR uid[200 /* VARSIZE */ ];
-varchar name[200];
-short value;
-exec sql end declare section;
-
-exec sql include sqlca;
-
-#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr)
-#define LENFIX(x) x.len=strlen(x.arr)
-#define STRFIX(x) x.arr[x.len]='\0'
-#define SQLCODE sqlca.sqlcode
-
-void
-db_error(char *msg)
-{
- sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
- printf("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc);
- exit(1);
-}
-
-int
-main()
-{
- strcpy(uid.arr, "test/test");
- LENFIX(uid);
-
- exec sql connect 'kom';
-
- if (SQLCODE)
- db_error("connect");
-
- strcpy(name.arr, "opt1");
- LENFIX(name);
-
- exec sql declare cur cursor for
- select name,
- value from pace_test;
-
- if (SQLCODE)
- db_error("declare");
-
- exec sql open cur;
-
- if (SQLCODE)
- db_error("open");
-
- while (1)
- {
- exec sql fetch in cur into:name,
- : value;
-
- if (SQLCODE)
- break;
- STRFIX(name);
- printf("%s\t%d\n", name.arr, value);
- }
-
- if (SQLCODE < 0)
- db_error("fetch");
-
- exec sql close cur;
-
- if (SQLCODE)
- db_error("close");
- exec sql commit;
-
- if (SQLCODE)
- db_error("commit");
-
- return (0);
-}
diff --git a/src/interfaces/ecpg/test/test1.pgc b/src/interfaces/ecpg/test/test1.pgc
new file mode 100644
index 00000000000..3363af07b1f
--- /dev/null
+++ b/src/interfaces/ecpg/test/test1.pgc
@@ -0,0 +1,63 @@
+#include <stdio.h>
+
+exec sql whenever sqlerror sqlprint;
+
+exec sql include sqlca;
+
+int
+main ()
+{
+exec sql begin declare section;
+ int amount[5];
+ char name[5][8];
+exec sql end declare section;
+ char msg[128], command[128];
+ FILE *dbgs;
+ int i,j;
+
+ if ((dbgs = fopen("log", "w")) != NULL)
+ ECPGdebug(1, dbgs);
+
+ strcpy(msg, "connect");
+ exec sql connect mm;
+
+ strcpy(msg, "create");
+ exec sql create table test(name char(8), amount int);
+
+ strcpy(msg, "execute insert 1");
+ sprintf(command, "insert into test(name, amount) values ('foobar', 1)");
+ exec sql execute immediate :command;
+
+ strcpy(msg, "excute insert 2");
+ sprintf(command, "insert into test(name, amount) select name, amount+1 from test");
+ exec sql execute immediate :command;
+
+ strcpy(msg, "excute insert 3");
+ sprintf(command, "insert into test(name, amount) select name, amount+10 from test");
+ exec sql execute immediate :command;
+
+ printf("Inserted %d tuples via execute immediate\n", sqlca.sqlerrd[2]);
+
+ strcpy(msg, "commit");
+ exec sql commit;
+
+ strcpy(msg, "select");
+ exec sql select name, amount into :name, :amount from test;
+
+ for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
+ printf("name[%d]=%8.8s, amount[%d]=%d\n", i, name[i], i, amount[i]);
+
+ strcpy(msg, "drop");
+ exec sql drop table test;
+
+ strcpy(msg, "commit");
+ exec sql commit;
+
+ strcpy(msg, "disconnect");
+ exec sql disconnect;
+
+ if (dbgs != NULL)
+ fclose(dbgs);
+
+ return (0);
+}
diff --git a/src/interfaces/ecpg/test/test2.pgc b/src/interfaces/ecpg/test/test2.pgc
index 87834aaa6b7..ed0599cdeaf 100644
--- a/src/interfaces/ecpg/test/test2.pgc
+++ b/src/interfaces/ecpg/test/test2.pgc
@@ -2,13 +2,6 @@
exec sql include header_test;
-static int not_found = 0;
-static void
-set_not_found(void)
-{
- not_found = 1;
-}
-
int
main ()
{
@@ -43,10 +36,7 @@ exec sql end declare section;
exec sql insert into meskes(name, born, age, married) values ('Michael', 19660117, 32, '19900404');
exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 7);
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 4);
-
- sprintf(command, "insert into meskes(name, born, age) values ('Chris', 19970923, 0)");
- strcpy(msg, "execute");
- exec sql execute immediate :command;
+ exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 0);
strcpy(msg, "commit");
exec sql commit;
@@ -58,11 +48,10 @@ exec sql end declare section;
strcpy(msg, "open");
exec sql open cur;
- while (not_found == 0) {
+ while (1) {
strcpy(msg, "fetch");
exec sql fetch cur into :personal:ind_personal, :married:ind_married;
- if (not_found == 0)
- printf ("%8.8s was born %d (age = %d) %s%s\n", personal.name.arr, personal.birth.born, personal.birth.age, ind_married ? "" : "and married ", ind_married ? "" : married);
+ printf ("%8.8s was born %d (age = %d) %s%s\n", personal.name.arr, personal.birth.born, personal.birth.age, ind_married ? "" : "and married ", ind_married ? "" : married);
}
strcpy(msg, "close");
@@ -74,6 +63,9 @@ exec sql end declare section;
strcpy(msg, "commit");
exec sql commit;
+ strcpy(msg, "disconnect");
+
+ exec sql disconnect;
if (dbgs != NULL)
fclose(dbgs);