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

Commit073f731

Browse files
author
Michael Meskes
committed
- Fixed indicator in SET DESCRIPTOR.
- Added special handling of descriptor header information.- Some code cleanup.
1 parentda09dea commit073f731

File tree

7 files changed

+132
-33
lines changed

7 files changed

+132
-33
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,13 @@ Wed Jun 30 16:56:32 CEST 2004
18341834
Sun Jul 4 16:53:53 CEST 2004
18351835

18361836
- Made sure SET DESCRIPTOR accepts all data types including constants.
1837+
- Some code cleanup.
1838+
1839+
Mon, 5 Jul 2004 10:41:54 +0200
1840+
1841+
- Fixed indicator in SET DESCRIPTOR.
1842+
- Added special handling of descriptor header information.
1843+
- More code cleanup.
18371844
- Set pgtypes library version to 1.2.
18381845
- Set ecpg version to 3.2.0.
18391846
- Set compat library version to 1.2.

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* dynamic SQL support routines
22
*
3-
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.10 2004/07/04 15:02:22 meskes Exp $
3+
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.11 2004/07/05 09:45:53 meskes Exp $
44
*/
55

66
#definePOSTGRES_ECPG_INTERNAL
@@ -430,6 +430,27 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
430430
return (true);
431431
}
432432

433+
bool
434+
ECPGset_desc_header(intlineno,char*desc_name,intcount)
435+
{
436+
structdescriptor*desc;
437+
438+
for (desc=all_descriptors;desc;desc=desc->next)
439+
{
440+
if (strcmp(desc_name,desc->name)==0)
441+
break;
442+
}
443+
444+
if (desc==NULL)
445+
{
446+
ECPGraise(lineno,ECPG_UNKNOWN_DESCRIPTOR,ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME,desc_name);
447+
return false;
448+
}
449+
450+
desc->count=count;
451+
return true;
452+
}
453+
433454
bool
434455
ECPGset_desc(intlineno,char*desc_name,intindex,...)
435456
{
@@ -581,6 +602,7 @@ ECPGallocate_desc(int line, const char *name)
581602
ECPGfree(new);
582603
return false;
583604
}
605+
new->count=-1;
584606
new->items=NULL;
585607
new->result=PQmakeEmptyPGresult(NULL,0);
586608
if (!new->result)

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

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.36 2004/07/04 15:02:22 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.37 2004/07/05 09:45:53 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -1080,6 +1080,7 @@ ECPGexecute(struct statement * stmt)
10801080
inthostvarl=0;
10811081

10821082
tobeinserted=NULL;
1083+
10831084
/* A descriptor is a special case since it contains many variables but is listed only once. */
10841085
if (var->type==ECPGt_descriptor)
10851086
{
@@ -1100,35 +1101,51 @@ ECPGexecute(struct statement * stmt)
11001101
}
11011102

11021103
desc_counter++;
1103-
for (desc_item=desc->items;desc_item;desc_item=desc_item->next)
1104+
if (desc->count<0||desc->count >=desc_counter)
11041105
{
1105-
if (desc_item->num==desc_counter)
1106+
for (desc_item=desc->items;desc_item;desc_item=desc_item->next)
11061107
{
1107-
desc_inlist.type=ECPGt_char;
1108-
desc_inlist.value=desc_item->data;
1109-
desc_inlist.pointer=&(desc_item->data);
1110-
desc_inlist.varcharsize=strlen(desc_item->data);
1111-
desc_inlist.arrsize=1;
1112-
desc_inlist.offset=0;
1113-
desc_inlist.ind_type=ECPGt_NO_INDICATOR;
1114-
desc_inlist.ind_value=desc_inlist.ind_pointer=NULL;
1115-
desc_inlist.ind_varcharsize=desc_inlist.ind_arrsize=desc_inlist.ind_offset=0;
1116-
1117-
if (!ECPGstore_input(stmt->lineno,stmt->force_indicator,&desc_inlist,&tobeinserted,&malloced))
1118-
return false;
1119-
1120-
break;
1108+
if (desc_item->num==desc_counter)
1109+
{
1110+
desc_inlist.type=ECPGt_char;
1111+
desc_inlist.value=desc_item->data;
1112+
desc_inlist.pointer=&(desc_item->data);
1113+
desc_inlist.varcharsize=strlen(desc_item->data);
1114+
desc_inlist.arrsize=1;
1115+
desc_inlist.offset=0;
1116+
if (!desc_item->indicator)
1117+
{
1118+
desc_inlist.ind_type=ECPGt_NO_INDICATOR;
1119+
desc_inlist.ind_value=desc_inlist.ind_pointer=NULL;
1120+
desc_inlist.ind_varcharsize=desc_inlist.ind_arrsize=desc_inlist.ind_offset=0;
1121+
}
1122+
else
1123+
{
1124+
desc_inlist.ind_type=ECPGt_int;
1125+
desc_inlist.ind_value=&(desc_item->indicator);
1126+
desc_inlist.ind_pointer=&(desc_inlist.ind_value);
1127+
desc_inlist.ind_varcharsize=desc_inlist.ind_arrsize=1;
1128+
desc_inlist.ind_offset=0;
1129+
}
1130+
if (!ECPGstore_input(stmt->lineno,stmt->force_indicator,&desc_inlist,&tobeinserted,&malloced))
1131+
return false;
1132+
1133+
break;
1134+
}
11211135
}
1122-
}
11231136

1124-
if (!desc_item)/* no more entries found in descriptor */
1137+
if (!desc_item)/* no more entries found in descriptor */
1138+
desc_counter=0;
1139+
}
1140+
else
11251141
desc_counter=0;
11261142
}
11271143
else
11281144
{
11291145
if (!ECPGstore_input(stmt->lineno,stmt->force_indicator,var,&tobeinserted,&malloced))
11301146
return false;
11311147
}
1148+
11321149
if (tobeinserted)
11331150
{
11341151
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ voidECPGraise(int line, int code, const char *sqlstate, const char *str);
7777
voidECPGraise_backend(intline,PGresult*result,PGconn*conn,intcompat);
7878
boolECPGget_desc_header(int,char*,int*);
7979
boolECPGget_desc(int,char*,int,...);
80-
boolECPGset_desc_header(int,char*,int*);
80+
boolECPGset_desc_header(int,char*,int);
8181
boolECPGset_desc(int,char*,int,...);
8282

8383
voidECPGset_noind_null(enumECPGttype,void*);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ECPGnumeric_lvalue(FILE *f, char *name)
5555
caseECPGt_unsigned_int:
5656
caseECPGt_unsigned_long:
5757
caseECPGt_unsigned_long_long:
58+
caseECPGt_const:
5859
fputs(name,yyout);
5960
break;
6061
default:
@@ -198,7 +199,7 @@ output_set_descr_header(char *desc_name)
198199
{
199200
structassignment*results;
200201

201-
fprintf(yyout,"{ ECPGset_desc_header(__LINE__, %s,&(",desc_name);
202+
fprintf(yyout,"{ ECPGset_desc_header(__LINE__, %s,(int)(",desc_name);
202203
for (results=assignments;results!=NULL;results=results->next)
203204
{
204205
if (results->value==ECPGd_count)

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.291 2004/07/04 15:02:23 meskes Exp $*/
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.292 2004/07/05 09:45:53 meskes Exp $*/
22

33
/* Copyright comment*/
44
%{
@@ -522,7 +522,7 @@ add_additional_variables(char *name, bool insert)
522522
%type<str>select_limitopt_for_update_clauseCheckPointStmt
523523
%type<str>OptSchemaNameOptSchemaEltListschema_stmtopt_drop_behavior
524524
%type<str>handler_nameany_name_listany_nameopt_asinsert_column_list
525-
%type<str>columnreffunction_nameinsert_target_el
525+
%type<str>columnreffunction_nameinsert_target_elAllConstVar
526526
%type<str>insert_target_listinsert_column_itemDropRuleStmt
527527
%type<str>createfunc_opt_itemset_restvar_list_or_default
528528
%type<str>CreateFunctionStmtcreatefunc_opt_listfunc_table
@@ -4207,14 +4207,53 @@ IntConst:PosIntConst{ $$ = $1; }
42074207
IntConstVar:Iconst
42084208
{
42094209
char *length = mm_alloc(32);
4210-
4210+
42114211
sprintf(length,"%d", (int) strlen($1));
42124212
new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0);
42134213
$$ =$1;
42144214
}
42154215
|cvariable{$$ =$1; }
42164216
;
42174217

4218+
AllConstVar:Fconst
4219+
{
4220+
char *length = mm_alloc(32);
4221+
4222+
sprintf(length,"%d", (int) strlen($1));
4223+
new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0);
4224+
$$ =$1;
4225+
}
4226+
|IntConstVar{$$ =$1; }
4227+
|'-'Fconst
4228+
{
4229+
char *length = mm_alloc(32);
4230+
char *var = cat2_str(make_str("-"),$2);
4231+
4232+
sprintf(length,"%d", (int) strlen(var));
4233+
new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
4234+
$$ = var;
4235+
}
4236+
|'-'Iconst
4237+
{
4238+
char *length = mm_alloc(32);
4239+
char *var = cat2_str(make_str("-"),$2);
4240+
4241+
sprintf(length,"%d", (int) strlen(var));
4242+
new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
4243+
$$ = var;
4244+
}
4245+
|Sconst
4246+
{
4247+
char *length = mm_alloc(32);
4248+
char *var =$1 +1;
4249+
4250+
var[strlen(var) -1] ='\0';
4251+
sprintf(length,"%d", (int) strlen(var));
4252+
new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
4253+
$$ = var;
4254+
}
4255+
;
4256+
42184257
StringConst:Sconst{$$ =$1; }
42194258
|civar{$$ =$1; }
42204259
;
@@ -5375,7 +5414,7 @@ ECPGSetDescItems: ECPGSetDescItem
53755414
|ECPGSetDescItems','ECPGSetDescItem
53765415
;
53775416

5378-
ECPGSetDescItem:descriptor_item'='IntConstVar
5417+
ECPGSetDescItem:descriptor_item'='AllConstVar
53795418
{
53805419
push_assignment($3, $1);
53815420
}

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ main()
66
EXEC SQL BEGIN DECLARE SECTION;
77
char *stmt1 = "INSERT INTO test1 VALUES (?, ?)";
88
char *stmt2 = "SELECT * from test1 where a = ? and b = ?";
9+
char *stmt3 = "SELECT * from test1 where a = ?";
910

1011
int val1 = 1;
1112
char val2[] = "one", val2output[] = "AAA";
1213
int val1output = 2, val2i = 0;
13-
int val2null = 1;
14+
int val2null =-1;
1415
EXEC SQL END DECLARE SECTION;
1516
FILE *dbgs;
1617

@@ -28,6 +29,7 @@ main()
2829
EXEC SQL CREATE TABLE test1 (a int, b text);
2930
EXEC SQL PREPARE foo1 FROM :stmt1;
3031
EXEC SQL PREPARE foo2 FROM :stmt2;
32+
EXEC SQL PREPARE foo3 FROM :stmt3;
3133

3234
EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc;
3335

@@ -44,16 +46,27 @@ main()
4446
EXEC SQL GET DESCRIPTOR outdesc VALUE 1 :val2output = DATA;
4547
printf("output = %s\n", val2output);
4648

47-
EXEC SQL DECLAREc CURSOR FOR foo2;
48-
EXEC SQL OPENc USING DESCRIPTOR indesc;
49+
EXEC SQL DECLAREc1 CURSOR FOR foo2;
50+
EXEC SQL OPENc1 USING DESCRIPTOR indesc;
4951

50-
EXEC SQL FETCH next FROMc INTO :val1output, :val2output;
52+
EXEC SQL FETCH next FROMc1 INTO :val1output, :val2output;
5153
printf("val1=%d val2=%s\n", val1output, val2output);
5254

53-
EXEC SQL CLOSE c;
55+
EXEC SQL CLOSE c1;
56+
57+
EXEC SQL SET DESCRIPTOR indesc COUNT = 1;
58+
EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
5459

55-
EXEC SQL SELECT * INTO :val1output, :val2output FROM test1 where a = 2;
56-
printf("val1=%d val2=%s\n", val1output, val2output);
60+
EXEC SQL DECLARE c2 CURSOR FOR foo3;
61+
EXEC SQL OPEN c2 USING DESCRIPTOR indesc;
62+
63+
EXEC SQL FETCH next FROM c2 INTO :val1output, :val2output :val2i;
64+
printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
65+
66+
EXEC SQL CLOSE c2;
67+
68+
EXEC SQL SELECT * INTO :val1output, :val2output :val2i FROM test1 where a = 2;
69+
printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
5770

5871
EXEC SQL DROP TABLE test1;
5972
EXEC SQL DISCONNECT;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp