mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Erk, the whole directory structure changed on us here...
This commit is contained in:
14
src/interfaces/ecpg/test/Makefile
Normal file
14
src/interfaces/ecpg/test/Makefile
Normal file
@ -0,0 +1,14 @@
|
||||
all: test2 perftest
|
||||
|
||||
test2: test2.c
|
||||
gcc -g -I ../include -I ../../../libpq -o test2 test2.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
|
||||
test2.c: test2.pgc
|
||||
../preproc/ecpg test2.pgc
|
||||
|
||||
perftest: perftest.c
|
||||
gcc -g -I ../include -I ../../../libpq -o perftest perftest.c ../lib/libecpg.a ../../../libpq/libpq.a -lcrypt
|
||||
perftest.c: perftest.pgc
|
||||
../preproc/ecpg perftest.pgc
|
||||
|
||||
clean:
|
||||
/bin/rm test2 test2.c perftest perftest.c
|
64
src/interfaces/ecpg/test/Ptest1.c
Normal file
64
src/interfaces/ecpg/test/Ptest1.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* 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);
|
||||
}
|
72
src/interfaces/ecpg/test/perftest.pgc
Normal file
72
src/interfaces/ecpg/test/perftest.pgc
Normal file
@ -0,0 +1,72 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
exec sql include sqlca;
|
||||
|
||||
#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 ()
|
||||
{
|
||||
exec sql begin declare section;
|
||||
long i;
|
||||
exec sql end declare section;
|
||||
struct timeval tvs, tve;
|
||||
|
||||
gettimeofday(&tvs, NULL);
|
||||
|
||||
exec sql connect 'mm';
|
||||
if (SQLCODE)
|
||||
db_error ("connect");
|
||||
|
||||
exec sql create table perftest(number int4, ascii char16);
|
||||
if (SQLCODE)
|
||||
db_error ("create t");
|
||||
|
||||
exec sql create unique index number on perftest(number);
|
||||
if (SQLCODE)
|
||||
db_error ("create i");
|
||||
|
||||
for (i = 0;i < 1407; i++)
|
||||
{
|
||||
exec sql begin declare section;
|
||||
char text[16];
|
||||
exec sql end declare section;
|
||||
|
||||
sprintf(text, "%ld", i);
|
||||
exec sql insert into perftest(number, ascii) values (:i, :text);
|
||||
if (SQLCODE)
|
||||
db_error ("insert");
|
||||
|
||||
exec sql commit;
|
||||
if (SQLCODE)
|
||||
db_error ("commit");
|
||||
}
|
||||
|
||||
exec sql drop index number;
|
||||
if (SQLCODE)
|
||||
db_error ("drop i");
|
||||
|
||||
exec sql drop table perftest;
|
||||
if (SQLCODE)
|
||||
db_error ("drop t");
|
||||
|
||||
exec sql commit;
|
||||
if (SQLCODE)
|
||||
db_error ("commit");
|
||||
|
||||
gettimeofday(&tve, NULL);
|
||||
|
||||
printf("I needed %ld seconds and %ld microseconds for this test\n", tve.tv_sec - tvs.tv_sec, tve.tv_usec - tvs.tv_usec);
|
||||
|
||||
return (0);
|
||||
}
|
60
src/interfaces/ecpg/test/test1.c
Normal file
60
src/interfaces/ecpg/test/test1.c
Normal file
@ -0,0 +1,60 @@
|
||||
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);
|
||||
}
|
50
src/interfaces/ecpg/test/test2.pgc
Normal file
50
src/interfaces/ecpg/test/test2.pgc
Normal file
@ -0,0 +1,50 @@
|
||||
exec sql include sqlca;
|
||||
|
||||
#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 ()
|
||||
{
|
||||
exec sql begin declare section;
|
||||
varchar text[8];
|
||||
int count;
|
||||
double control;
|
||||
exec sql end declare section;
|
||||
|
||||
exec sql connect 'mm';
|
||||
if (SQLCODE)
|
||||
db_error ("connect");
|
||||
|
||||
exec sql declare cur cursor for
|
||||
select text, control, count from test;
|
||||
if (SQLCODE) db_error ("declare");
|
||||
|
||||
exec sql open cur;
|
||||
if (SQLCODE)
|
||||
db_error ("open");
|
||||
|
||||
while (1) {
|
||||
exec sql fetch in cur into :text, :control, :count;
|
||||
if (SQLCODE)
|
||||
break;
|
||||
printf ("%8.8s %d %f\n", text.arr, count, control);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user