Commit 03ad5da8 authored by Michael Meskes's avatar Michael Meskes

- Only use typedefs inside their scope.

- Variables that are out of scope, were not removed all the time.
- Make a varchar NULL set everything to 0 when not using indicators.
- Synced parser.
parent 4eb5f0a8
......@@ -1814,6 +1814,13 @@ Thu Jun 17 13:50:06 CEST 2004
Sun Jun 20 12:44:01 CEST 2004
- Synced parser and keyword list.
Sun Jun 27 13:50:58 CEST 2004
- Only use typedefs inside their scope.
- Variables that are out of scope, were not removed all the time.
- Make a varchar NULL set everything to 0 when not using indicators.
- Synced parser.
- Set pgtypes library version to 1.2.
- Set ecpg version to 3.2.0.
- Set compat library version to 1.2.
......
......@@ -1002,12 +1002,12 @@ ECPG_informix_get_var(int number)
int
rsetnull(int t, char *ptr)
{
ECPGset_informix_null(t, ptr);
ECPGset_noind_null(t, ptr);
return 0;
}
int
risnull(int t, char *ptr)
{
return (ECPGis_informix_null(t, ptr));
return (ECPGis_noind_null(t, ptr));
}
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.23 2004/05/05 15:03:04 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.24 2004/06/27 12:28:39 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
......@@ -76,7 +76,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
* and 0 if not
*/
if (PQgetisnull(results, act_tuple, act_field))
{
printf("MM NULL\n");
value_for_indicator = -1;
}
switch (ind_type)
{
......@@ -107,7 +110,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
* Informix has an additional way to specify NULLs
* note that this uses special values to denote NULL
*/
ECPGset_informix_null(type, var + offset * act_tuple);
ECPGset_noind_null(type, var + offset * act_tuple);
}
else
{
......@@ -411,7 +414,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (INFORMIX_MODE(compat))
{
/* Informix wants its own NULL value here instead of an error */
ECPGset_informix_null(ECPGt_numeric, nres);
ECPGset_noind_null(ECPGt_numeric, nres);
}
else
{
......@@ -454,7 +457,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (INFORMIX_MODE(compat))
{
/* Informix wants its own NULL value here instead of an error */
ECPGset_informix_null(ECPGt_interval, ires);
ECPGset_noind_null(ECPGt_interval, ires);
}
else
{
......@@ -493,7 +496,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (INFORMIX_MODE(compat))
{
/* Informix wants its own NULL value here instead of an error */
ECPGset_informix_null(ECPGt_date, &ddres);
ECPGset_noind_null(ECPGt_date, &ddres);
}
else
{
......@@ -531,7 +534,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (INFORMIX_MODE(compat))
{
/* Informix wants its own NULL value here instead of an error */
ECPGset_informix_null(ECPGt_timestamp, &tres);
ECPGset_noind_null(ECPGt_timestamp, &tres);
}
else
{
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.33 2004/05/05 15:03:04 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.34 2004/06/27 12:28:40 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
......@@ -532,7 +532,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
case ECPGt_NO_INDICATOR:
if (stmt->force_indicator == false)
{
if (ECPGis_informix_null(var->type, var->value))
if (ECPGis_noind_null(var->type, var->value))
*tobeinserted_p = "null";
}
break;
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.20 2004/03/14 14:47:33 momjian Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.21 2004/06/27 12:28:40 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
......@@ -266,7 +266,7 @@ ECPGlog(const char *format,...)
}
void
ECPGset_informix_null(enum ECPGttype type, void *ptr)
ECPGset_noind_null(enum ECPGttype type, void *ptr)
{
switch (type)
{
......@@ -301,6 +301,7 @@ ECPGset_informix_null(enum ECPGttype type, void *ptr)
break;
case ECPGt_varchar:
*(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
((struct ECPGgeneric_varchar *) ptr)->len = 0;
break;
case ECPGt_decimal:
memset((char *) ptr, 0, sizeof(decimal));
......@@ -331,7 +332,7 @@ _check(unsigned char *ptr, int length)
}
bool
ECPGis_informix_null(enum ECPGttype type, void *ptr)
ECPGis_noind_null(enum ECPGttype type, void *ptr)
{
switch (type)
{
......
......@@ -77,8 +77,8 @@ void ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat);
bool ECPGget_desc_header(int, char *, int *);
bool ECPGget_desc(int, char *, int,...);
void ECPGset_informix_null(enum ECPGttype, void *);
bool ECPGis_informix_null(enum ECPGttype, void *);
void ECPGset_noind_null(enum ECPGttype, void *);
bool ECPGis_noind_null(enum ECPGttype, void *);
bool ECPGdescribe(int, bool, const char *,...);
/* dynamic result allocation */
......
......@@ -82,6 +82,7 @@ extern struct typedefs *get_typedef(char *);
extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int, bool);
extern void reset_variables(void);
extern void check_indicator(struct ECPGtype *);
extern void remove_typedefs(int);
extern void remove_variables(int);
extern struct variable *new_variable(const char *, struct ECPGtype *, int);
extern ScanKeyword *ScanKeywordLookup(char *text);
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.288 2004/06/20 10:45:47 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.289 2004/06/27 12:28:42 meskes Exp $ */
/* Copyright comment */
%{
......@@ -542,7 +542,7 @@ add_additional_variables(char *name, bool insert)
%type <str> inf_val_list inf_col_list using_descriptor into_descriptor
%type <str> ecpg_into_using prepared_name struct_union_type_with_symbol
%type <str> ECPGunreserved ECPGunreserved_interval cvariable
%type <str> AlterDbOwnerStmt OptTableSpaceOwner CreateTableSpaceStmt
%type <str> AlterOwnerStmt OptTableSpaceOwner CreateTableSpaceStmt
%type <str> DropTableSpaceStmt indirection indirection_el
%type <struct_union> s_struct_union_symbol
......@@ -578,7 +578,7 @@ statement: ecpgstart opt_at stmt ';' { connection = NULL; }
| c_thing { fprintf(yyout, "%s", $1); free($1); }
| CPP_LINE { fprintf(yyout, "%s", $1); free($1); }
| '{' { braces_open++; fputs("{", yyout); }
| '}' { remove_variables(braces_open--); fputs("}", yyout); }
| '}' { remove_typedefs(braces_open); remove_variables(braces_open--); fputs("}", yyout); }
;
opt_at: AT connection_target
......@@ -594,9 +594,9 @@ opt_at: AT connection_target
};
stmt: AlterDatabaseSetStmt { output_statement($1, 0, connection); }
| AlterDbOwnerStmt { output_statement($1, 0, connection); }
| AlterDomainStmt { output_statement($1, 0, connection); }
| AlterGroupStmt { output_statement($1, 0, connection); }
| AlterOwnerStmt { output_statement($1, 0, connection); }
| AlterSeqStmt { output_statement($1, 0, connection); }
| AlterTableStmt { output_statement($1, 0, connection); }
| AlterUserSetStmt { output_statement($1, 0, connection); }
......@@ -2385,12 +2385,42 @@ RenameStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' RENAME TO name
{ $$ = cat_str(6, make_str("alter trigger"), $3, make_str("on"), $5, make_str("rename to"), $8); }
| ALTER USER UserId RENAME TO UserId
{ $$ = cat_str(4, make_str("alter user"), $3, make_str("rename to"), $6); }
| ALTER TABLESPACE name RENAME TO name
{ $$ = cat_str(4, make_str("alter tablespace"), $3, make_str("rename to"), $6); }
;
opt_column: COLUMN { $$ = make_str("column"); }
| /*EMPTY*/ { $$ = EMPTY; }
;
/*****************************************************************************
*
* ALTER THING name OWNER TO newname.
*
*****************************************************************************/
AlterOwnerStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' OWNER TO UserId
{ $$ = cat_str(6, make_str("alter aggregate"), $3, make_str("("), $5, make_str(") owner to"), $9); }
| ALTER CONVERSION_P any_name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter conversion"), $3, make_str("owner to"), $6); }
| ALTER DATABASE database_name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter database"), $3, make_str("owner to"), $6); }
| ALTER DOMAIN_P database_name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter domain"), $3, make_str("owner to"), $6); }
| ALTER FUNCTION func_name func_args OWNER TO UserId
{ $$ = cat_str(5, make_str("alter function"), $3, $4, make_str("owner to"), $7); }
| ALTER OPERATOR any_operator '(' oper_argtypes ')' OWNER TO UserId
{ $$ = cat_str(6, make_str("alter operator"), $3, make_str("("), $5, make_str(") owner to"), $9); }
| ALTER OPERATOR CLASS any_name USING access_method OWNER TO UserId
{ $$ = cat_str(6, make_str("alter operator class"), $4, make_str("using"), $6, make_str("owner to"), $9); }
| ALTER SCHEMA name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter schema"), $3, make_str("owner to"), $6); }
| ALTER TYPE_P any_name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter type"), $3, make_str("owner to"), $6); }
| ALTER TABLESPACE name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter tablespace"), $3, make_str("owner to"), $6); }
;
/*****************************************************************************
*
......@@ -2589,8 +2619,6 @@ opt_equal: '=' { $$ = make_str("="); }
*
*****************************************************************************/
AlterDbOwnerStmt: ALTER DATABASE database_name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter database"), $3, make_str("owner to"), $6); }
AlterDatabaseSetStmt: ALTER DATABASE database_name SET set_rest
{ $$ = cat_str(4, make_str("alter database"), $3, make_str("set"), $5); }
| ALTER DATABASE database_name VariableResetStmt
......@@ -2632,8 +2660,6 @@ AlterDomainStmt:
{ $$ = cat_str(4, make_str("alter domain"), $3, make_str("add"), $5); }
| ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
{ $$ = cat_str(5, make_str("alter domain"), $3, make_str("drop constraint"), $6, $7); }
| ALTER DOMAIN_P any_name OWNER TO UserId
{ $$ = cat_str(4, make_str("alter domain"), $3, make_str("owner to"), $6); }
;
opt_as: AS {$$ = make_str("as"); }
......@@ -4582,6 +4608,7 @@ type_declaration: S_TYPEDEF
/* initial definition */
this->next = types;
this->name = $5;
this->brace_level = braces_open;
this->type = (struct this_type *) mm_alloc(sizeof(struct this_type));
this->type->type_enum = $3.type_enum;
this->type->type_str = mm_strdup($5);
......@@ -4897,6 +4924,7 @@ struct_union_type_with_symbol: s_struct_union_symbol
/* initial definition */
this->next = types;
this->name = mm_strdup(su_type.type_str);
this->brace_level = braces_open;
this->type = (struct this_type *) mm_alloc(sizeof(struct this_type));
this->type->type_enum = su_type.type_enum;
this->type->type_str = mm_strdup(su_type.type_str);
......@@ -5417,6 +5445,7 @@ ECPGTypedef: TYPE_P
/* initial definition */
this->next = types;
this->name = $3;
this->brace_level = braces_open;
this->type = (struct this_type *) mm_alloc(sizeof(struct this_type));
this->type->type_enum = $5.type_enum;
this->type->type_str = mm_strdup($3);
......
......@@ -123,26 +123,27 @@ struct cursor
struct typedefs
{
char *name;
struct this_type *type;
struct ECPGstruct_member *struct_member_list;
struct typedefs *next;
char *name;
struct this_type *type;
struct ECPGstruct_member *struct_member_list;
int brace_level;
struct typedefs *next;
};
struct _defines
{
char *old;
char *new;
int pertinent;
char *old;
char *new;
int pertinent;
struct _defines *next;
};
/* This is a linked list of the variable names and types. */
struct variable
{
char *name;
char *name;
struct ECPGtype *type;
int brace_level;
int brace_level;
struct variable *next;
};
......
......@@ -275,13 +275,47 @@ find_variable(char *name)
return (p);
}
void
remove_typedefs(int brace_level)
{
struct typedefs *p,
*prev;
for (p = prev = types; p;)
{
if (p->brace_level >= brace_level)
{
/* remove it */
if (p == types)
prev = types = p->next;
else
prev->next = p->next;
if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union)
free(p->struct_member_list);
free(p->type);
free(p->name);
free(p);
if (prev == types)
p = types;
else
p = prev ? prev->next : NULL;
}
else
{
prev = p;
p = prev->next;
}
}
}
void
remove_variables(int brace_level)
{
struct variable *p,
*prev;
for (p = prev = allvariables; p; p = p ? p->next : NULL)
for (p = prev = allvariables; p;)
{
if (p->brace_level >= brace_level)
{
......@@ -326,10 +360,16 @@ remove_variables(int brace_level)
ECPGfree_type(p->type);
free(p->name);
free(p);
p = prev;
if (prev == allvariables)
p = allvariables;
else
p = prev ? prev->next : NULL;
}
else
{
prev = p;
p = prev->next;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment