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

Commitd077c61

Browse files
committed
From: Michael Meskes <Michael_Meskes@topmail.de>++ Tue Feb 23 17:32:25 CET 1999++ - Other than a struct a union itself cannot be specified as variable.++ Fri Feb 26 07:18:25 CET 1999++ - Synced preproc.y with gram.y.++ Sat Feb 27 20:30:03 CET 1999++ - Added automatic allocating for NULL pointers.
1 parent51f0f6d commitd077c61

File tree

12 files changed

+19942
-244
lines changed

12 files changed

+19942
-244
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,5 +475,17 @@ Mon Feb 22 19:47:45 CET 1999
475475
requires me to increase the major version number.
476476
- Synced pgc.l with scan.l.
477477
- Added support for unions.
478+
479+
Tue Feb 23 17:32:25 CET 1999
480+
481+
- Other than a struct a union itself cannot be specified as variable.
482+
483+
Fri Feb 26 07:18:25 CET 1999
484+
485+
- Synced preproc.y with gram.y.
486+
487+
Sat Feb 27 20:30:03 CET 1999
488+
489+
- Added automatic allocating for NULL pointers.
478490
- Set library version to 3.0.0
479491
- Set ecpg version to 3.0.0

‎src/interfaces/ecpg/TODO

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ DESCRIPTOR statement will be ignored.
1111

1212
it would be nice to be able to use :var[:index] as cvariable
1313

14-
support for dynamic SQL with unknown number of variables with SQLDA structure
14+
it would also be nice to be able to work with varchar * (inculding automatic
15+
allocating)
1516

16-
allocate memory for pointers as C input variables
17+
support for dynamic SQL with unknown number of variables with SQLDA structure
18+
or something similar
1719

1820
Missing statements:
1921
- exec sql allocate

‎src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern"C"
4343
ECPGt_varchar,ECPGt_varchar2,
4444
ECPGt_array,
4545
ECPGt_struct,
46+
ECPGt_union,
4647
ECPGt_char_variable,
4748
ECPGt_EOIT,/* End of insert types. */
4849
ECPGt_EORT,/* End of result types. */

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

Lines changed: 123 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct variable
6464
{
6565
enumECPGttypetype;
6666
void*value;
67+
void*pointer;
6768
longvarcharsize;
6869
longarrsize;
6970
longoffset;
@@ -91,19 +92,38 @@ struct prepared_statement
9192
structprepared_statement*next;
9293
}*prep_stmts=NULL;
9394

95+
structauto_mem
96+
{
97+
void*pointer;
98+
structauto_mem*next;
99+
}*auto_allocs=NULL;
100+
94101
staticintsimple_debug=0;
95102
staticFILE*debugstream=NULL;
96103

97104
staticvoid
98105
register_error(longcode,char*fmt,...)
99106
{
100107
va_listargs;
101-
108+
structauto_mem*am;
109+
102110
sqlca.sqlcode=code;
103111
va_start(args,fmt);
104112
vsprintf(sqlca.sqlerrm.sqlerrmc,fmt,args);
105113
va_end(args);
106114
sqlca.sqlerrm.sqlerrml=strlen(sqlca.sqlerrm.sqlerrmc);
115+
116+
/* free all memory we allocate for the user */
117+
for (am=auto_allocs;am;)
118+
{
119+
structauto_mem*act=am;
120+
121+
am=am->next;
122+
free(act->pointer);
123+
free(act);
124+
}
125+
126+
auto_allocs=NULL;
107127
}
108128

109129
staticstructconnection*
@@ -166,7 +186,7 @@ ecpg_alloc(long size, int lineno)
166186
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",lineno);
167187
returnNULL;
168188
}
169-
189+
170190
memset(new,'\0',size);
171191
return (new);
172192
}
@@ -186,6 +206,15 @@ ecpg_strdup(const char *string, int lineno)
186206
return (new);
187207
}
188208

209+
staticvoid
210+
add_mem(void*ptr,intlineno)
211+
{
212+
structauto_mem*am= (structauto_mem*)ecpg_alloc(sizeof(structauto_mem),lineno);
213+
214+
am->next=auto_allocs;
215+
auto_allocs=am;
216+
}
217+
189218
/* This function returns a newly malloced string that has the ' and \
190219
in the argument quoted with \.
191220
*/
@@ -301,26 +330,33 @@ create_statement(int lineno, struct connection *connection, struct statement **
301330
return false;
302331

303332
var->type=type;
304-
var->value=va_arg(ap,void*);
333+
var->pointer=va_arg(ap,void*);
334+
335+
/* if variable is NULL, the statement hasn't been prepared */
336+
if (var->pointer==NULL)
337+
{
338+
ECPGlog("create_statement: invalid statement name\n");
339+
register_error(ECPG_INVALID_STMT,"Invalid statement name in line %d",lineno);
340+
free(var);
341+
return false;
342+
}
343+
305344
var->varcharsize=va_arg(ap,long);
306345
var->arrsize=va_arg(ap,long);
307346
var->offset=va_arg(ap,long);
347+
348+
if (var->arrsize==0||var->varcharsize==0)
349+
var->value=*((void**)(var->pointer));
350+
else
351+
var->value=var->pointer;
352+
308353
var->ind_type=va_arg(ap,enumECPGttype);
309354
var->ind_value=va_arg(ap,void*);
310355
var->ind_varcharsize=va_arg(ap,long);
311356
var->ind_arrsize=va_arg(ap,long);
312357
var->ind_offset=va_arg(ap,long);
313358
var->next=NULL;
314359

315-
/* if variable is NULL, the statement hasn't been prepared */
316-
if (var->value==NULL)
317-
{
318-
ECPGlog("create_statement: invalid statement name\n");
319-
register_error(ECPG_INVALID_STMT,"Invalid statement name in line %d",lineno);
320-
free(var);
321-
return false;
322-
}
323-
324360
for (ptr=*list;ptr&&ptr->next;ptr=ptr->next);
325361

326362
if (ptr==NULL)
@@ -478,8 +514,7 @@ ECPGexecute(struct statement * stmt)
478514
break;
479515
caseECPGt_char_variable:
480516
{
481-
/* set slen to string length if type is char * */
482-
intslen= (var->varcharsize==0) ?strlen((char*)var->value) :var->varcharsize;
517+
intslen=strlen((char*)var->value);
483518
char*tmp;
484519

485520
if (!(newcopy=ecpg_alloc(slen+1,stmt->lineno)))
@@ -632,13 +667,6 @@ ECPGexecute(struct statement * stmt)
632667
act_field;
633668

634669
casePGRES_TUPLES_OK:
635-
636-
/*
637-
* XXX Cheap Hack. For now, we see only the last group of
638-
* tuples.This is clearly not the right way to do things
639-
* !!
640-
*/
641-
642670
nfields=PQnfields(results);
643671
sqlca.sqlerrd[2]=ntuples=PQntuples(results);
644672
status= true;
@@ -676,18 +704,67 @@ ECPGexecute(struct statement * stmt)
676704
status= false;
677705
break;
678706
}
679-
680-
for (act_tuple=0;act_tuple<ntuples;act_tuple++)
707+
708+
/*
709+
* allocate memory for NULL pointers
710+
*/
711+
if (var->arrsize==0||var->varcharsize==0)
712+
{
713+
switch(var->type)
714+
{
715+
caseECPGt_char:
716+
caseECPGt_unsigned_char:
717+
if (var->value==NULL)
718+
{
719+
var->varcharsize=0;
720+
/* check strlen for each tuple */
721+
for (act_tuple=0;act_tuple<ntuples;act_tuple++)
722+
{
723+
intlen=strlen(PQgetvalue(results,act_tuple,act_field));
724+
725+
if (len>var->varcharsize)
726+
var->varcharsize=len;
727+
}
728+
var->offset *=var->varcharsize;
729+
add_mem((void*)(var->value)=*((void**)(var->pointer))= (void*)ecpg_alloc(var->offset*ntuples,stmt->lineno),stmt->lineno);
730+
}
731+
break;
732+
#if0
733+
caseECPGt_varchar:
734+
if (((structECPGgeneric_varchar*)var->value)->arr==NULL)
735+
{
736+
var->varcharsize=0;
737+
/* check strlen for each tuple */
738+
for (act_tuple=0;act_tuple<ntuples;act_tuple++)
739+
{
740+
intlen=strlen(PQgetvalue(results,act_tuple,act_field));
741+
742+
if (len>var->varcharsize)
743+
var->varcharsize=len;
744+
745+
((structECPGgeneric_varchar*) ((long)var->value+var->offset*act_tuple))->arr= (char*)ecpg_alloc(len,stmt->lineno);
746+
}
747+
}
748+
break;
749+
#endif
750+
default:
751+
if (var->value==NULL)
752+
add_mem((void*)(var->value)=*((void**)(var->pointer))= (void*)ecpg_alloc(var->offset*ntuples,stmt->lineno),stmt->lineno);
753+
break;
754+
}
755+
}
756+
757+
for (act_tuple=0;act_tuple<ntuples&&status;act_tuple++)
681758
{
682759
pval=PQgetvalue(results,act_tuple,act_field);
683760

684761
ECPGlog("ECPGexecute line %d: RESULT: %s\n",stmt->lineno,pval ?pval :"");
685762

686-
/* Now the pval is a pointer to thevar->value. */
687-
/* We will have to decode thevar->value */
763+
/* Now the pval is a pointer to the value. */
764+
/* We will have to decode the value */
688765

689766
/*
690-
* check for nullvar->value and set indicator
767+
* check for null value and set indicator
691768
* accordingly
692769
*/
693770
switch (var->ind_type)
@@ -840,37 +917,28 @@ ECPGexecute(struct statement * stmt)
840917
caseECPGt_char:
841918
caseECPGt_unsigned_char:
842919
{
843-
if (var->varcharsize==0)
920+
strncpy((char*) ((long)var->value+var->offset*act_tuple),pval,var->varcharsize);
921+
if (var->varcharsize&&var->varcharsize<strlen(pval))
844922
{
845-
/* char* */
846-
strncpy(((char**)var->value)[act_tuple],pval,strlen(pval));
847-
(((char**)var->value)[act_tuple])[strlen(pval)]='\0';
848-
}
849-
else
850-
{
851-
strncpy((char*) ((long)var->value+var->offset*act_tuple),pval,var->varcharsize);
852-
if (var->varcharsize<strlen(pval))
923+
/* truncation */
924+
switch (var->ind_type)
853925
{
854-
/* truncation */
855-
switch (var->ind_type)
856-
{
857-
caseECPGt_short:
858-
caseECPGt_unsigned_short:
859-
((short*)var->ind_value)[act_tuple]=var->varcharsize;
860-
break;
861-
caseECPGt_int:
862-
caseECPGt_unsigned_int:
863-
((int*)var->ind_value)[act_tuple]=var->varcharsize;
864-
break;
865-
caseECPGt_long:
866-
caseECPGt_unsigned_long:
867-
((long*)var->ind_value)[act_tuple]=var->varcharsize;
868-
break;
869-
default:
870-
break;
871-
}
872-
sqlca.sqlwarn[0]=sqlca.sqlwarn[1]='W';
926+
caseECPGt_short:
927+
caseECPGt_unsigned_short:
928+
((short*)var->ind_value)[act_tuple]=var->varcharsize;
929+
break;
930+
caseECPGt_int:
931+
caseECPGt_unsigned_int:
932+
((int*)var->ind_value)[act_tuple]=var->varcharsize;
933+
break;
934+
caseECPGt_long:
935+
caseECPGt_unsigned_long:
936+
((long*)var->ind_value)[act_tuple]=var->varcharsize;
937+
break;
938+
default:
939+
break;
873940
}
941+
sqlca.sqlwarn[0]=sqlca.sqlwarn[1]='W';
874942
}
875943
}
876944
break;
@@ -914,8 +982,7 @@ ECPGexecute(struct statement * stmt)
914982
break;
915983

916984
default:
917-
register_error(ECPG_UNSUPPORTED,"Unsupported type %s on line %d.",
918-
ECPGtype_name(var->type),stmt->lineno);
985+
register_error(ECPG_UNSUPPORTED,"Unsupported type %s on line %d.",ECPGtype_name(var->type),stmt->lineno);
919986
status= false;
920987
break;
921988
}

‎src/interfaces/ecpg/preproc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ preproc.c preproc.h: preproc.y
2020
mv y.tab.h preproc.h
2121

2222
clean:
23-
rm -f*.o core a.out ecpg$(X)*~
23+
rm -f*.o core a.out ecpg$(X)*~*.output*.tab.?
2424

2525
install: all
2626
$(INSTALL)$(INSTL_EXE_OPTS) ecpg$(X)$(DESTDIR)$(BINDIR)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp