Skip to content

Commit dbdc2e5

Browse files
author
Michael Meskes
committed
Re-enabled variables in fetch/move command.
1 parent abab776 commit dbdc2e5

File tree

8 files changed

+126
-156
lines changed

8 files changed

+126
-156
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,10 @@ Mon, 14 Jan 2008 10:42:23 +0100
22932293

22942294
- Set valid return values even in case of an error to prevent
22952295
segfaults.
2296+
2297+
Tue, 15 Jan 2008 11:26:14 +0100
2298+
2299+
- Re-enabled variables in fetch/move command.
22962300
- Set pgtypes library version to 3.0.
22972301
- Set compat library version to 3.0.
22982302
- Set ecpg library version to 6.0.

src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 2 additions & 2 deletions
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.28 2007/11/15 21:14:45 momjian Exp $
3+
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.29 2008/01/15 10:31:47 meskes Exp $
44
*/
55

66
#define POSTGRES_ECPG_INTERNAL
@@ -529,7 +529,7 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
529529
for (;;)
530530
{
531531
enum ECPGdtype itemtype;
532-
const char *tobeinserted = NULL;
532+
char *tobeinserted = NULL;
533533

534534
itemtype = va_arg(args, enum ECPGdtype);
535535

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 84 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.74 2008/01/13 11:53:16 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.75 2008/01/15 10:31:47 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -128,8 +128,8 @@ next_insert(char *text, int pos, bool questionmarks)
128128
int i;
129129

130130
for (i = p + 1; isdigit(text[i]); i++);
131-
if (!isalpha(text[i]) &&isascii(text[i]) &&text[i] != '_')
132-
/* not dollar delimeted quote */
131+
if (!isalpha(text[i]) && isascii(text[i]) && text[i] != '_')
132+
/* not dollar delimited quote */
133133
return p;
134134
}
135135
else if (questionmarks && text[p] == '?')
@@ -451,7 +451,7 @@ ecpg_store_result(const PGresult *results, int act_field,
451451

452452
bool
453453
ecpg_store_input(const int lineno, const bool force_indicator, const struct variable * var,
454-
const char **tobeinserted_p, bool quote)
454+
char **tobeinserted_p, bool quote)
455455
{
456456
char *mallocedval = NULL;
457457
char *newcopy = NULL;
@@ -1046,6 +1046,39 @@ free_params(const char **paramValues, int nParams, bool print, int lineno)
10461046
ecpg_free(paramValues);
10471047
}
10481048

1049+
1050+
static bool
1051+
insert_tobeinserted(int position, int ph_len, struct statement * stmt, char *tobeinserted)
1052+
{
1053+
char *newcopy;
1054+
1055+
if (!(newcopy = (char *) ecpg_alloc(strlen(stmt->command)
1056+
+ strlen(tobeinserted)
1057+
+ 1, stmt->lineno)))
1058+
{
1059+
ecpg_free(tobeinserted);
1060+
return false;
1061+
}
1062+
1063+
strcpy(newcopy, stmt->command);
1064+
strcpy(newcopy + position - 1, tobeinserted);
1065+
1066+
/*
1067+
* The strange thing in the second argument is the rest of the
1068+
* string from the old string
1069+
*/
1070+
strcat(newcopy,
1071+
stmt->command
1072+
+ position
1073+
+ ph_len - 1);
1074+
1075+
ecpg_free(stmt->command);
1076+
stmt->command = newcopy;
1077+
1078+
ecpg_free((char *) tobeinserted);
1079+
return true;
1080+
}
1081+
10491082
static bool
10501083
ecpg_execute(struct statement * stmt)
10511084
{
@@ -1069,7 +1102,7 @@ ecpg_execute(struct statement * stmt)
10691102
var = stmt->inlist;
10701103
while (var)
10711104
{
1072-
const char *tobeinserted;
1105+
char *tobeinserted;
10731106
int counter = 1;
10741107

10751108
tobeinserted = NULL;
@@ -1134,11 +1167,51 @@ ecpg_execute(struct statement * stmt)
11341167

11351168
/*
11361169
* now tobeinserted points to an area that contains the next parameter
1170+
* now find the positin in the string where it belongs
1171+
*/
1172+
if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1173+
{
1174+
/*
1175+
* We have an argument but we dont have the matched up
1176+
* placeholder in the string
1177+
*/
1178+
ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
1179+
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
1180+
NULL);
1181+
free_params(paramValues, nParams, false, stmt->lineno);
1182+
return false;
1183+
}
1184+
1185+
/*
11371186
* if var->type=ECPGt_char_variable we have a dynamic cursor we have
11381187
* to simulate a dynamic cursor because there is no backend
11391188
* functionality for it
11401189
*/
1141-
if (var->type != ECPGt_char_variable)
1190+
if (var->type == ECPGt_char_variable)
1191+
{
1192+
int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
1193+
1194+
if (!insert_tobeinserted(position, ph_len, stmt, tobeinserted))
1195+
{
1196+
free_params(paramValues, nParams, false, stmt->lineno);
1197+
return false;
1198+
}
1199+
tobeinserted = NULL;
1200+
}
1201+
/*
1202+
* if the placeholder is '$0' we have to replace it on the client side
1203+
* this is for places we want to support variables at that are not supported in the backend
1204+
*/
1205+
else if (stmt->command[position] == '0' )
1206+
{
1207+
if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1208+
{
1209+
free_params(paramValues, nParams, false, stmt->lineno);
1210+
return false;
1211+
}
1212+
tobeinserted = NULL;
1213+
}
1214+
else
11421215
{
11431216
nParams++;
11441217
if (!(paramValues = (const char **) ecpg_realloc(paramValues, sizeof(const char *) * nParams, stmt->lineno)))
@@ -1149,107 +1222,28 @@ ecpg_execute(struct statement * stmt)
11491222

11501223
paramValues[nParams - 1] = tobeinserted;
11511224

1152-
if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1153-
{
1154-
/*
1155-
* We have an argument but we dont have the matched up
1156-
* placeholder in the string
1157-
*/
1158-
ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
1159-
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
1160-
NULL);
1161-
free_params(paramValues, nParams, false, stmt->lineno);
1162-
return false;
1163-
}
1164-
11651225
/* let's see if this was an old style placeholder */
1166-
if (stmt->command[position - 1] == '?')
1226+
if (stmt->command[position] == '?')
11671227
{
11681228
/* yes, replace with new style */
11691229
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
11701230
* size we need */
1171-
char *buffer,
1172-
*newcopy;
11731231

1174-
if (!(buffer = (char *) ecpg_alloc(buffersize, stmt->lineno)))
1232+
if (!(tobeinserted = (char *) ecpg_alloc(buffersize, stmt->lineno)))
11751233
{
11761234
free_params(paramValues, nParams, false, stmt->lineno);
11771235
return false;
11781236
}
11791237

1180-
snprintf(buffer, buffersize, "$%d", counter++);
1238+
snprintf(tobeinserted, buffersize, "$%d", counter++);
11811239

1182-
if (!(newcopy = (char *) ecpg_alloc(strlen(stmt->command) + strlen(buffer) + 1, stmt->lineno)))
1240+
if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
11831241
{
11841242
free_params(paramValues, nParams, false, stmt->lineno);
1185-
ecpg_free(buffer);
11861243
return false;
11871244
}
1188-
1189-
strcpy(newcopy, stmt->command);
1190-
1191-
/* set positional parameter */
1192-
strcpy(newcopy + position - 1, buffer);
1193-
1194-
/*
1195-
* The strange thing in the second argument is the rest of the
1196-
* string from the old string
1197-
*/
1198-
strcat(newcopy,
1199-
stmt->command
1200-
+ position + 1);
1201-
ecpg_free(buffer);
1202-
ecpg_free(stmt->command);
1203-
stmt->command = newcopy;
1204-
}
1205-
}
1206-
else
1207-
{
1208-
char *newcopy;
1209-
1210-
if (!(newcopy = (char *) ecpg_alloc(strlen(stmt->command)
1211-
+ strlen(tobeinserted)
1212-
+ 1, stmt->lineno)))
1213-
{
1214-
free_params(paramValues, nParams, false, stmt->lineno);
1215-
return false;
1216-
}
1217-
1218-
strcpy(newcopy, stmt->command);
1219-
if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1220-
{
1221-
/*
1222-
* We have an argument but we dont have the matched up string
1223-
* in the string
1224-
*/
1225-
ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
1226-
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
1227-
NULL);
1228-
free_params(paramValues, nParams, false, stmt->lineno);
1229-
ecpg_free(newcopy);
1230-
return false;
1245+
tobeinserted = NULL;
12311246
}
1232-
else
1233-
{
1234-
int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
1235-
1236-
strcpy(newcopy + position - 1, tobeinserted);
1237-
1238-
/*
1239-
* The strange thing in the second argument is the rest of the
1240-
* string from the old string
1241-
*/
1242-
strcat(newcopy,
1243-
stmt->command
1244-
+ position
1245-
+ ph_len - 1);
1246-
}
1247-
1248-
ecpg_free(stmt->command);
1249-
stmt->command = newcopy;
1250-
1251-
ecpg_free((char *) tobeinserted);
1252-
tobeinserted = NULL;
12531247
}
12541248

12551249
if (desc_counter == 0)

src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.32 2007/11/15 21:14:45 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.33 2008/01/15 10:31:47 meskes Exp $ */
22

33
#ifndef _ECPG_LIB_EXTERN_H
44
#define _ECPG_LIB_EXTERN_H
@@ -138,7 +138,7 @@ struct descriptor *ecpg_find_desc(int line, const char *name);
138138

139139
bool ecpg_store_result(const PGresult *results, int act_field,
140140
const struct statement * stmt, struct variable * var);
141-
bool ecpg_store_input(const int, const bool, const struct variable *, const char **, bool);
141+
bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool);
142142

143143
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE);
144144
void ecpg_raise(int line, int code, const char *sqlstate, const char *str);

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.158 2008/01/11 15:19:16 meskes Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.159 2008/01/15 10:31:47 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -28,7 +28,6 @@ extern YYSTYPE yylval;
2828

2929
static int xcdepth = 0; /* depth of nesting in slash-star comments */
3030
static char *dolqstart; /* current $foo$ quote start string */
31-
static bool escape_string_warning;
3231
static YY_BUFFER_STATE scanbufhandle;
3332
static char *scanbuf;
3433

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