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

Commit03842eb

Browse files
author
Michael Meskes
committed
*** empty log message ***
1 parent9db6b7f commit03842eb

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ register_error(long code, char *fmt,...)
113113
va_end(args);
114114
sqlca.sqlerrm.sqlerrml=strlen(sqlca.sqlerrm.sqlerrmc);
115115

116-
/* free all memory weallocate for the user */
116+
/* free all memory wehave allocated for the user */
117117
for (am=auto_allocs;am;)
118118
{
119119
structauto_mem*act=am;
@@ -178,7 +178,7 @@ ECPGfinish(struct connection * act)
178178
staticchar*
179179
ecpg_alloc(longsize,intlineno)
180180
{
181-
char*new= (char*)malloc(size);
181+
char*new= (char*)calloc(1L,size);
182182

183183
if (!new)
184184
{
@@ -344,7 +344,7 @@ create_statement(int lineno, struct connection *connection, struct statement **
344344
var->varcharsize=va_arg(ap,long);
345345
var->arrsize=va_arg(ap,long);
346346
var->offset=va_arg(ap,long);
347-
347+
348348
if (var->arrsize==0||var->varcharsize==0)
349349
var->value=*((void**)(var->pointer));
350350
else
@@ -710,6 +710,8 @@ ECPGexecute(struct statement * stmt)
710710
*/
711711
if (var->arrsize==0||var->varcharsize==0)
712712
{
713+
intlen=0;
714+
713715
switch(var->type)
714716
{
715717
caseECPGt_char:
@@ -720,38 +722,26 @@ ECPGexecute(struct statement * stmt)
720722
/* check strlen for each tuple */
721723
for (act_tuple=0;act_tuple<ntuples;act_tuple++)
722724
{
723-
intlen=strlen(PQgetvalue(results,act_tuple,act_field));
725+
intlen=strlen(PQgetvalue(results,act_tuple,act_field))+1;
724726

725727
if (len>var->varcharsize)
726728
var->varcharsize=len;
727729
}
728730
var->offset *=var->varcharsize;
729-
add_mem((void*)(var->value)=*((void**)(var->pointer))= (void*)ecpg_alloc(var->offset*ntuples,stmt->lineno),stmt->lineno);
731+
len=var->offset*ntuples;
730732
}
731733
break;
732-
#if0
733734
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-
}
735+
if (var->value==NULL)
736+
len=ntuples* (var->varcharsize+sizeof (int));
748737
break;
749-
#endif
750738
default:
751739
if (var->value==NULL)
752-
add_mem((void*)(var->value)=*((void**)(var->pointer))= (void*)ecpg_alloc(var->offset*ntuples,stmt->lineno),stmt->lineno);
740+
len=var->offset*ntuples;
753741
break;
754742
}
743+
744+
add_mem((void*)(var->value)=*((void**)(var->pointer))= (void*)ecpg_alloc(len,stmt->lineno),stmt->lineno);
755745
}
756746

757747
for (act_tuple=0;act_tuple<ntuples&&status;act_tuple++)

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
573573
*dimension = type_dimension;
574574
}
575575

576+
if (*length >=0 && *dimension >=0 && pointer)
577+
yyerror("No multi-dimensional array support");
578+
576579
switch (type_enum)
577580
{
578581
case ECPGt_struct:
@@ -589,9 +592,9 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
589592

590593
break;
591594
case ECPGt_varchar:
592-
/* pointer has to getlength 0*/
595+
/* pointer has to getdimension 0*/
593596
if (pointer)
594-
*length=0;
597+
*dimension =0;
595598

596599
/* one index is the string length*/
597600
if (*length <0)
@@ -3721,11 +3724,11 @@ a_expr: attr opt_indirection
37213724
}
37223725
|a_exprIN'('in_expr')'
37233726
{
3724-
$$ = make4_str($1, make1_str("in ("),$4, make1_str(")"));
3727+
$$ = make4_str($1, make1_str("in ("),$4, make1_str(")"));
37253728
}
37263729
|a_exprNOTIN'('not_in_expr')'
37273730
{
3728-
$$ = make4_str($1, make1_str("not in ("),$5, make1_str(")"));
3731+
$$ = make4_str($1, make1_str("not in ("),$5, make1_str(")"));
37293732
}
37303733
|a_exprOp'('SubSelect')'
37313734
{
@@ -4838,15 +4841,16 @@ type: simple_type
48384841
{
48394842
$$.type_str =$1;
48404843
$$.type_enum = ECPGt_int;
4841-
$$.type_dimension = -1;
4844+
4845+
$$.type_dimension = -1;
48424846
$$.type_index = -1;
48434847
}
48444848
|symbol
48454849
{
48464850
/* this is for typedef'ed types*/
48474851
structtypedefs *this = get_typedef($1);
48484852

4849-
$$.type_str = mm_strdup(this->name);
4853+
$$.type_str =(this->type->type_enum == ECPGt_varchar) ? make1_str("") :mm_strdup(this->name);
48504854
$$.type_enum =this->type->type_enum;
48514855
$$.type_dimension =this->type->type_dimension;
48524856
$$.type_index =this->type->type_index;
@@ -4945,8 +4949,6 @@ variable: opt_pointer symbol opt_array_bounds opt_initializer
49454949
switch(dimension)
49464950
{
49474951
case0:
4948-
strcpy(dim,"[]");
4949-
break;
49504952
case -1:
49514953
case1:
49524954
*dim ='\0';
@@ -4957,11 +4959,14 @@ variable: opt_pointer symbol opt_array_bounds opt_initializer
49574959
}
49584960
sprintf(ascii_len,"%d", length);
49594961

4960-
if (length >0)
4961-
$$ = make4_str(make5_str(mm_strdup(actual_storage[struct_level]), make1_str(" struct varchar_"), mm_strdup($2), make1_str(" { int len; char arr["), mm_strdup(ascii_len)), make1_str("]; }"), mm_strdup($2), mm_strdup(dim));
4962-
else
4963-
yyerror ("pointer to varchar are not implemented yet");
4964-
/* $$ = make4_str(make3_str(mm_strdup(actual_storage[struct_level]), make1_str(" struct varchar_"), mm_strdup($2)), make1_str(" { int len; char *arr; }"), mm_strdup($2), mm_strdup(dim));*/
4962+
if (length ==0)
4963+
yyerror ("pointer to varchar are not implemented");
4964+
4965+
if (dimension ==0)
4966+
$$ = make4_str(make5_str(mm_strdup(actual_storage[struct_level]), make1_str(" struct varchar_"), mm_strdup($2), make1_str(" { int len; char arr["), mm_strdup(ascii_len)), make1_str("]; } *"), mm_strdup($2),$4);
4967+
else
4968+
$$ = make5_str(make5_str(mm_strdup(actual_storage[struct_level]), make1_str(" struct varchar_"), mm_strdup($2), make1_str(" { int len; char arr["), mm_strdup(ascii_len)), make1_str("]; }"), mm_strdup($2), mm_strdup(dim),$4);
4969+
49654970
break;
49664971
case ECPGt_char:
49674972
case ECPGt_unsigned_char:

‎src/interfaces/ecpg/test/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all: test1 test2 perftest
1+
all: test1 test2test3perftest
22

33
LDFLAGS=-g -I /usr/local/pgsql/include -L/usr/local/pgsql/lib -lecpg -lpq -lcrypt
44

@@ -10,9 +10,13 @@ test2: test2.c
1010
test2.c: test2.pgc
1111
/usr/local/pgsql/bin/ecpg$?
1212

13+
test3: test3.c
14+
test3.c: test3.pgc
15+
/usr/local/pgsql/bin/ecpg$?
16+
1317
perftest: perftest.c
1418
perftest.c:perftest.pgc
1519
/usr/local/pgsql/bin/ecpg$?
1620

1721
clean:
18-
-/bin/rm test1 test2 perftest*.c log
22+
-/bin/rm test1 test2test3perftest*.c log

‎src/interfaces/ecpg/test/test2.pgc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ typedef char* c;
88
exec sql type ind is union { int integer; short smallint; };
99
typedef union { int integer; short smallint; } ind;
1010

11+
exec sql type str is varchar[8];
12+
1113
int
1214
main ()
1315
{
1416
typedef struct { long born; short age; } birthinfo;
1517
exec sql type birthinfo is struct { long born; short age; };
1618
exec sql begin declare section;
17-
struct personal_struct{varchar name[8];
19+
struct personal_struct{str name;
1820
birthinfo birth;
1921
} personal;
2022
struct personal_indicator {int ind_name;
2123
birthinfo ind_birth;
2224
} ind_personal;
23-
int ind_married;
25+
float ind_married;
2426
ind children;
2527
ind ind_children;
2628
char *married = NULL;
@@ -68,8 +70,8 @@ exec sql end declare section;
6870
printf(", born %d", personal.birth.born);
6971
if (ind_personal.ind_birth.age >= 0)
7072
printf(", age = %d", personal.birth.age);
71-
if (ind_married >= 0)
72-
printf(", married %10.10s", married);
73+
if ((long)ind_married >= 0)
74+
printf(", married %s", married);
7375
if (ind_children.smallint >= 0)
7476
printf(", children = %d", children.integer);
7577
putchar('\n');
@@ -98,8 +100,8 @@ exec sql end declare section;
98100
printf(", born %d", personal.birth.born);
99101
if (ind_personal.ind_birth.age >= 0)
100102
printf(", age = %d", personal.birth.age);
101-
if (ind_married >= 0)
102-
printf(", married %10.10s", married);
103+
if ((long)ind_married >= 0)
104+
printf(", married %s", married);
103105
if (ind_children.smallint >= 0)
104106
printf(", children = %d", children.integer);
105107
putchar('\n');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp