- printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
-
- strcpy(msg, "commit");
- exec sql commit;
-
- strcpy(msg, "select");
- exec sql at pm select name, amount, letter into :name_letter:ind from "Test";
-
- printf("Database: pm\n");
- for (i=0, j=sqlca.sqlerrd[2]; i
- printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name_letter[i].name, i, name_letter[i].amount,i, name_letter[i].letter);
-
- name_letter[4].amount=1407;
- strcpy(msg, "insert");
- exec sql insert into "Test" (name, amount, letter) values (:name_letter[4]);
-
- strcpy(msg, "select");
- exec sql select name, amount, letter into :name_letter[2] from "Test" where amount = 1407;
-
- printf("Database: mm\n");
- printf("name[2]=%8.8s\tamount[2]=%d\tletter[2]=%c\n", name_letter[2].name, name_letter[2].amount, name_letter[2].letter);
-
- /* Start automatic transactioning for connection main. */
- exec sql set autocommit to on;
-
- strcpy(msg, "drop");
- exec sql drop table "Test";
- exec sql at pm drop table "Test";
-
- strcpy(msg, "disconnect");
- exec sql disconnect main;
- exec sql disconnect pm;
-
- if (dbgs != NULL)
- fclose(dbgs);
-
- return (0);
-}
+++ /dev/null
-#include
-#include
-
-exec sql include header_test;
-
-exec sql type c is char reference;
-typedef char* c;
-
-exec sql type ind is union { int integer; short smallint; };
-typedef union { int integer; short smallint; } ind;
-
-#define BUFFERSIZ 8
-exec sql type str is varchar[BUFFERSIZ];
-
-exec sql declare cur cursor for
- select name, born, age, married, children from meskes;
-
-int
-main (void)
-{
- exec sql struct birthinfo { long born; short age; };
-exec sql begin declare section;
- struct personal_struct { str name;
- struct birthinfo birth;
- } personal, *p;
- struct personal_indicator { int ind_name;
- struct birthinfo ind_birth;
- } ind_personal, *i;
- ind ind_children;
- char *query="select name, born, age, married, children from meskes where name = :var1";
-exec sql end declare section;
-
- exec sql char *married = NULL;
- exec sql float ind_married;
- exec sql ind children;
-
- exec sql var ind_married is long;
-
- char msg[128];
- FILE *dbgs;
-
- if ((dbgs = fopen("log", "w")) != NULL)
- ECPGdebug(1, dbgs);
-
- strcpy(msg, "connect");
- exec sql connect to tcp:postgresql://127.0.0.1:5432/mm;
-
- strcpy(msg, "create");
- exec sql create table meskes(name char(8), born integer, age smallint, married date, children integer);
-
- strcpy(msg, "insert");
- exec sql insert into meskes(name, married, children) values ('Petra', '19900404', 3);
- exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 35, '19900404', 3);
- exec sql insert into meskes(name, born, age) values ('Carsten', 19910103,10);
- exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 8);
- exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 4);
-
- strcpy(msg, "commit");
- exec sql commit;
-
- strcpy(msg, "open");
- exec sql open cur;
-
- exec sql whenever not found do break;
-
- p=&personal;
- i=&ind_personal;
- memset(i, 0, sizeof(ind_personal));
- while (1) {
- strcpy(msg, "fetch");
- exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;
- printf("%8.8s", personal.name.arr);
- if (i->ind_birth.born >= 0)
- printf(", born %ld", personal.birth.born);
- if (i->ind_birth.age >= 0)
- printf(", age = %d", personal.birth.age);
- if ((long)ind_married >= 0)
- printf(", married %s", married);
- if (ind_children.smallint >= 0)
- printf(", children = %d", children.integer);
- putchar('\n');
-
- free(married);
- married = NULL;
- }
-
- strcpy(msg, "close");
- exec sql close cur;
-
- /* and now a same query with prepare */
- exec sql prepare MM from :query;
- exec sql declare prep cursor for MM;
-
- strcpy(msg, "open");
- exec sql open prep using 'Petra';
-
- exec sql whenever not found do break;
-
- while (1) {
- strcpy(msg, "fetch");
- exec sql fetch in prep 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 %ld", personal.birth.born);
- if (ind_personal.ind_birth.age >= 0)
- printf(", age = %d", personal.birth.age);
- if ((long)ind_married >= 0)
- printf(", married %s", married);
- if (ind_children.smallint >= 0)
- printf(", children = %d", children.integer);
- putchar('\n');
- }
-
- free(married);
-
- strcpy(msg, "close");
- exec sql close prep;
-
- strcpy(msg, "drop");
- exec sql drop table meskes;
-
- strcpy(msg, "commit");
- exec sql commit;
-
- strcpy(msg, "disconnect");
- exec sql disconnect;
-
- if (dbgs != NULL)
- fclose(dbgs);
-
- return (0);
-}
+++ /dev/null
-/****************************************************************************/
-/* Test comment */
-/*--------------------------------------------------------------------------*/
-exec sql include header_test;
-
-exec sql type str is varchar[10];
-
-#include
-#include
-
-int
-main (void)
-{
-exec sql begin declare section;
- typedef struct { long born; short age; } birthinfo;
- struct personal_struct { str name;
- birthinfo birth;
- } personal;
- struct personal_indicator { int ind_name;
- birthinfo ind_birth;
- } ind_personal;
- int *ind_married = NULL;
- int children, movevalue = 2;
- int ind_children;
- str *married = NULL;
- char *wifesname="Petra";
- char *query="select * from meskes where name = ?";
-exec sql end declare section;
-
- exec sql declare cur cursor for
- select name, born, age, married, children from meskes;
-
- char msg[128];
- FILE *dbgs;
-
- if ((dbgs = fopen("log", "w")) != NULL)
- ECPGdebug(1, dbgs);
-
- strcpy(msg, "connect");
- exec sql connect to unix:postgresql://localhost:5432/mm;
-
- strcpy(msg, "create");
- exec sql create table meskes(name char(8), born integer, age smallint, married date, children integer);
-
- strcpy(msg, "insert");
- exec sql insert into meskes(name, married, children) values (:wifesname, '19900404', 3);
- exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 35, '19900404', 3);
- exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 10);
- exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 8);
- exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 4);
-
- strcpy(msg, "commit");
- exec sql commit;
-
- strcpy(msg, "open");
- exec sql open cur;
-
- strcpy(msg, "move");
- exec sql move :movevalue in cur;
-
- exec sql whenever not found do break;
-
- while (1) {
- strcpy(msg, "fetch");
- 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 %ld", personal.birth.born);
- if (ind_personal.ind_birth.age >= 0)
- printf(", age = %d", personal.birth.age);
- if (*ind_married >= 0)
- printf(", married %10.10s", married->arr);
- if (ind_children >= 0)
- printf(", children = %d", children);
- putchar('\n');
-
- free(married);
- married = NULL;
- }
-
- strcpy(msg, "close");
- exec sql close cur;
-
- /* and now a query with prepare */
- exec sql prepare MM from :query;
- exec sql declare prep cursor for MM;
-
- strcpy(msg, "open");
- exec sql open prep using :wifesname;
-
- exec sql whenever not found do break;
-
- while (1) {
- strcpy(msg, "fetch");
- exec sql fetch in prep 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 %ld", personal.birth.born);
- if (ind_personal.ind_birth.age >= 0)
- printf(", age = %d", personal.birth.age);
- if (*ind_married >= 0)
- printf(", married %10.10s", married->arr);
- if (ind_children >= 0)
- printf(", children = %d", children);
- putchar('\n');
- }
-
- free(married);
-
- strcpy(msg, "close");
- exec sql close prep;
-
- strcpy(msg, "drop");
- exec sql drop table meskes;
-
- strcpy(msg, "commit");
- exec sql commit;
-
- strcpy(msg, "disconnect");
- exec sql disconnect;
-
- if (dbgs != NULL)
- fclose(dbgs);
-
- return (0);
-}
+++ /dev/null
-#include
-#include
-#include
-
-exec sql whenever sqlerror sqlprint;
-
-exec sql include sqlca;
-
-EXEC SQL type errtype is enum
-{
- OK = 0,
- ERR = 1,
- WARN = 2
-};
-
-int
-main (void)
-{
-EXEC SQL BEGIN DECLARE SECTION;
- struct
- {
- errtype e :2;
- int code :14;
- } error = {1, 147};
- int i = 1;
- int *did = &i;
- int a[10] = {9,8,7,6,5,4,3,2,1,0};
- char text[25] = "klmnopqrst";
- char *t = (char *)malloc(10);
- double f;
- bool b = true;
- varchar database[3];
-EXEC SQL END DECLARE SECTION;
- FILE *dbgs;
-
- strcpy(t, "0123456789");
- setlocale(LC_ALL, "de_DE");
-
- if ((dbgs = fopen("log", "w")) != NULL)
- ECPGdebug(1, dbgs);
-
- strcpy(database.arr, "mm");
- EXEC SQL CONNECT TO :database;
-
- EXEC SQL SET AUTOCOMMIT = ON;
-
- EXEC SQL BEGIN WORK;
-
- EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), b bool, t int, err int);
-
- EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij','f',0,0);
-
- EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(140787.0,2,:a,:text,'t',2,14);
-
-EXEC SQL IFDEF BIT_FIELD_IS_NOT_ACCESSIBLE;
- EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,:error);
-EXEC SQL ELSE;
- EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,1,147);
- error.code=0;
-EXEC SQL ENDIF;
-
- EXEC SQL COMMIT;
-
- EXEC SQL BEGIN WORK;
-
- EXEC SQL SELECT f,text,b
- INTO :f,:text,:b
- FROM test
- WHERE i = 1;
-
- printf("Found f=%f text=%10.10s b=%d\n", f, text, b);
-
- f=140787;
- EXEC SQL SELECT a,text
- INTO :a,:t
- FROM test
- WHERE f = :f;
-
- for (i = 0; i < 10; i++)
- printf("Found a[%d] = %d\n", i, a[i]);
-
- printf("Found text=%10.10s\n", t);
-
- EXEC SQL SELECT a
- INTO :text
- FROM test
- WHERE f = :f;
-
- printf("Found text=%s\n", text);
-
- EXEC SQL DROP TABLE test;
-
- EXEC SQL COMMIT;
-
- EXEC SQL DISCONNECT;
-
- if (dbgs != NULL)
- fclose(dbgs);
-
- return (0);
-}
+++ /dev/null
-#include
-#include
-
-EXEC SQL typedef long mmInteger;
-EXEC SQL typedef char mmChar;
-EXEC SQL typedef short mmSmallInt;
-
-EXEC SQL BEGIN DECLARE SECTION;
-struct TBempl
-{
- mmInteger idnum;
- mmChar name[21];
- mmSmallInt accs;
- mmChar byte[20];
-};
-EXEC SQL END DECLARE SECTION;
-
-int
-main (void)
-{
- EXEC SQL BEGIN DECLARE SECTION;
- struct TBempl empl;
- char *data = "\\001\\155\\000\\212";
- union
- {
- mmSmallInt accs;
- char t[2];
- } a;
- EXEC SQL END DECLARE SECTION;
- FILE *dbgs;
- int i;
-
- if ((dbgs = fopen ("log", "w")) != NULL)
- ECPGdebug (1, dbgs);
-
- empl.idnum = 1;
- EXEC SQL connect to mm;
- if (sqlca.sqlcode)
- {
- printf ("connect error = %ld\n", sqlca.sqlcode);
- exit (sqlca.sqlcode);
- }
-
- EXEC SQL create table empl
- (idnum integer, name char (20), accs smallint, byte bytea);
- if (sqlca.sqlcode)
- {
- printf ("create error = %ld\n", sqlca.sqlcode);
- exit (sqlca.sqlcode);
- }
-
- EXEC SQL insert into empl values (1, 'first user', 320,:data);
- if (sqlca.sqlcode)
- {
- printf ("insert error = %ld\n", sqlca.sqlcode);
- exit (sqlca.sqlcode);
- }
-
- EXEC SQL select name, accs, byte
- into :empl.name, :empl.accs, :empl.byte
- from empl
- where idnum =:empl.idnum;
- if (sqlca.sqlcode)
- {
- printf ("select error = %ld\n", sqlca.sqlcode);
- exit (sqlca.sqlcode);
- }
- printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
-
- EXEC SQL DECLARE C CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum;
- EXEC SQL OPEN C;
- EXEC SQL FETCH C INTO:empl.name,:empl.accs,:empl.byte;
- if (sqlca.sqlcode)
- {
- printf ("fetch error = %ld\n", sqlca.sqlcode);
- exit (sqlca.sqlcode);
- }
-
- printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
-
- memset(empl.name, 0, 21L);
- memset(empl.byte, '#', 20L);
- EXEC SQL DECLARE B BINARY CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum;
- EXEC SQL OPEN B;
- EXEC SQL FETCH B INTO :empl.name,:a.accs,:empl.byte;
- if (sqlca.sqlcode)
- {
- printf ("fetch error = %ld\n", sqlca.sqlcode);
- exit (sqlca.sqlcode);
- }
-
- EXEC SQL CLOSE B;
-
- i=a.t[0];
- a.t[0]=a.t[1];
- a.t[1]=i;
-
- printf ("name=%s, accs=%d byte=", empl.name, a.accs);
- for (i=0; i<20; i++)
- {
- if (empl.byte[i] == '#')
- break;
- printf("(%o)", (unsigned char)empl.byte[i]);
- }
- printf("\n");
- EXEC SQL disconnect;
- fclose (dbgs);
- exit (0);
-}
+++ /dev/null
-// $PostgreSQL: pgsql/src/interfaces/ecpg/test/test_code100.pgc,v 1.3 2003/11/29 22:41:18 pgsql Exp $
-
-exec sql include sqlca;
-#include
-
-int main(int argc, char **argv)
-{ exec sql begin declare section;
- int index;
- exec sql end declare section;
-
-
- // ECPGdebug(1,stdout);
-
- exec sql connect to mm;
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql create table test (
- "index" numeric(3) primary key,
- "payload" int4 NOT NULL);
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
- exec sql commit work;
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- for (index=0;index<10;++index)
- { exec sql insert into test
- (payload, index)
- values (0, :index);
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
- }
- exec sql commit work;
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql update test
- set payload=payload+1 where index=-1;
- if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql delete from test where index=-1;
- if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql insert into test (select * from test where index=-1);
- if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql drop table test;
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
- exec sql commit work;
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql disconnect;
- if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
- return 0;
-}
+++ /dev/null
-EXEC SQL WHENEVER SQLERROR SQLPRINT;
-
-int
-main(void)
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char *stmt1 = "INSERT INTO test1 VALUES (?, ?)";
- char *stmt2 = "SELECT * from test1 where a = ? and b = ?";
- char *stmt3 = "SELECT * from test1 where a = ?";
-
- int val1 = 1;
- char val2[] = "one", val2output[] = "AAA";
- int val1output = 2, val2i = 0;
- int val2null = -1;
- EXEC SQL END DECLARE SECTION;
- FILE *dbgs;
-
- if ((dbgs = fopen("log", "w")) != NULL)
- ECPGdebug(1, dbgs);
-
- EXEC SQL ALLOCATE DESCRIPTOR indesc;
- EXEC SQL ALLOCATE DESCRIPTOR outdesc;
-
- EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1;
- EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2;
-
- EXEC SQL CONNECT TO mm;
-
- EXEC SQL CREATE TABLE test1 (a int, b text);
- EXEC SQL PREPARE foo1 FROM :stmt1;
- EXEC SQL PREPARE foo2 FROM :stmt2;
- EXEC SQL PREPARE foo3 FROM :stmt3;
-
- EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc;
-
- EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
- EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2null, DATA = :val2;
-
- EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc;
-
- EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1;
- EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2;
-
- EXEC SQL EXECUTE foo2 USING DESCRIPTOR indesc INTO DESCRIPTOR outdesc;
-
- EXEC SQL GET DESCRIPTOR outdesc VALUE 1 :val2output = DATA;
- printf("output = %s\n", val2output);
-
- EXEC SQL DECLARE c1 CURSOR FOR foo2;
- EXEC SQL OPEN c1 USING DESCRIPTOR indesc;
-
- EXEC SQL FETCH next FROM c1 INTO :val1output, :val2output;
- printf("val1=%d val2=%s\n", val1output, val2output);
-
- EXEC SQL CLOSE c1;
-
- EXEC SQL SET DESCRIPTOR indesc COUNT = 1;
- EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
-
- EXEC SQL DECLARE c2 CURSOR FOR foo3;
- EXEC SQL OPEN c2 USING DESCRIPTOR indesc;
-
- EXEC SQL FETCH next FROM c2 INTO :val1output, :val2output :val2i;
- printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
-
- EXEC SQL CLOSE c2;
-
- EXEC SQL SELECT * INTO :val1output, :val2output :val2i FROM test1 where a = 2;
- printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
-
- EXEC SQL DROP TABLE test1;
- EXEC SQL DISCONNECT;
-
- EXEC SQL DEALLOCATE DESCRIPTOR indesc;
- EXEC SQL DEALLOCATE DESCRIPTOR outdesc;
-
- if (dbgs != NULL)
- fclose(dbgs);
-
- return 0;
-}
+++ /dev/null
-#include
-#include
-#include
-
-int main(int argc, char* argv[]) {
- FILE *dbgs;
-
- if ((dbgs = fopen("log", "w")) != NULL)
- ECPGdebug(1, dbgs);
- EXEC SQL CONNECT TO mm;
-
- EXEC SQL SET AUTOCOMMIT TO ON;
- EXEC SQL WHENEVER SQLWARNING SQLPRINT;
- EXEC SQL WHENEVER SQLERROR SQLPRINT;
-
- EXEC SQL CREATE TABLE My_Table ( Item1 int, Item2 text );
-
- EXEC SQL CREATE FUNCTION My_Table_Check() RETURNS trigger
- AS $test$
- BEGIN
- RAISE NOTICE 'TG_NAME=%, TG WHEN=%', TG_NAME, TG_WHEN;
- RETURN NEW;
- END; $test$
- LANGUAGE plpgsql;
-
- EXEC SQL CREATE TRIGGER My_Table_Check_Trigger
- BEFORE INSERT
- ON My_Table
- FOR EACH ROW
- EXECUTE PROCEDURE My_Table_Check();
-
- EXEC SQL INSERT INTO My_Table VALUES (1234, 'Some random text');
- EXEC SQL INSERT INTO My_Table VALUES (5678, 'The Quick Brown');
-
- EXEC SQL DROP TRIGGER My_Table_Check_Trigger ON My_Table;
- EXEC SQL DROP FUNCTION My_Table_Check();
- EXEC SQL DROP TABLE My_Table;
-
- EXEC SQL DISCONNECT ALL;
- if (dbgs != NULL)
- fclose(dbgs);
-
-
- return 0;
-}
+++ /dev/null
-#include "sqltypes.h"
-
-static void openit(void);
-
-int main(void)
-{
- $int i = 14;
- $decimal j, m, n;
- FILE *dbgs;
-
- if ((dbgs = fopen("log", "w")) != NULL)
- ECPGdebug(1, dbgs);
-
- $connect to mm;
-
- $create table test(i int primary key, j int);
-
- rsetnull(CDECIMALTYPE, (char *)&j);
- $insert into test (i, j) values (7, :j);
- $commit;
-
- $insert into test (i, j) values (7, 2);
- printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
- if (sqlca.sqlcode != 0) $rollback;
-
- $insert into test (i, j) values (:i, 1);
- $commit;
-
- $select i from test where j=(select j from test);
- printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
- if (sqlca.sqlcode != 0) $rollback;
-
- $declare c cursor for select * from test where i <= :i;
- openit();
-
- deccvint(0, &j);
-
- while (1)
- {
- $fetch forward c into :i, :j;
- if (sqlca.sqlcode == 100) break;
- else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);
-
- if (risnull(CDECIMALTYPE, (char *)&j))
- printf("%d NULL\n", i);
- else
- {
- int a;
-
- dectoint(&j, &a);
- printf("%d %d\n", i, a);
- }
- }
-
- deccvint(7, &j);
- deccvint(14, &m);
- decadd(&j, &m, &n);
- $delete from test where i=:n;
- printf("DELETE: %ld\n", sqlca.sqlcode);
-
- $select 1 from test where i=14;
- printf("Exists: %ld\n", sqlca.sqlcode);
-
- $select 1 from test where i=147;
- printf("Does not exist: %ld\n", sqlca.sqlcode);
-
- $commit;
- $drop table test;
- $commit;
-
- $close database;
-
- return 0;
-}
-
-static void openit(void)
-{
- $open c;
-}
-
+++ /dev/null
-#include
-#include
-#include "sqltypes.h"
-
-EXEC SQL include sqlca.h;
-
-/* Check SQLCODE, and produce a "standard error" if it's wrong! */
-static void sql_check(char *fn, char *caller, int ignore)
-{
- char errorstring[255];
-
- if (SQLCODE == ignore)
- return;
- else
- {
- if (SQLCODE != 0)
- {
-
- sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
- SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
- fprintf(stderr, "%s", errorstring);
- printf("%s\n", errorstring);
-
- /* attempt a ROLLBACK */
- EXEC SQL rollback;
-
- if (SQLCODE == 0)
- {
- sprintf(errorstring, "Rollback successful.\n");
- } else {
- sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
- }
-
- fprintf(stderr, "%s", errorstring);
- printf("%s\n", errorstring);
-
- exit(1);
- }
- }
-}
-
-
-
-int main(void)
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int c;
- timestamp d;
- timestamp maxd;
- char dbname[30];
- EXEC SQL END DECLARE SECTION;
-
- EXEC SQL whenever sqlerror sqlprint;
-
- strcpy(dbname, "mm");
- EXEC SQL connect to :dbname;
- sql_check("main", "connect", 0);
-
- EXEC SQL create table history (customerid integer, timestamp timestamp without time zone, action_taken char(5), narrative varchar(100));
- sql_check("main", "create", 0);
-
- EXEC SQL insert into history
- (customerid, timestamp, action_taken, narrative)
- values(1, now(), 'test', 'test');
- sql_check("main", "insert", 0);
-
- EXEC SQL select max(timestamp)
- into :maxd
- from history;
- sql_check("main", "select max", 100);
-
- if (risnull(CDTIMETYPE, (char *) &maxd))
- {
- printf("Nothing on the history table\n\n");
- exit(0);
- }
-
- EXEC SQL select customerid, timestamp
- into :c, :d
- from history
- where timestamp = :maxd
- limit 1;
- sql_check("main", "select", 0);
-
- printf("Read in customer %d\n", c);
-
- /* Adding 1 to d adds 1 second. So:
- 60 1 minute
- 3600 1 hour
- 86400 1 day */
- d=d+86400;
- c++;
-
- EXEC SQL insert into history
- (customerid, timestamp, action_taken, narrative)
- values(:c, :d, 'test', 'test');
- sql_check("main", "update", 0);
-
- EXEC SQL commit;
-
- EXEC SQL drop table history;
- sql_check("main", "drop", 0);
-
- EXEC SQL commit;
-
- EXEC SQL disconnect;
- sql_check("main", "disconnect", 0);
-
- printf("All OK!\n");
-
- exit(0);
-
-/*
- Table "public.history"
- Column | Type | Modifiers
---------------+-----------------------------+-----------
- customerid | integer | not null
- timestamp | timestamp without time zone | not null
- action_taken | character(5) | not null
- narrative | character varying(100) |
-*/
-
-}
+++ /dev/null
-exec sql include sqlca;
-
-int fa(void) { return 2; }
-int fb(int x) { return x; }
-int fc(const char *x) { return *x; }
-int fd(const char *x,int i) { return (*x)*i; }
-enum e { ENUM0, ENUM1 };
-int fe(enum e x) { return (int)x; }
-struct sa { int member; };
-
-void sqlmeldung(char *meldung, short trans)
-{
-}
-
-exec sql define NONO 0;
-
-#define YES 1
-
-#ifdef _cplusplus
-namespace N
-{ static const int i=2;
-};
-#endif
-
-int main(void)
-{ struct sa x,*y=&x;
-exec sql begin declare section;
-int a=(int)2;
-int b=2+2;
-int b2=(14*7);
-int d=x.member;
-int g=fb(2);
-int i=3^1;
-int j=1?1:2;
-
-int e=y->member;
-int c=10>>2;
-bool h=2||1;
-long iay /* = 1L */ ;
-long long iax /* = 40000000000LL */ ;
-exec sql end declare section;
-
-int f=fa();
-
-#ifdef _cplusplus
-exec sql begin declare section;
-int k=N::i; /* compile error */
-exec sql end declare section;
-#endif
-
-exec sql whenever sqlerror do fa();
-exec sql select now();
-exec sql whenever sqlerror do fb(20);
-exec sql select now();
-exec sql whenever sqlerror do fc("50");
-exec sql select now();
-exec sql whenever sqlerror do fd("50",1);
-exec sql select now();
-exec sql whenever sqlerror do fe(ENUM0);
-exec sql select now();
-exec sql whenever sqlerror do sqlmeldung(NULL, NONO);
-exec sql select now();
-return 0;
-}
+++ /dev/null
-// $PostgreSQL: pgsql/src/interfaces/ecpg/test/test_notice.pgc,v 1.4 2003/11/29 22:41:18 pgsql Exp $
-
-exec sql include sqlca;
-
-#include
-
-static void printwarning(void)
-{
- if (sqlca.sqlwarn[0]) printf("sqlca.sqlwarn: %c",sqlca.sqlwarn[0]);
- else return;
-
- if (sqlca.sqlwarn[1]) putchar('1');
- if (sqlca.sqlwarn[2]) putchar('2');
-
- putchar('\n');
-}
-
-int main(int argc, char **argv)
-{
- exec sql begin declare section;
- int payload;
- exec sql end declare section;
- FILE *dbgs;
-
- /* actually this will print 'sql error' if a warning occurs */
- exec sql whenever sqlwarning do printwarning();
-
- if ((dbgs = fopen("log", "w")) != NULL)
- ECPGdebug(1, dbgs);
-
- exec sql connect to mm;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql create table test (
- "index" numeric(3) primary key,
- "payload" int4 NOT NULL);
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql commit work;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql begin work;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql begin work;
- if (sqlca.sqlcode!=ECPG_WARNING_IN_TRANSACTION) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql commit;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql commit;
- if (sqlca.sqlcode!=ECPG_WARNING_NO_TRANSACTION) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql rollback;
- if (sqlca.sqlcode!=ECPG_WARNING_NO_TRANSACTION) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- sqlca.sqlcode=0;
- exec sql declare x cursor for select * from test;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql open x;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql open x;
- if (sqlca.sqlcode!=ECPG_WARNING_PORTAL_EXISTS) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql close x;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql close x;
- if (sqlca.sqlcode!=ECPG_WARNING_UNKNOWN_PORTAL) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql update test set nonexistent=2;
- if (sqlca.sqlcode!=ECPG_PGSQL) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql select payload into :payload from test where index=1;
- if (sqlca.sqlcode!=ECPG_WARNING_QUERY_IGNORED) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql rollback;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- // this will raise a warning
- exec sql drop table test;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
- exec sql commit work;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- exec sql disconnect;
- if (sqlca.sqlcode) printf("%d %ld:%s\n",__LINE__,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-
- if (dbgs != NULL)
- fclose(dbgs);
- return 0;
-}
+++ /dev/null
-/*
- * Thread test program
- * by Philip Yarra & Lee Kindness.
- */
-
-/* #define ECPGDEBUG */
-
-#include
-
-void *test_thread(void *arg);
-
-EXEC SQL BEGIN DECLARE SECTION;
-char *l_dbname;
-EXEC SQL END DECLARE SECTION;
-int nthreads = 2;
-int iterations = 10;
-
-int main(int argc, char *argv[])
-{
-#ifdef ECPGDEBUG
- char debugfilename[] = "thread_test.log";
- FILE *debugfile;
-#endif
- pthread_t *threads;
- int n;
- EXEC SQL BEGIN DECLARE SECTION;
- int l_rows;
- EXEC SQL END DECLARE SECTION;
-
- /* parse command line arguments */
- if( (argc < 2) || (argc > 4) )
- {
- fprintf(stderr, "Usage: %s dbname [threads] [iterations_per_thread]\n", argv[0]);
- return( 1 );
- }
- l_dbname = argv[1];
- if( argc >= 3 )
- nthreads = atoi(argv[2]);
- if( argc == 4 )
- iterations = atoi(argv[3]);
-
- /* open ECPG debug log? */
-#ifdef ECPGDEBUG
- debugfile = fopen(debugfilename, "w");
- if( debugfile != NULL )
- ECPGdebug(1, debugfile);
- else
- fprintf(stderr, "Cannot open ECPG debug log: %s\n", debugfilename);
-#endif
-
- /* setup test_thread table */
- EXEC SQL CONNECT TO :l_dbname;
- EXEC SQL DROP TABLE test_thread; /* DROP might fail */
- EXEC SQL COMMIT;
- EXEC SQL CREATE TABLE
- test_thread(tstamp TIMESTAMP NOT NULL DEFAULT CAST(timeofday() AS TIMESTAMP),
- thread TEXT NOT NULL,
- iteration INTEGER NOT NULL,
- PRIMARY KEY(thread, iteration));
- EXEC SQL COMMIT;
- EXEC SQL DISCONNECT;
-
- /* create, and start, threads */
- threads = calloc(nthreads, sizeof(pthread_t));
- if( threads == NULL )
- {
- fprintf(stderr, "Cannot alloc memory\n");
- return( 1 );
- }
- for( n = 0; n < nthreads; n++ )
- {
- pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
- }
-
- /* wait for thread completion */
- for( n = 0; n < nthreads; n++ )
- {
- pthread_join(threads[n], NULL);
- }
- free(threads);
-
- /* and check results */
- EXEC SQL CONNECT TO :l_dbname;
- EXEC SQL SELECT COUNT(*) INTO :l_rows FROM test_thread;
- EXEC SQL COMMIT;
- EXEC SQL DISCONNECT;
- if( l_rows == (nthreads * iterations) )
- printf("\nSuccess.\n");
- else
- printf("\nERROR: Failure - expecting %d rows, got %d.\n", nthreads * iterations, l_rows);
-
- /* close ECPG debug log? */
-#ifdef ECPGDEBUG
- if( debugfile != NULL )
- {
- ECPGdebug(0, debugfile);
- fclose(debugfile);
- }
-#endif
-
- return( 0 );
-}
-
-void *test_thread(void *arg)
-{
- long threadnum = (long)arg;
- EXEC SQL BEGIN DECLARE SECTION;
- int l_i;
- char l_connection[128];
- EXEC SQL END DECLARE SECTION;
-
- /* build up connection name, and connect to database */
- snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum);
- EXEC SQL WHENEVER sqlerror sqlprint;
- EXEC SQL CONNECT TO :l_dbname AS :l_connection;
- if( sqlca.sqlcode != 0 )
- {
- printf("%s: ERROR: cannot connect to database!\n", l_connection);
- return( NULL );
- }
- EXEC SQL AT :l_connection BEGIN;
-
- /* insert into test_thread table */
- for( l_i = 1; l_i <= iterations; l_i++ )
- {
- printf("%s: inserting %d\n", l_connection, l_i);
- EXEC SQL AT :l_connection INSERT INTO test_thread(thread, iteration) VALUES(:l_connection, :l_i);
- if( sqlca.sqlcode == 0 )
- printf("%s: insert done\n", l_connection);
- else
- printf("%s: ERROR: insert failed!\n", l_connection);
- }
-
- /* all done */
- EXEC SQL AT :l_connection COMMIT;
- EXEC SQL DISCONNECT :l_connection;
- printf("%s: done!\n", l_connection);
- return( NULL );
-}
+++ /dev/null
-/*
- * Thread test program
- * by Lee Kindness.
- */
-
-/* #define ECPGDEBUG */
-
-#include
-
-void *test_thread(void *arg);
-
-EXEC SQL BEGIN DECLARE SECTION;
-char *l_dbname;
-EXEC SQL END DECLARE SECTION;
-int nthreads = 2;
-int iterations = 10;
-
-int main(int argc, char *argv[])
-{
-#ifdef ECPGDEBUG
- char debugfilename[] = "thread_test_implicit.log";
- FILE *debugfile;
-#endif
- pthread_t *threads;
- int n;
- EXEC SQL BEGIN DECLARE SECTION;
- int l_rows;
- EXEC SQL END DECLARE SECTION;
-
- /* parse command line arguments */
- if( (argc < 2) || (argc > 4) )
- {
- fprintf(stderr, "Usage: %s dbname [threads] [iterations_per_thread]\n", argv[0]);
- return( 1 );
- }
- l_dbname = argv[1];
- if( argc >= 3 )
- nthreads = atoi(argv[2]);
- if( argc == 4 )
- iterations = atoi(argv[3]);
-
- /* open ECPG debug log? */
-#ifdef ECPGDEBUG
- debugfile = fopen(debugfilename, "w");
- if( debugfile != NULL )
- ECPGdebug(1, debugfile);
- else
- fprintf(stderr, "Cannot open ECPG debug log: %s\n", debugfilename);
-#endif
-
- /* setup test_thread table */
- EXEC SQL CONNECT TO:l_dbname;
- EXEC SQL DROP TABLE test_thread; /* DROP might fail */
- EXEC SQL COMMIT;
- EXEC SQL CREATE TABLE
- test_thread(tstamp TIMESTAMP NOT NULL DEFAULT CAST(timeofday() AS TIMESTAMP),
- thread TEXT NOT NULL,
- iteration INTEGER NOT NULL,
- PRIMARY KEY(thread, iteration));
- EXEC SQL COMMIT;
- EXEC SQL DISCONNECT;
-
- /* create, and start, threads */
- threads = calloc(nthreads, sizeof(pthread_t));
- if( threads == NULL )
- {
- fprintf(stderr, "Cannot alloc memory\n");
- return( 1 );
- }
- for( n = 0; n < nthreads; n++ )
- {
- pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
- }
-
- /* wait for thread completion */
- for( n = 0; n < nthreads; n++ )
- {
- pthread_join(threads[n], NULL);
- }
- free(threads);
-
- /* and check results */
- EXEC SQL CONNECT TO :l_dbname;
- EXEC SQL SELECT COUNT(*) INTO :l_rows FROM test_thread;
- EXEC SQL COMMIT;
- EXEC SQL DISCONNECT;
- if( l_rows == (nthreads * iterations) )
- printf("\nSuccess.\n");
- else
- printf("\nERROR: Failure - expecting %d rows, got %d.\n", nthreads * iterations, l_rows);
-
- /* close ECPG debug log? */
-#ifdef ECPGDEBUG
- if( debugfile != NULL )
- {
- ECPGdebug(0, debugfile);
- fclose(debugfile);
- }
-#endif
-
- return( 0 );
-}
-
-void *test_thread(void *arg)
-{
- long threadnum = (long)arg;
- EXEC SQL BEGIN DECLARE SECTION;
- int l_i;
- char l_connection[128];
- EXEC SQL END DECLARE SECTION;
-
- /* build up connection name, and connect to database */
- snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum);
- EXEC SQL WHENEVER sqlerror sqlprint;
- EXEC SQL CONNECT TO :l_dbname AS :l_connection;
- if( sqlca.sqlcode != 0 )
- {
- printf("%s: ERROR: cannot connect to database!\n", l_connection);
- return( NULL );
- }
- EXEC SQL BEGIN;
-
- /* insert into test_thread table */
- for( l_i = 1; l_i <= iterations; l_i++ )
- {
- printf("%s: inserting %d\n", l_connection, l_i);
- EXEC SQL INSERT INTO test_thread(thread, iteration) VALUES(:l_connection, :l_i);
- if( sqlca.sqlcode == 0 )
- printf("%s: insert done\n", l_connection);
- else
- printf("%s: ERROR: insert failed!\n", l_connection);
- }
-
- /* all done */
- EXEC SQL COMMIT;
- EXEC SQL DISCONNECT :l_connection;
- printf("%s: done!\n", l_connection);
- return( NULL );
-}
+++ /dev/null
-#include
-exec sql include sqlca;
-#include
-
-int main(void)
-{
- exec sql begin declare section;
- char **cpp=0;
- int *ipointer=0;
- exec sql end declare section;
- int i;
-
- if (getenv("SQLOPT")) ECPGdebug(1,stderr);
-
- exec sql whenever sqlerror do sqlprint();
- exec sql connect to postgres;
-
- exec sql allocate descriptor mydesc;
- exec sql select tablename into descriptor mydesc from pg_tables;
- exec sql get descriptor mydesc value 1 :cpp=DATA, :ipointer=INDICATOR;
-
- printf("Result ");
- for (i=0;i
- { if (ipointer[i]) printf("NULL, ");
- else printf("'%s', ",cpp[i]);
- }
- ECPGfree_auto_mem();
- printf("\n");
-
- exec sql deallocate descriptor mydesc;
- exec sql disconnect;
- return 0;
-}