Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit35478b8

Browse files
committed
From: Michael Meskes <meskes@online-club.de>++ Fri Aug 14 12:44:21 CEST 1998++ - Added EXEC SQL DEFINE statement+ - Set version to 2.4.0++ Tue Aug 18 09:24:15 CEST 1998++ - Removed keyword IS from DEFINE statement+ - Added latest changes from gram.y+ - Removed duplicate symbols from preproc.y+ - Initialize sqlca structure+ - Added check for connection to ecpglib+ - Set version to 2.4.1++ Thu Aug 20 15:31:29 CEST 1998++ - Cleaned up memory allocation in ecpglib.c+ - Set library version to 2.6+
1 parent32cfc4a commit35478b8

File tree

7 files changed

+340
-187
lines changed

7 files changed

+340
-187
lines changed

‎src/interfaces/ecpg/lib/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include $(SRCDIR)/Makefile.global
44
PQ_INCLUDE=-I$(SRCDIR)/interfaces/libpq
55

66
SO_MAJOR_VERSION=2
7-
SO_MINOR_VERSION=5
7+
SO_MINOR_VERSION=6
88

99
PORTNAME=@PORTNAME@
1010

‎src/interfaces/ecpg/lib/ecpglib.c

Lines changed: 96 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,32 @@
2424
#include<ecpglib.h>
2525
#include<sqlca.h>
2626

27-
externintno_auto_trans;
27+
/* variables visible to the programs */
28+
intno_auto_trans;
29+
30+
staticstructsqlcasqlca_init=
31+
{
32+
{'S','Q','L','C','A',' ',' ',' '},
33+
sizeof(structsqlca),
34+
0,
35+
{0, {0}},
36+
{'N','O','T',' ','S','E','T',' '},
37+
{0,0,0,0,0,0},
38+
{0,0,0,0,0,0,0,0},
39+
{0,0,0,0,0,0,0,0}
40+
};
41+
42+
structsqlcasqlca=
43+
{
44+
{'S','Q','L','C','A',' ',' ',' '},
45+
sizeof(structsqlca),
46+
0,
47+
{0, {0}},
48+
{'N','O','T',' ','S','E','T',' '},
49+
{0,0,0,0,0,0},
50+
{0,0,0,0,0,0,0,0},
51+
{0,0,0,0,0,0,0,0}
52+
};
2853

2954
staticstructconnection
3055
{
@@ -72,39 +97,6 @@ register_error(long code, char *fmt,...)
7297
sqlca.sqlerrm.sqlerrml=strlen(sqlca.sqlerrm.sqlerrmc);
7398
}
7499

75-
/* This function returns a newly malloced string that has the ' and \
76-
in the argument quoted with \.
77-
*/
78-
static
79-
char*
80-
quote_postgres(char*arg)
81-
{
82-
char*res= (char*)malloc(2*strlen(arg)+1);
83-
inti,
84-
ri;
85-
86-
if (!res)
87-
return(res);
88-
89-
for (i=0,ri=0;arg[i];i++,ri++)
90-
{
91-
switch (arg[i])
92-
{
93-
case'\'':
94-
case'\\':
95-
res[ri++]='\\';
96-
default:
97-
;
98-
}
99-
100-
res[ri]=arg[i];
101-
}
102-
res[ri]='\0';
103-
104-
returnres;
105-
}
106-
107-
108100
staticvoid
109101
ECPGfinish(structconnection*act)
110102
{
@@ -139,22 +131,63 @@ ECPGfinish(struct connection *act)
139131
ECPGlog("ECPGfinish: called an extra time.\n");
140132
}
141133

134+
staticchar*ecpg_alloc(longsize,intlineno)
135+
{
136+
char*new= (char*)malloc(size);
137+
138+
if (!new)
139+
{
140+
ECPGfinish(actual_connection);
141+
ECPGlog("out of memory\n");
142+
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",lineno);
143+
returnNULL;
144+
}
145+
146+
memset(new,'\0',size);
147+
return(new);
148+
}
149+
150+
/* This function returns a newly malloced string that has the ' and \
151+
in the argument quoted with \.
152+
*/
153+
static
154+
char*
155+
quote_postgres(char*arg,intlineno)
156+
{
157+
char*res= (char*)ecpg_alloc(2*strlen(arg)+1,lineno);
158+
inti,
159+
ri;
160+
161+
if (!res)
162+
return(res);
163+
164+
for (i=0,ri=0;arg[i];i++,ri++)
165+
{
166+
switch (arg[i])
167+
{
168+
case'\'':
169+
case'\\':
170+
res[ri++]='\\';
171+
default:
172+
;
173+
}
174+
175+
res[ri]=arg[i];
176+
}
177+
res[ri]='\0';
178+
179+
returnres;
180+
}
181+
142182
/* create a list of variables */
143183
staticbool
144184
create_statement(intlineno,structstatement**stmt,char*query,va_listap)
145185
{
146186
structvariable**list=&((*stmt)->inlist);
147187
enumECPGttypetype;
148188

149-
*stmt=calloc(sizeof(structstatement),1);
150-
151-
if (!*stmt)
152-
{
153-
ECPGfinish(actual_connection);
154-
ECPGlog("out of memory\n");
155-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",lineno);
156-
return false;
157-
}
189+
if (!(*stmt= (structstatement*)ecpg_alloc(sizeof(structstatement),lineno)))
190+
return false;
158191

159192
(*stmt)->command=query;
160193
(*stmt)->lineno=lineno;
@@ -173,14 +206,8 @@ create_statement(int lineno, struct statement **stmt, char *query, va_list ap)
173206
{
174207
structvariable*var,*ptr;
175208

176-
var=malloc(sizeof(structvariable));
177-
if (!var)
178-
{
179-
ECPGfinish(actual_connection);
180-
ECPGlog("out of memory\n");
181-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",lineno);
209+
if (!(var= (structvariable*)ecpg_alloc(sizeof(structvariable),lineno)))
182210
return false;
183-
}
184211

185212
var->type=type;
186213
var->value=va_arg(ap,void*);
@@ -217,8 +244,8 @@ ECPGexecute(struct statement *stmt)
217244
PGnotify*notify;
218245
structvariable*var;
219246

220-
memset((char*)&sqlca,0,sizeof(sqlca));
221-
247+
memcpy((char*)&sqlca,(char*)&sqlca_init,sizeof(sqlca));
248+
222249
copiedquery=strdup(stmt->command);
223250

224251
/*
@@ -314,36 +341,19 @@ ECPGexecute(struct statement *stmt)
314341
intslen= (var->varcharsize==0) ?strlen((char*)var->value) :var->varcharsize;
315342
char*tmp;
316343

317-
newcopy= (char*)malloc(slen+1);
318-
if (!newcopy)
319-
{
320-
ECPGfinish(actual_connection);
321-
ECPGlog("out of memory\n");
322-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",stmt->lineno);
344+
if (!(newcopy=ecpg_alloc(slen+1,stmt->lineno)))
323345
return false;
324-
}
325346

326347
strncpy(newcopy, (char*)var->value,slen);
327348
newcopy[slen]='\0';
328349

329-
mallocedval= (char*)malloc(2*strlen(newcopy)+3);
330-
if (!mallocedval)
331-
{
332-
ECPGfinish(actual_connection);
333-
ECPGlog("out of memory\n");
334-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",stmt->lineno);
350+
if (!(mallocedval= (char*)ecpg_alloc(2*strlen(newcopy)+3,stmt->lineno)))
335351
return false;
336-
}
337352

338353
strcpy(mallocedval,"'");
339-
tmp=quote_postgres(newcopy);
354+
tmp=quote_postgres(newcopy,stmt->lineno);
340355
if (!tmp)
341-
{
342-
ECPGfinish(actual_connection);
343-
ECPGlog("out of memory\n");
344-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",stmt->lineno);
345356
return false;
346-
}
347357

348358
strcat(mallocedval,tmp);
349359
strcat(mallocedval,"'");
@@ -360,36 +370,19 @@ ECPGexecute(struct statement *stmt)
360370
(structECPGgeneric_varchar*) (var->value);
361371
char*tmp;
362372

363-
newcopy= (char*)malloc(variable->len+1);
364-
if (!newcopy)
365-
{
366-
ECPGfinish(actual_connection);
367-
ECPGlog("out of memory\n");
368-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",stmt->lineno);
373+
if (!(newcopy= (char*)ecpg_alloc(variable->len+1,stmt->lineno)))
369374
return false;
370-
}
371375

372376
strncpy(newcopy,variable->arr,variable->len);
373377
newcopy[variable->len]='\0';
374378

375-
mallocedval= (char*)malloc(2*strlen(newcopy)+3);
376-
if (!mallocedval)
377-
{
378-
ECPGfinish(actual_connection);
379-
ECPGlog("out of memory\n");
380-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",stmt->lineno);
379+
if (!(mallocedval= (char*)ecpg_alloc(2*strlen(newcopy)+3,stmt->lineno)))
381380
return false;
382-
}
383381

384382
strcpy(mallocedval,"'");
385-
tmp=quote_postgres(newcopy);
383+
tmp=quote_postgres(newcopy,stmt->lineno);
386384
if (!tmp)
387-
{
388-
ECPGfinish(actual_connection);
389-
ECPGlog("out of memory\n");
390-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",stmt->lineno);
391385
return false;
392-
}
393386

394387
strcat(mallocedval,tmp);
395388
strcat(mallocedval,"'");
@@ -415,16 +408,8 @@ ECPGexecute(struct statement *stmt)
415408
* Now tobeinserted points to an area that is to be inserted at
416409
* the first %s
417410
*/
418-
newcopy= (char*)malloc(strlen(copiedquery)
419-
+strlen(tobeinserted)
420-
+1);
421-
if (!newcopy)
422-
{
423-
ECPGfinish(actual_connection);
424-
ECPGlog("out of memory\n");
425-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",stmt->lineno);
411+
if (!(newcopy= (char*)ecpg_alloc(strlen(copiedquery)+strlen(tobeinserted)+1,stmt->lineno)))
426412
return false;
427-
}
428413

429414
strcpy(newcopy,copiedquery);
430415
if ((p=strstr(newcopy,";;"))==NULL)
@@ -857,7 +842,15 @@ ECPGdo(int lineno, char *query, ...)
857842
if (create_statement(lineno,&stmt,query,args)== false)
858843
return(false);
859844
va_end(args);
860-
845+
846+
/* are we connected? */
847+
if (actual_connection==NULL||actual_connection->connection==NULL)
848+
{
849+
ECPGlog("ECPGdo: not connected\n");
850+
register_error(ECPG_NOT_CONN,"Not connected in line %d",lineno);
851+
return false;
852+
}
853+
861854
return(ECPGexecute(stmt));
862855
}
863856

@@ -902,14 +895,10 @@ ECPGsetconn(int lineno, const char *connection_name)
902895
bool
903896
ECPGconnect(intlineno,constchar*dbname,constchar*user,constchar*passwd,constchar*connection_name)
904897
{
905-
structconnection*this=malloc(sizeof(structconnection));
898+
structconnection*this=(structconnection*)ecpg_alloc(sizeof(structconnection),lineno);
906899

907900
if (!this)
908-
{
909-
ECPGlog("out of memory\n");
910-
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",lineno);
911901
return false;
912-
}
913902

914903
if (dbname==NULL&&connection_name==NULL)
915904
connection_name="DEFAULT";
@@ -937,7 +926,6 @@ ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd
937926
{
938927
ECPGfinish(this);
939928
ECPGlog("connect: could not open database %s %s%s in line %d\n",dbname ?dbname :"NULL",user ?"for user ":"",user ?user :"",lineno);
940-
941929
register_error(ECPG_CONNECT,"connect: could not open database %s.",dbname ?dbname :"NULL");
942930
return false;
943931
}

‎src/interfaces/ecpg/preproc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ SRCDIR= ../../..
22
include$(SRCDIR)/Makefile.global
33

44
MAJOR_VERSION=2
5-
MINOR_VERSION=3
6-
PATCHLEVEL=5
5+
MINOR_VERSION=4
6+
PATCHLEVEL=1
77

88
CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION)\
99
-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL)\

‎src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern char *optarg;
2222
#include"extern.h"
2323

2424
struct_include_path*include_paths;
25-
staticintno_auto_trans=0;
25+
intno_auto_trans=0;
2626
structcursor*cur=NULL;
2727

2828
staticvoid
@@ -138,10 +138,12 @@ main(int argc, char *const argv[])
138138
else
139139
{
140140
structcursor*ptr;
141+
struct_defines*defptr;
141142

142143
/* remove old cursor definitions if any are still there */
143-
for (ptr=cur;ptr!=NULL;ptr=ptr->next)
144+
for (ptr=cur;ptr!=NULL;)
144145
{
146+
structcursor*this=ptr;
145147
structarguments*l1,*l2;
146148

147149
free(ptr->command);
@@ -156,12 +158,25 @@ main(int argc, char *const argv[])
156158
l2=l1->next;
157159
free(l1);
158160
}
161+
ptr=ptr->next;
162+
free(this);
159163
}
164+
165+
/* remove old defines as well */
166+
for (defptr=defines;defptr!=NULL;)
167+
{
168+
struct_defines*this=defptr;
169+
free(defptr->new);
170+
free(defptr->old);
171+
defptr=defptr->next;
172+
free(this);
173+
}
174+
160175
/* initialize lex */
161176
lex_init();
162177

163178
/* we need two includes and a constant */
164-
fprintf(yyout,"/* Processed by ecpg (%d.%d.%d) */\n/*These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n\nconst int no_auto_trans = %d;\n\n",MAJOR_VERSION,MINOR_VERSION,PATCHLEVEL,no_auto_trans);
179+
fprintf(yyout,"/* Processed by ecpg (%d.%d.%d) */\n/*These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n\n",MAJOR_VERSION,MINOR_VERSION,PATCHLEVEL);
165180

166181
/* and parse the source */
167182
yyparse();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp