Commit f419de8a authored by Peter Eisentraut's avatar Peter Eisentraut

Clean up some warnings and bugs and make things build easier.

parent dfb8e3f1
all: test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init # $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.31 2001/08/11 10:52:09 petere Exp $
#LDFLAGS=-g -I /usr/local/pgsql/include -L/usr/local/pgsql/lib -lecpg -lpq subdir = src/interfaces/ecpg/test
LDFLAGS=-g -I ../include top_builddir = ../../../..
LDLIBS=-L ../lib -lecpg -L ../../libpq -lpq include $(top_builddir)/src/Makefile.global
#ECPG=/usr/local/pgsql/bin/ecpg -I../include override CPPFLAGS := -I$(srcdir)/../include $(CPPFLAGS)
ECPG=../preproc/ecpg -I../include
.SUFFIXES: .pgc .c ECPG = ../preproc/ecpg -I$(srcdir)/../include
test1: test1.c TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init
test2: test2.c
test3: test3.c
test4: test4.c
perftest: perftest.c
dyntest: dyntest.c
dyntest2: dyntest2.c
test_code100: test_code100.c
test_notice: test_notice.c
test_init: test_init.c
test_text: test_text.c
.pgc.c: all: $(TESTS)
$(ECPG) $?
%: %.o
$(CC) $(CFLAGS) $(LDFLAGS) -L../lib -L../../libpq $^ $(LIBS) -lecpg -lpq -o $@
%.c: %.pgc
$(ECPG) $<
clean: clean:
rm -f test1 test2 test3 test4 perftest *.c log dyntest dyntest2 test_notice test_code100 test_init test_text *.exe rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log
...@@ -2,16 +2,18 @@ ...@@ -2,16 +2,18 @@
* *
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de> * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
* *
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest.pgc,v 1.7 2000/10/16 19:53:04 meskes Exp $ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest.pgc,v 1.8 2001/08/11 10:52:09 petere Exp $
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
exec sql include sql3types; exec sql include sql3types;
exec sql include sqlca; exec sql include sqlca;
void error() static void error()
{ printf("#%d:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc); { printf("#%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
exit(1); exit(1);
} }
...@@ -64,7 +66,8 @@ int main(int argc,char **argv) ...@@ -64,7 +66,8 @@ int main(int argc,char **argv)
:TYPE = type, :TYPE = type,
:LENGTH = length, :OCTET_LENGTH=octet_length, :LENGTH = length, :OCTET_LENGTH=octet_length,
:PRECISION = precision, :SCALE=scale, :PRECISION = precision, :SCALE=scale,
:NULLABLE=nullable, :NAME=name; :NULLABLE=nullable, :NAME=name,
:RETURNED_OCTET_LENGTH=returned_octet_length;
printf("%s ",NAME); printf("%s ",NAME);
switch (TYPE) switch (TYPE)
{ case SQL3_BOOLEAN: { case SQL3_BOOLEAN:
......
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
* *
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de> * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
* *
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest2.pgc,v 1.1 2000/03/03 13:24:06 meskes Exp $ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest2.pgc,v 1.2 2001/08/11 10:52:09 petere Exp $
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
exec sql include sql3types; exec sql include sql3types;
exec sql include sqlca; exec sql include sqlca;
void error() static void error()
{ {
printf("\n#%d:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc); printf("\n#%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
exit(1); exit(1);
} }
......
exec sql include sqlca; exec sql include sqlca;
void #include "stdlib.h"
Finish(msg)
static void
Finish(char *msg)
{ {
fprintf(stderr, "Error in statement '%s':\n", msg); fprintf(stderr, "Error in statement '%s':\n", msg);
sqlprint(); sqlprint();
...@@ -18,7 +20,7 @@ Finish(msg) ...@@ -18,7 +20,7 @@ Finish(msg)
exit(-1); exit(-1);
} }
void static void
warn(void) warn(void)
{ {
fprintf(stderr, "Warning: At least one column was truncated\n"); fprintf(stderr, "Warning: At least one column was truncated\n");
......
#include <stdlib.h>
#include <string.h>
exec sql include sqlca; exec sql include sqlca;
exec sql whenever sqlerror do PrintAndStop(msg); exec sql whenever sqlerror do PrintAndStop(msg);
exec sql whenever sqlwarning do warn(); exec sql whenever sqlwarning do warn();
void PrintAndStop(msg) static void PrintAndStop(char *msg)
{ {
fprintf(stderr, "Error in statement '%s':\n", msg); fprintf(stderr, "Error in statement '%s':\n", msg);
sqlprint(); sqlprint();
exit(-1); exit(-1);
} }
void warn(void) static void warn(void)
{ {
fprintf(stderr, "Warning: At least one column was truncated\n"); fprintf(stderr, "Warning: At least one column was truncated\n");
} }
...@@ -61,7 +64,7 @@ exec sql end declare section; ...@@ -61,7 +64,7 @@ exec sql end declare section;
strcpy(msg, "execute insert 1"); strcpy(msg, "execute insert 1");
sprintf(command, "insert into \"Test\" (name, amount, letter) values ('db: ''mm''', 1, 'f')"); sprintf(command, "insert into \"Test\" (name, amount, letter) values ('db: ''mm''', 1, 'f')");
exec sql execute immediate :command; exec sql execute immediate :command;
printf("New tuple got OID = %d\n", sqlca.sqlerrd[1]); printf("New tuple got OID = %ld\n", sqlca.sqlerrd[1]);
sprintf(command, "insert into \"Test\" (name, amount, letter) values ('db: \\\'mm\\\'', 2, 't')"); sprintf(command, "insert into \"Test\" (name, amount, letter) values ('db: \\\'mm\\\'', 2, 't')");
exec sql execute immediate :command; exec sql execute immediate :command;
...@@ -74,14 +77,14 @@ exec sql end declare section; ...@@ -74,14 +77,14 @@ exec sql end declare section;
sprintf(command, "insert into \"Test\" (name, amount, letter) select name, amount+10, letter from \"Test\""); sprintf(command, "insert into \"Test\" (name, amount, letter) select name, amount+10, letter from \"Test\"");
exec sql execute immediate :command; exec sql execute immediate :command;
printf("Inserted %d tuples via execute immediate\n", sqlca.sqlerrd[2]); printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
strcpy(msg, "execute insert 4"); strcpy(msg, "execute insert 4");
sprintf(command, "insert into \"Test\" (name, amount, letter) select name, amount+?, letter from \"Test\""); sprintf(command, "insert into \"Test\" (name, amount, letter) select name, amount+?, letter from \"Test\"");
exec sql prepare I from :command; exec sql prepare I from :command;
exec sql at pm execute I using :increment; exec sql at pm execute I using :increment;
printf("Inserted %d tuples via prepared execute\n", sqlca.sqlerrd[2]); printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
strcpy(msg, "commit"); strcpy(msg, "commit");
exec sql commit; exec sql commit;
......
#include <stdlib.h>
#include <string.h>
exec sql include header_test; exec sql include header_test;
...@@ -35,14 +36,14 @@ exec sql end declare section; ...@@ -35,14 +36,14 @@ exec sql end declare section;
exec sql declare cur cursor for exec sql declare cur cursor for
select name, born, age, married, children from meskes; select name, born, age, married, children from meskes;
char msg[128], command[128]; char msg[128];
FILE *dbgs; FILE *dbgs;
if ((dbgs = fopen("log", "w")) != NULL) if ((dbgs = fopen("log", "w")) != NULL)
ECPGdebug(1, dbgs); ECPGdebug(1, dbgs);
strcpy(msg, "connect"); strcpy(msg, "connect");
exec sql connect to unix:postgresql://127.0.0.1:5432/mm; exec sql connect to tcp:postgresql://127.0.0.1:5432/mm;
strcpy(msg, "create"); strcpy(msg, "create");
exec sql create table meskes(name char(8), born integer, age smallint, married date, children integer); exec sql create table meskes(name char(8), born integer, age smallint, married date, children integer);
...@@ -67,7 +68,7 @@ exec sql end declare section; ...@@ -67,7 +68,7 @@ exec sql end declare section;
exec sql fetch cur into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint; exec sql fetch cur into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint;
printf("%8.8s", personal.name.arr); printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0) if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born); printf(", born %ld", personal.birth.born);
if (ind_personal.ind_birth.age >= 0) if (ind_personal.ind_birth.age >= 0)
printf(", age = %d", personal.birth.age); printf(", age = %d", personal.birth.age);
if ((long)ind_married >= 0) if ((long)ind_married >= 0)
...@@ -97,7 +98,7 @@ exec sql end declare section; ...@@ -97,7 +98,7 @@ exec sql end declare section;
exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint; exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint;
printf("%8.8s", personal.name.arr); printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0) if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born); printf(", born %ld", personal.birth.born);
if (ind_personal.ind_birth.age >= 0) if (ind_personal.ind_birth.age >= 0)
printf(", age = %d", personal.birth.age); printf(", age = %d", personal.birth.age);
if ((long)ind_married >= 0) if ((long)ind_married >= 0)
......
...@@ -5,6 +5,9 @@ exec sql include header_test; ...@@ -5,6 +5,9 @@ exec sql include header_test;
exec sql type str is varchar[10]; exec sql type str is varchar[10];
#include <stdlib.h>
#include <string.h>
int int
main () main ()
{ {
...@@ -28,7 +31,7 @@ exec sql end declare section; ...@@ -28,7 +31,7 @@ exec sql end declare section;
exec sql declare cur cursor for exec sql declare cur cursor for
select name, born, age, married, children from meskes; select name, born, age, married, children from meskes;
char msg[128], command[128]; char msg[128];
FILE *dbgs; FILE *dbgs;
if ((dbgs = fopen("log", "w")) != NULL) if ((dbgs = fopen("log", "w")) != NULL)
...@@ -63,7 +66,7 @@ exec sql end declare section; ...@@ -63,7 +66,7 @@ exec sql end declare section;
exec sql fetch from cur into :personal:ind_personal, :married:ind_married, :children:ind_children; exec sql fetch from cur into :personal:ind_personal, :married:ind_married, :children:ind_children;
printf("%8.8s", personal.name.arr); printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0) if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born); printf(", born %ld", personal.birth.born);
if (ind_personal.ind_birth.age >= 0) if (ind_personal.ind_birth.age >= 0)
printf(", age = %d", personal.birth.age); printf(", age = %d", personal.birth.age);
if (ind_married >= 0) if (ind_married >= 0)
...@@ -93,7 +96,7 @@ exec sql end declare section; ...@@ -93,7 +96,7 @@ exec sql end declare section;
exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children:ind_children; exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children:ind_children;
printf("%8.8s", personal.name.arr); printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0) if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born); printf(", born %ld", personal.birth.born);
if (ind_personal.ind_birth.age >= 0) if (ind_personal.ind_birth.age >= 0)
printf(", age = %d", personal.birth.age); printf(", age = %d", personal.birth.age);
if (ind_married >= 0) if (ind_married >= 0)
......
#include <locale.h> #include <locale.h>
#include <string.h>
exec sql whenever sqlerror sqlprint; exec sql whenever sqlerror sqlprint;
......
// $Id: test_notice.pgc,v 1.1 2000/09/20 13:25:52 meskes Exp $ // $Id: test_notice.pgc,v 1.2 2001/08/11 10:52:09 petere Exp $
exec sql include sqlca; exec sql include sqlca;
#include <stdio.h> #include <stdio.h>
void printwarning(void) static void printwarning(void)
{ {
if (sqlca.sqlwarn[0]) printf("sqlca.sqlwarn: %c",sqlca.sqlwarn[0]); if (sqlca.sqlwarn[0]) printf("sqlca.sqlwarn: %c",sqlca.sqlwarn[0]);
else return; else return;
...@@ -18,7 +18,7 @@ void printwarning(void) ...@@ -18,7 +18,7 @@ void printwarning(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
exec sql begin declare section; exec sql begin declare section;
int index,payload; int payload;
exec sql end declare section; exec sql end declare section;
FILE *dbgs; FILE *dbgs;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment