Skip to content

Commit abd310a

Browse files
author
Michael Meskes
committed
Allow constants in using clauses.
1 parent 5fc9f3d commit abd310a

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,10 @@ Thu Jun 19 10:08:26 CEST 2003
15011501

15021502
- Added missing rdayofweek function for Informix compatibility.
15031503
- Fixed fetch into char pointer.
1504+
1505+
Fri Jun 20 13:23:07 CEST 2003
1506+
1507+
- Enabled constants in using clause.
15041508
- Set ecpg version to 3.0.0
15051509
- Set ecpg library to 4.0.0
15061510
- Set pgtypes library to 1.0.0

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.10 2003/06/15 04:07:58 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.11 2003/06/20 12:00:59 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -775,6 +775,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
775775
*malloced_p = true;
776776
}
777777
break;
778+
case ECPGt_const:
778779
case ECPGt_char_variable:
779780
{
780781
int slen = strlen((char *) var->value);
@@ -1214,7 +1215,7 @@ ECPGexecute(struct statement * stmt)
12141215
{
12151216
ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
12161217
stmt->lineno, notify->relname, notify->be_pid);
1217-
PQfreemem(notify);
1218+
PQfreemem(notify);
12181219
}
12191220

12201221
return status;

src/interfaces/ecpg/ecpglib/typename.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.5 2003/06/17 07:28:22 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.6 2003/06/20 12:00:59 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -56,6 +56,8 @@ ECPGtype_name(enum ECPGttype typ)
5656
return "Timestamp";
5757
case ECPGt_interval:
5858
return "Interval";
59+
case ECPGt_char_const:
60+
return "Const";
5961
default:
6062
abort();
6163
}

src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum ECPGttype
5353
ECPGt_union,
5454
ECPGt_descriptor, /* sql descriptor, no C variable */
5555
ECPGt_char_variable,
56+
ECPGt_const, /* a constant is needed sometimes */
5657
ECPGt_EOIT, /* End of insert types. */
5758
ECPGt_EORT, /* End of result types. */
5859
ECPGt_NO_INDICATOR /* no indicator */

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.234 2003/06/19 09:52:11 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.235 2003/06/20 12:00:59 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -475,7 +475,7 @@ adjust_informix(struct arguments *list)
475475
%type <str> ECPGGetDescriptorHeader ECPGColLabel single_var_declaration
476476
%type <str> reserved_keyword unreserved_keyword ecpg_interval opt_ecpg_using
477477
%type <str> col_name_keyword func_name_keyword precision opt_scale
478-
%type <str> ECPGTypeName using_list ECPGColLabelCommon
478+
%type <str> ECPGTypeName using_list ECPGColLabelCommon UsingConst
479479
%type <str> inf_val_list inf_col_list using_descriptor into_descriptor
480480
%type <str> ecpg_into_using
481481

@@ -5196,7 +5196,19 @@ ecpg_into: INTO into_list { $$ = EMPTY; }
51965196
| into_descriptor { $$ = $1; }
51975197
;
51985198

5199-
using_list: civar | civar ',' using_list;
5199+
using_list: UsingConst | UsingConst ',' using_list;
5200+
5201+
UsingConst: AllConst
5202+
{
5203+
if ($1[1] != '?') /* found a constant */
5204+
{
5205+
char *length = mm_alloc(sizeof("INT_MAX")+1);
5206+
5207+
sprintf(length, "%d", strlen($1));
5208+
add_variable(&argsinsert, new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0), &no_indicator);
5209+
}
5210+
}
5211+
;
52005212

52015213
/*
52025214
* As long as the prepare statement is not supported by the backend, we will

src/interfaces/ecpg/preproc/type.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ get_type(enum ECPGttype type)
169169
* quoted */
170170
return ("ECPGt_char_variable");
171171
break;
172+
case ECPGt_const: /* constant string quoted */
173+
return ("ECPGt_const");
174+
break;
172175
case ECPGt_numeric:
173176
return ("ECPGt_numeric");
174177
break;
@@ -381,6 +384,14 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
381384
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
382385
sprintf(offset, "sizeof(Date)");
383386
break;
387+
case ECPGt_const:
388+
389+
/*
390+
* just dump the const as string
391+
*/
392+
sprintf(variable, "\"%s\"", name);
393+
sprintf(offset, "strlen(\"%s\")", name);
394+
break;
384395
default:
385396

386397
/*

src/interfaces/ecpg/test/test2.pgc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ exec sql begin declare section;
2727
struct birthinfo ind_birth;
2828
} ind_personal, *i;
2929
ind ind_children;
30-
c testname="Petra";
3130
char *query="select name, born, age, married, children from meskes where name = :var1";
3231
exec sql end declare section;
3332

@@ -92,7 +91,7 @@ exec sql end declare section;
9291
exec sql declare prep cursor for MM;
9392

9493
strcpy(msg, "open");
95-
exec sql open prep using :testname;
94+
exec sql open prep using 'Petra';
9695

9796
exec sql whenever not found do break;
9897

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy