-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.17 2003/09/09 10:46:37 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.18 2003/09/18 13:12:23 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
else
nres = PGTYPESnumeric_from_asc(pval, &scan_length);
+ /* did we get an error? */
+ if (errno != 0)
+ {
+ if (INFORMIX_MODE(compat))
+ {
+ /* Informix wants its own NULL value here instead of an error */
+ ECPGset_informix_null(ECPGt_numeric, &nres);
+ return (true);
+ }
+ else
+ {
+ ECPGraise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ return (false);
+ }
+ }
if (isarray && *scan_length == '"')
scan_length++;
else
ires = PGTYPESinterval_from_asc(pval, &scan_length);
+ /* did we get an error? */
+ if (errno != 0)
+ {
+ if (INFORMIX_MODE(compat))
+ {
+ /* Informix wants its own NULL value here instead of an error */
+ ECPGset_informix_null(ECPGt_interval, &ires);
+ return (true);
+ }
+ else
+ {
+ ECPGraise(lineno, ECPG_INTERVAL_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ return (false);
+ }
+ }
if (isarray && *scan_length == '"')
scan_length++;
else
ddres = PGTYPESdate_from_asc(pval, &scan_length);
+ /* did we get an error? */
+ if (errno != 0)
+ {
+ if (INFORMIX_MODE(compat))
+ {
+ /* Informix wants its own NULL value here instead of an error */
+ ECPGset_informix_null(ECPGt_date, &ddres);
+ return (true);
+ }
+ else
+ {
+ ECPGraise(lineno, ECPG_DATE_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ return (false);
+ }
+ }
+
if (isarray && *scan_length == '"')
scan_length++;
else
tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
+ /* did we get an error? */
+ if (errno != 0)
+ {
+ if (INFORMIX_MODE(compat))
+ {
+ /* Informix wants its own NULL value here instead of an error */
+ ECPGset_informix_null(ECPGt_timestamp, &tres);
+ return (true);
+ }
+ else
+ {
+ ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ return (false);
+ }
+ }
if (isarray && *scan_length == '"')
scan_length++;
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.254 2003/09/09 10:46:38 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.255 2003/09/18 13:12:23 meskes Exp $ */
/* Copyright comment */
%{
return result;
}
+static struct cursor *
+add_additional_variables(char *name, bool insert)
+{
+ struct cursor *ptr;
+ struct arguments *p;
+
+ for (ptr = cur; ptr != NULL; ptr=ptr->next)
+ {
+ if (strcmp(ptr->name, name) == 0)
+ break;
+ }
+
+ if (ptr == NULL)
+ {
+ snprintf(errortext, sizeof(errortext), "trying to access an undeclared cursor %s\n", name);
+ mmerror(PARSE_ERROR, ET_ERROR, errortext);
+ return NULL;
+ }
+ if (insert)
+ {
+ /* add all those input variables that were given earlier */
+ for (p = ptr->argsinsert; p; p = p->next)
+ add_variable(&argsinsert, p->variable, p->indicator);
+ }
+ else
+ {
+ /* add all those output variables that were given earlier */
+ for (p = ptr->argsresult; p; p = p->next)
+ add_variable(&argsresult, p->variable, p->indicator);
+ }
+ return ptr;
+}
%}
%union {
%type <str> trim_list in_expr substr_for attrs TableFuncElement
%type <str> Typename SimpleTypename Numeric opt_float opt_numeric
%type <str> opt_decimal Character character opt_varying opt_charset
-%type <str> opt_collate opt_timezone opt_interval table_ref fetch_direction
+%type <str> opt_timezone opt_interval table_ref fetch_direction
%type <str> row_descriptor ConstDatetime AlterDomainStmt AlterSeqStmt
%type <str> SelectStmt into_clause OptTemp ConstraintAttributeSpec
%type <str> opt_table opt_all sort_clause sortby_list ConstraintAttr
%type <str> col_name_keyword func_name_keyword precision opt_scale
%type <str> ECPGTypeName using_list ECPGColLabelCommon UsingConst
%type <str> inf_val_list inf_col_list using_descriptor into_descriptor
-%type <str> ecpg_into_using
+%type <str> ecpg_into_using prepared_name
%type <struct_union> s_struct_union_symbol
| ECPGOpen
{
struct cursor *ptr;
- struct arguments *p;
-
- for (ptr = cur; ptr != NULL; ptr=ptr->next)
- {
- if (strcmp(ptr->name, $1) == 0)
- break;
- }
-
- if (ptr == NULL)
- {
- snprintf(errortext, sizeof(errortext), "trying to open undeclared cursor %s\n", $1);
- mmerror(PARSE_ERROR, ET_ERROR, errortext);
- }
- else
- {
- /* merge variables given in prepare statement with those given here */
- for (p = ptr->argsinsert; p; p = p->next)
- append_variable(&argsinsert, p->variable, p->indicator);
-
- for (p = ptr->argsresult; p; p = p->next)
- add_variable(&argsresult, p->variable, p->indicator);
+ if ((ptr = add_additional_variables($1, true)) != NULL)
output_statement(mm_strdup(ptr->command), 0, ptr->connection ? mm_strdup(ptr->connection) : NULL);
- }
}
| ECPGPrepare
{
| TableConstraint { $$ = $1; }
;
-columnDef: ColId Typename ColQualList opt_collate
+columnDef: ColId Typename ColQualList
{
- if (strlen($4) > 0)
- {
- snprintf(errortext, sizeof(errortext), "Currently unsupported CREATE TABLE / COLLATE %s will be passed to backend", $4);
- mmerror(PARSE_ERROR, ET_WARNING, errortext);
- }
- $$ = cat_str(4, $1, $2, $3, $4);
+ $$ = cat_str(3, $1, $2, $3);
}
;
* translate it to the PGSQL syntax. */
FetchStmt: FETCH fetch_direction from_in name ecpg_into_using
- { $$ = cat_str(4, make_str("fetch"), $2, $3, $4); }
+ {
+ add_additional_variables($4, false);
+ $$ = cat_str(4, make_str("fetch"), $2, $3, $4);
+ }
| FETCH fetch_direction name ecpg_into_using
- { $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3); }
+ {
+ add_additional_variables($3, false);
+ $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3);
+ }
| FETCH from_in name ecpg_into_using
- { $$ = cat_str(3, make_str("fetch"), $2, $3); }
+ {
+ add_additional_variables($3, false);
+ $$ = cat_str(3, make_str("fetch"), $2, $3);
+ }
| FETCH name ecpg_into_using
- { $$ = cat2_str(make_str("fetch"), $2); }
+ {
+ add_additional_variables($2, false);
+ $$ = cat2_str(make_str("fetch"), $2);
+ }
| FETCH fetch_direction from_in name
- { $$ = cat_str(4, make_str("fetch"), $2, $3, $4); }
+ {
+ add_additional_variables($4, false);
+ $$ = cat_str(4, make_str("fetch"), $2, $3, $4);
+ }
| FETCH fetch_direction name
- { $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3); }
+ {
+ add_additional_variables($3, false);
+ $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3);
+ }
| FETCH from_in name
- { $$ = cat_str(3, make_str("fetch"), $2, $3); }
+ {
+ add_additional_variables($3, false);
+ $$ = cat_str(3, make_str("fetch"), $2, $3);
+ }
| FETCH name
- { $$ = cat2_str(make_str("fetch"), $2); }
+ {
+ add_additional_variables($2, false);
+ $$ = cat2_str(make_str("fetch"), $2);
+ }
| MOVE fetch_direction from_in name
{ $$ = cat_str(4, make_str("move"), $2, $3, $4); }
| MOVE name
*
*****************************************************************************/
-CreateDomainStmt: CREATE DOMAIN_P any_name opt_as Typename ColQualList opt_collate
+CreateDomainStmt: CREATE DOMAIN_P any_name opt_as Typename ColQualList
{
- $$ = cat_str(6, make_str("create domain"), $3, $4, $5, $6, $7);
+ $$ = cat_str(55555, make_str("create domain"), $3, $4, $5, $6);
}
;
{ $$ = EMPTY; }
;
-opt_collate: COLLATE ColId
- { $$ = cat2_str(make_str("collate"), $2); }
- | /*EMPTY*/
- { $$ = EMPTY; }
- ;
-
ConstDatetime: TIMESTAMP '(' PosIntConst ')' opt_timezone
{ $$ = cat_str(4, make_str("timestamp("), $3, make_str(")"), $5); }
| TIMESTAMP opt_timezone
* Declare a prepared cursor. The syntax is different from the standard
* declare statement, so we create a new rule.
*/
-ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR ident
+ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
{
struct cursor *ptr, *this;
struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
thisquery->type = &ecpg_query;
thisquery->brace_level = 0;
thisquery->next = NULL;
- thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(\"\")") + strlen($7));
- sprintf(thisquery->name, "ECPGprepared_statement(\"%s\")", $7);
+ thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement()") + strlen($7));
+ sprintf(thisquery->name, "ECPGprepared_statement(%s)", $7);
this->argsinsert = NULL;
add_variable(&(this->argsinsert), thisquery, &no_indicator);
* the exec sql deallocate prepare command to deallocate a previously
* prepared statement
*/
-ECPGDeallocate: DEALLOCATE PREPARE ident
+ECPGDeallocate: DEALLOCATE PREPARE prepared_name
{ $$ = $3; }
- | DEALLOCATE ident
+ | DEALLOCATE prepared_name
{ $$ = $2; }
;
;
/*
- * As long as the prepare statement is not supported by the backend, we will
- * try to simulate it here so we get dynamic SQL
+ * We try to simulate the correct DECLARE syntax here so we get dynamic SQL
*/
ECPGDeclare: DECLARE STATEMENT ident
{
$$ = make_str("?");
}
- | EXECUTE name
+ | EXECUTE prepared_name
{
struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
thisquery->type = &ecpg_query;
thisquery->brace_level = 0;
thisquery->next = NULL;
- thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(\"\")") + strlen($2));
- sprintf(thisquery->name, "ECPGprepared_statement(\"%s\")", $2);
+ thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement()") + strlen($2));
+ sprintf(thisquery->name, "ECPGprepared_statement(%s)", $2);
add_variable(&argsinsert, thisquery, &no_indicator);
}
{ $$ = make3_str(make_str("\""), $1, make_str("\"")); }
;
+prepared_name: name { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
+ | char_variable { $$ = $1; }
+
/*
* the exec sql free command to deallocate a previously
* prepared statement
*
* It is supported now but not usable yet by ecpg.
*/
-ECPGPrepare: PREPARE name FROM execstring
- { $$ = cat2_str(make3_str(make_str("\""), $2, make_str("\",")), $4); }
+ECPGPrepare: PREPARE prepared_name FROM execstring
+ { $$ = cat_str(3, $2, make_str(","), $4); }
;
/*
* We accept descibe but do nothing with it so far.
| SQL_INDICATOR name { check_indicator((find_variable($2))->type); $$ = $2; }
;
-ident: IDENT { $$ = $1; }
- | CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
+ident: IDENT { $$ = $1; }
+ | CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
;
quoted_ident_stringvar: name