Commit 9b0e2057 authored by Michael Meskes's avatar Michael Meskes

*** empty log message ***

parent 49f68a85
...@@ -13,6 +13,8 @@ support for dynamic SQL with unknown number of variables with DESCRIPTORS ...@@ -13,6 +13,8 @@ support for dynamic SQL with unknown number of variables with DESCRIPTORS
The line numbering is not exact. The line numbering is not exact.
Inside an SQL statement quoting only works with SQL92 style double quotes: ''.
Missing statements: Missing statements:
- exec sql allocate - exec sql allocate
- exec sql deallocate - exec sql deallocate
......
...@@ -241,41 +241,6 @@ quote_postgres(char *arg, int lineno) ...@@ -241,41 +241,6 @@ quote_postgres(char *arg, int lineno)
return res; return res;
} }
/* This function returns a newly malloced string that has the \
in the strings inside the argument quoted with another \.
*/
static
char *
quote_strings(char *arg, int lineno)
{
char *res = (char *) ecpg_alloc(2 * strlen(arg) + 1, lineno);
int i,
ri;
bool string = false;
if (!res)
return (res);
for (i = 0, ri = 0; arg[i]; i++, ri++)
{
switch (arg[i])
{
case '\'':
string = string ? false : true;
break;
case '\\':
res[ri++] = '\\';
default:
;
}
res[ri] = arg[i];
}
res[ri] = '\0';
return res;
}
/* /*
* create a list of variables * create a list of variables
* The variables are listed with input variables preceeding outputvariables * The variables are listed with input variables preceeding outputvariables
...@@ -544,17 +509,8 @@ ECPGexecute(struct statement * stmt) ...@@ -544,17 +509,8 @@ ECPGexecute(struct statement * stmt)
strncpy(newcopy, (char *) var->value, slen); strncpy(newcopy, (char *) var->value, slen);
newcopy[slen] = '\0'; newcopy[slen] = '\0';
if (!(mallocedval = (char *) ecpg_alloc(2 * strlen(newcopy) + 1, stmt->lineno)))
return false;
tmp = quote_strings(newcopy, stmt->lineno);
if (!tmp)
return false;
strcat(mallocedval, tmp); tobeinserted = newcopy;
free(newcopy);
tobeinserted = mallocedval;
} }
break; break;
case ECPGt_varchar: case ECPGt_varchar:
......
...@@ -9,8 +9,9 @@ CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION) \ ...@@ -9,8 +9,9 @@ CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION) \
-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \ -DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
-DINCLUDE_PATH=\"$(HEADERDIR)\" -DINCLUDE_PATH=\"$(HEADERDIR)\"
OBJ=preproc.o pgc.o type.o ecpg.o ecpg_keywords.o ../../../backend/parser/scansup.o \ OBJ=preproc.o pgc.o type.o ecpg.o ecpg_keywords.o \
keywords.o c_keywords.o ../lib/typename.o keywords.o c_keywords.o ../lib/typename.o
#../../../backend/parser/scansup.o
all:: ecpg all:: ecpg
......
...@@ -248,7 +248,8 @@ cppline {space}*#.*(\\{space}*\n)*\n* ...@@ -248,7 +248,8 @@ cppline {space}*#.*(\\{space}*\n)*\n*
} }
<xq>{xqstop} { <xq>{xqstop} {
BEGIN(SQL); BEGIN(SQL);
yylval.str = mm_strdup(scanstr(literal)); /* yylval.str = mm_strdup(scanstr(literal));*/
yylval.str = mm_strdup(literal);
return SCONST; return SCONST;
} }
<xq>{xqdouble} | <xq>{xqdouble} |
...@@ -609,7 +610,8 @@ cppline {space}*#.*(\\{space}*\n)*\n* ...@@ -609,7 +610,8 @@ cppline {space}*#.*(\\{space}*\n)*\n*
if (strcmp(old, ptr->old) == 0) if (strcmp(old, ptr->old) == 0)
{ {
free(ptr->new); free(ptr->new);
ptr->new = mm_strdup(scanstr(literal)); /* ptr->new = mm_strdup(scanstr(literal));*/
ptr->new = mm_strdup(literal);
} }
} }
if (ptr == NULL) if (ptr == NULL)
...@@ -618,7 +620,8 @@ cppline {space}*#.*(\\{space}*\n)*\n* ...@@ -618,7 +620,8 @@ cppline {space}*#.*(\\{space}*\n)*\n*
/* initial definition */ /* initial definition */
this->old = old; this->old = old;
this->new = mm_strdup(scanstr(literal)); /* this->new = mm_strdup(scanstr(literal));*/
this->new = mm_strdup(literal);
this->next = defines; this->next = defines;
defines = this; defines = this;
} }
......
...@@ -6,7 +6,7 @@ exec sql include sqlca; ...@@ -6,7 +6,7 @@ exec sql include sqlca;
exec sql define AMOUNT 4; exec sql define AMOUNT 4;
exec sql type intarray is int[AMOUNT]; exec sql type intarray is int[AMOUNT];
exec sql type string is char(6); exec sql type string is char(8);
typedef int intarray[AMOUNT]; typedef int intarray[AMOUNT];
...@@ -16,7 +16,7 @@ main () ...@@ -16,7 +16,7 @@ main ()
exec sql begin declare section; exec sql begin declare section;
intarray amount; intarray amount;
int increment=100; int increment=100;
char name[AMOUNT][6]; char name[AMOUNT][8];
char letter[AMOUNT][1]; char letter[AMOUNT][1];
char command[128]; char command[128];
exec sql end declare section; exec sql end declare section;
...@@ -35,8 +35,8 @@ exec sql end declare section; ...@@ -35,8 +35,8 @@ exec sql end declare section;
exec sql connect to pm; exec sql connect to pm;
strcpy(msg, "create"); strcpy(msg, "create");
exec sql at main create table test(name char(6), amount int, letter char(1)); exec sql at main create table test(name char(8), amount int, letter char(1));
exec sql create table test(name char(6), amount int, letter char(1)); exec sql create table test(name char(8), amount int, letter char(1));
strcpy(msg, "commit"); strcpy(msg, "commit");
exec sql at main commit; exec sql at main commit;
...@@ -46,13 +46,13 @@ exec sql end declare section; ...@@ -46,13 +46,13 @@ exec sql end declare section;
exec sql set connection to main; exec sql set connection to main;
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;
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;
strcpy(msg, "execute insert 2"); strcpy(msg, "execute insert 2");
sprintf(command, "insert into test(name, amount, letter) values ('db: pm', 1, 'f')"); sprintf(command, "insert into test(name, amount, letter) values ('db: ''pm''', 1, 'f')");
exec sql at pm execute immediate :command; exec sql at pm execute immediate :command;
strcpy(msg, "execute insert 3"); strcpy(msg, "execute insert 3");
...@@ -78,12 +78,12 @@ exec sql end declare section; ...@@ -78,12 +78,12 @@ exec sql end declare section;
exec sql select name, amount, letter into :name, :amount, :letter from test; exec sql select name, amount, letter into :name, :amount, :letter from test;
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
printf("name[%d]=%6.6s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]); printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
exec sql at pm select name, amount, letter into :name, :amount, :letter from test; exec sql at pm select name, amount, letter into :name, :amount, :letter from test;
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
printf("name[%d]=%6.6s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]); printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
strcpy(msg, "drop"); strcpy(msg, "drop");
exec sql drop table test; exec sql drop table test;
......
...@@ -18,7 +18,7 @@ exec sql begin declare section; ...@@ -18,7 +18,7 @@ exec sql begin declare section;
int children; int children;
int ind_children; int ind_children;
str *married = NULL; str *married = NULL;
char *testname="Petra"; char *wifesname="Petra";
char *query="select name, born, age, married, children from meskes where name = :var1"; char *query="select name, born, age, married, children from meskes where name = :var1";
exec sql end declare section; exec sql end declare section;
...@@ -38,7 +38,7 @@ exec sql end declare section; ...@@ -38,7 +38,7 @@ exec sql end declare section;
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);
strcpy(msg, "insert"); strcpy(msg, "insert");
exec sql insert into meskes(name, married, children) values ('Petra', '19900404', 3); 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, 33, '19900404', 3); exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 33, '19900404', 3);
exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8); exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8);
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 5); exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 5);
...@@ -78,7 +78,7 @@ exec sql end declare section; ...@@ -78,7 +78,7 @@ exec sql end declare section;
exec sql declare prep cursor for MM; exec sql declare prep cursor for MM;
strcpy(msg, "open"); strcpy(msg, "open");
exec sql open prep using :testname; exec sql open prep using :wifesname;
exec sql whenever not found do break; exec sql whenever not found do break;
......
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