mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
*** empty log message ***
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
all: test1 test2 test3 test4 perftest
|
||||
all: stp.so test1 test2 test3 test4 test5 perftest
|
||||
|
||||
#LDFLAGS=-g -I /usr/local/pgsql/include -L/usr/local/pgsql/lib -lecpg -lpq -lcrypt
|
||||
LDFLAGS=-g -I../include -I/usr/include/postgresql -L/usr/lib/postgresql -L../lib -lecpg -lpq -lcrypt
|
||||
#LDFLAGS=-g -I/usr/include/postgresql -lecpg -lpq -lcrypt
|
||||
|
||||
#ECPG=/usr/local/pgsql/bin/ecpg
|
||||
ECPG=../preproc/ecpg -I../include
|
||||
#ECPG=/usr/bin/ecpg -I/usr/include/postgresql
|
||||
|
||||
.SUFFIXES: .pgc .c
|
||||
|
||||
@ -12,10 +14,16 @@ test1: test1.c
|
||||
test2: test2.c
|
||||
test3: test3.c
|
||||
test4: test4.c
|
||||
test5: test5.c
|
||||
perftest: perftest.c
|
||||
|
||||
.pgc.c:
|
||||
$(ECPG) $?
|
||||
|
||||
stp.so: stp.c
|
||||
cc -fPIC -I../include -I/usr/include/postgresql -c -o stp.o stp.c
|
||||
cc -shared -Wl,-soname,stp.so -o stp.so stp.o -lpq -lecpg
|
||||
|
||||
|
||||
clean:
|
||||
-/bin/rm test1 test2 test3 test4 perftest *.c log
|
||||
-/bin/rm test1 test2 test3 test4 test5 perftest *.c log stp.o stp.so
|
||||
|
16
src/interfaces/ecpg/test/stp.pgc
Normal file
16
src/interfaces/ecpg/test/stp.pgc
Normal file
@ -0,0 +1,16 @@
|
||||
EXEC SQL INCLUDE sqlca;
|
||||
|
||||
int my_fun (void)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
int sql_index = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
|
||||
EXEC SQL WHENEVER SQLERROR GOTO Error;
|
||||
EXEC SQL SELECT MIN(index) INTO :sql_index FROM tab;
|
||||
|
||||
return (sql_index);
|
||||
|
||||
Error:
|
||||
return (sqlca.sqlcode);
|
||||
}
|
@ -94,11 +94,20 @@ exec sql end declare section;
|
||||
strcpy(msg, "select");
|
||||
exec sql select name, amount, letter into :name, :amount, :letter from "Test";
|
||||
|
||||
printf("Database: mm\n");
|
||||
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
|
||||
{
|
||||
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
|
||||
amount[i]+=1000;
|
||||
}
|
||||
|
||||
strcpy(msg, "insert");
|
||||
exec sql at pm insert into "Test" (name, amount, letter) values (:name, :amount, :letter);
|
||||
|
||||
strcpy(msg, "select");
|
||||
exec sql at pm select * into :name, :amount, :letter from "Test";
|
||||
|
||||
printf("Database: pm\n");
|
||||
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
|
||||
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
|
||||
|
||||
|
@ -62,7 +62,7 @@ exec sql end declare section;
|
||||
|
||||
while (1) {
|
||||
strcpy(msg, "fetch");
|
||||
exec sql fetch from 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);
|
||||
if (ind_personal.ind_birth.born >= 0)
|
||||
printf(", born %d", personal.birth.born);
|
||||
|
@ -19,7 +19,7 @@ exec sql begin declare section;
|
||||
int ind_children;
|
||||
str *married = NULL;
|
||||
char *wifesname="Petra";
|
||||
char *query="select * from meskes where name = :var1";
|
||||
char *query="select * from meskes where name = ?";
|
||||
exec sql end declare section;
|
||||
|
||||
exec sql declare cur cursor for
|
||||
@ -54,7 +54,7 @@ exec sql end declare section;
|
||||
|
||||
while (1) {
|
||||
strcpy(msg, "fetch");
|
||||
exec sql fetch 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);
|
||||
if (ind_personal.ind_birth.born >= 0)
|
||||
printf(", born %d", personal.birth.born);
|
||||
@ -74,7 +74,7 @@ exec sql end declare section;
|
||||
exec sql close cur;
|
||||
|
||||
/* and now a query with prepare */
|
||||
exec sql prepare MM from "select name, born, age, married, children from meskes where name = ?";
|
||||
exec sql prepare MM from :query;
|
||||
exec sql declare prep cursor for MM;
|
||||
|
||||
strcpy(msg, "open");
|
||||
|
61
src/interfaces/ecpg/test/test5.pgc
Normal file
61
src/interfaces/ecpg/test/test5.pgc
Normal file
@ -0,0 +1,61 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
EXEC SQL INCLUDE sqlca;
|
||||
|
||||
static void ErrorExit (void);
|
||||
|
||||
int main (void)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
int result;
|
||||
int values[2], i;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
FILE *dbgs;
|
||||
|
||||
|
||||
if ((dbgs = fopen("log", "w")) != NULL)
|
||||
ECPGdebug(1, dbgs);
|
||||
|
||||
EXEC SQL WHENEVER SQLERROR DO ErrorExit();
|
||||
EXEC SQL CONNECT TO 'mm';
|
||||
EXEC SQL CREATE TABLE tab (index int);
|
||||
EXEC SQL INSERT INTO tab(index) values(14);
|
||||
EXEC SQL INSERT INTO tab(index) values(7);
|
||||
EXEC SQL COMMIT;
|
||||
|
||||
EXEC SQL CREATE FUNCTION my_fun () RETURNS int AS
|
||||
'/home/postgres/pgsql/src/interfaces/ecpg.mm/test/stp.so' LANGUAGE 'C';
|
||||
EXEC SQL COMMIT;
|
||||
|
||||
EXEC SQL SELECT index INTO :values FROM tab;
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("tab[%d] = %d\n", i, values[i]);
|
||||
|
||||
EXEC SQL SELECT my_fun () INTO :result;
|
||||
printf ("result = %d\n", result);
|
||||
|
||||
EXEC SQL DROP TABLE tab;
|
||||
EXEC SQL DROP FUNCTION my_fun ();
|
||||
EXEC SQL COMMIT;
|
||||
EXEC SQL DISCONNECT;
|
||||
|
||||
if (dbgs != NULL)
|
||||
fclose(dbgs);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
||||
static void ErrorExit (void)
|
||||
{
|
||||
EXEC SQL WHENEVER SQLERROR CONTINUE;
|
||||
|
||||
sqlprint();
|
||||
|
||||
EXEC SQL DROP TABLE tab;
|
||||
EXEC SQL DROP FUNCTION my_fun ();
|
||||
EXEC SQL COMMIT;
|
||||
|
||||
EXEC SQL DISCONNECT;
|
||||
exit (-1);
|
||||
}
|
Reference in New Issue
Block a user