- Synced preproc.y with gram.y.
- Started to clean up preproc.y.
+
+Tue Feb 22 13:48:18 CET 2000
+
+ - Synced preproc.y with gram.y.
+ - Much more clean ups.
- Set library version to 3.1.0.
- Set ecpg version to 2.7.0.
make ECPGnumeric_lvalue more accurate by using something like ECPGdump_a_*
+remove space_or_nl and line_end from pgc.l
+
Missing statements:
- exec sql ifdef
- SQLSTATE
/* dynamic SQL related */
#define ECPG_UNKNOWN_DESCRIPTOR -240
#define ECPG_INVALID_DESCRIPTOR_INDEX -241
+#define ECPG_UNKNOWN_DESCRIPTOR_ITEM -242
+#define ECPG_VAR_NOT_NUMERIC -243
/* finally the backend error messages, they start at 400 */
#define ECPG_PGSQL -400
bool ECPGallocate_desc(int line,const char *name);
void ECPGraise(int line, int code, const char *str);
bool ECPGget_desc_header(int, char *, int *);
+ bool ECPGget_desc(int, char *, int, ...);
#ifdef __cplusplus
ECPGt_EORT, /* End of result types. */
ECPGt_NO_INDICATOR /* no indicator */
};
+
+ enum ECPGdtype
+ {
+ ECPGd_count,
+ ECPGd_data,
+ ECPGd_di_code,
+ ECPGd_di_precision,
+ ECPGd_indicator,
+ ECPGd_key_member,
+ ECPGd_length,
+ ECPGd_name,
+ ECPGd_nullable,
+ ECPGd_octet,
+ ECPGd_precision,
+ ECPGd_ret_length,
+ ECPGd_ret_octet,
+ ECPGd_scale,
+ ECPGd_type,
+ ECPGd_EODT, /* End of descriptor types. */
+ };
#define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_varchar2)
# Copyright (c) 1994, Regents of the University of California
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.58 2000/02/16 16:18:05 meskes Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.59 2000/02/22 19:57:05 meskes Exp $
#
#-------------------------------------------------------------------------
CFLAGS+= $(KRBFLAGS)
endif
-OBJS= ecpglib.o typename.o
+OBJS= ecpglib.o typename.o descriptor.o
SHLIB_LINK= -L../../libpq -lpq
return false;
*count = PQnfields(ECPGresult);
- ECPGlog("ECPGget-desc_header: found %d sttributes.\n", *count);
+ ECPGlog("ECPGget_desc_header: found %d attributes.\n", *count);
return true;
}
+
+static bool
+get_int_item(int lineno, void *var, enum ECPGdtype vartype, int value)
+{
+ switch (vartype)
+ {
+ case ECPGt_short:
+ *(short *)var = value;
+ break;
+ case ECPGt_int:
+ *(int *)var = value;
+ break;
+ case ECPGt_long:
+ *(long *)var = value;
+ break;
+ case ECPGt_unsigned_short:
+ *(unsigned short *)var = value;
+ break;
+ case ECPGt_unsigned_int:
+ *(unsigned int *)var = value;
+ break;
+ case ECPGt_unsigned_long:
+ *(unsigned long *)var = value;
+ break;
+ case ECPGt_float:
+ *(float *)var = value;
+ break;
+ case ECPGt_double:
+ *(double *)var = value;
+ break;
+ default:
+ ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, NULL);
+ return (false);
+ }
+
+ return(true);
+}
+
+bool
+ECPGget_desc(int lineno, char *desc_name, int index, ...)
+{
+ va_list args;
+ PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
+ enum ECPGdtype type;
+ bool DataButNoIndicator = false;
+
+ va_start(args, index);
+ if (!ECPGresult)
+ return (false);
+
+ if (PQntuples(ECPGresult) < 1)
+ {
+ ECPGraise(lineno, ECPG_NOT_FOUND, NULL);
+ return (false);
+ }
+
+ if (index < 1 || index >PQnfields(ECPGresult))
+ {
+ ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, NULL);
+ return (false);
+ }
+
+ ECPGlog("ECPGget_desc: reading items for tuple %d\n", index);
+ --index;
+
+ type = va_arg(args, enum ECPGdtype);
+
+ while (type != ECPGd_EODT)
+ {
+ char type_str[20];
+ long varcharsize;
+ long offset;
+ long arrsize;
+ enum ECPGttype vartype;
+ void *var;
+
+ vartype = va_arg(args, enum ECPGttype);
+ var = va_arg(args, void *);
+ varcharsize = va_arg(args, long);
+ arrsize = va_arg(args, long);
+ offset = va_arg(args, long);
+
+ switch (type)
+ {
+ case (ECPGd_indicator):
+ if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, 0, index)))
+ return (false);
+ break;
+
+ case ECPGd_name:
+ strncpy((char *)var, PQfname(ECPGresult, index), varcharsize);
+ break;
+
+ case ECPGd_nullable:
+ if (!get_int_item(lineno, var, vartype, 1))
+ return (false);
+ break;
+
+ case ECPGd_key_member:
+ if (!get_int_item(lineno, var, vartype, 0))
+ return (false);
+ break;
+
+ case ECPGd_scale:
+ if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff))
+ return (false);
+ break;
+
+ case ECPGd_precision:
+ if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16))
+ return (false);
+ break;
+
+ case ECPGd_ret_length:
+ case ECPGd_ret_octet:
+ if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, 0, index)))
+ return (false);
+ break;
+
+ case ECPGd_octet:
+ if (!get_int_item(lineno, var, vartype, PQfsize(ECPGresult, index)))
+ return (false);
+ break;
+
+ case ECPGd_length:
+ if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) - VARHDRSZ))
+ return (false);
+ break;
+
+ case ECPGd_type:
+ if (!get_int_item(lineno, var, vartype, ECPGDynamicType(PQftype(ECPGresult, index))))
+ return (false);
+ break;
+
+ default:
+ snprintf(type_str, sizeof(type_str), "%d", type);
+ ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, type_str);
+ return(false);
+ }
+
+ type = va_arg(args, enum ECPGdtype);
+ }
+
+ if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index))
+ {
+ ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
+ return (false);
+ }
+
+ return (true);
+}
*
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.4 2000/02/18 16:02:49 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.5 2000/02/22 19:57:05 meskes Exp $
*/
/* I borrowed the include files from ecpglib.c, maybe we don't need all of them */
/* free previous result */
if (i->result) PQclear(i->result);
- i->result=NULL;
+ i->result=NULL;
status=do_descriptor2(line,connection,&i->result,query);
return (status);
}
}
- ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
+
+ ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, descriptor);
return false;
}
if (!strcmp(name, i->name)) return i->result;
}
- ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
+ ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
return NULL;
}
return true;
}
}
- ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
+ ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
return false;
}
{
struct auto_mem *am;
- sqlca.sqlcode=code;
+ sqlca.sqlcode = code;
switch (code)
{
case ECPG_NOT_FOUND:
case ECPG_UNKNOWN_DESCRIPTOR:
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "descriptor not found, line %d.", line);
+ "descriptor %s not found, line %d.", str, line);
break;
case ECPG_INVALID_DESCRIPTOR_INDEX:
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
"descriptor index out of range, line %d.", line);
break;
+
+ case ECPG_UNKNOWN_DESCRIPTOR_ITEM:
+ snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
+ "unknown descriptor item %s, line %d.", str, line);
+ break;
+
+ case ECPG_VAR_NOT_NUMERIC:
+ snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
+ "variable is not a numeric type, line %d.", line);
+ break;
- default:
+ default:
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
"SQL error #%d, line %d.",code, line);
break;
if (!new)
{
ECPGlog("out of memory\n");
- ECPGraise(ECPG_OUT_OF_MEMORY, lineno, NULL);
+ ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL);
return NULL;
}
if (!new)
{
ECPGlog("out of memory\n");
- ECPGraise(ECPG_OUT_OF_MEMORY, lineno, NULL);
+ ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL);
return NULL;
}
default:
/* Not implemented yet */
- ECPGraise(ECPG_UNSUPPORTED, stmt->lineno, ECPGtype_name(var->type));
+ ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, ECPGtype_name(var->type));
return false;
break;
}
* We have an argument but we dont have the matched up string
* in the string
*/
- ECPGraise(ECPG_TOO_MANY_ARGUMENTS, stmt->lineno, NULL);
+ ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, NULL);
return false;
}
else
/* Check if there are unmatched things left. */
if (next_insert(copiedquery) != NULL)
{
- ECPGraise(ECPG_TOO_FEW_ARGUMENTS, stmt->lineno, NULL);
+ ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, NULL);
return false;
}
{
ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n",
stmt->lineno, ntuples);
- ECPGraise(ECPG_NOT_FOUND, stmt->lineno, NULL);
+ ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL);
status = false;
break;
}
if (var == NULL)
{
ECPGlog("ECPGexecute line %d: Too few arguments.\n", stmt->lineno);
- ECPGraise(ECPG_TOO_FEW_ARGUMENTS, stmt->lineno, NULL);
+ ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, NULL);
return (false);
}
{
ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d don't fit into array of %d\n",
stmt->lineno, ntuples, var->arrsize);
- ECPGraise(ECPG_TOO_MANY_MATCHES, stmt->lineno, NULL);
+ ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL);
status = false;
break;
}
}
break;
default:
- ECPGraise(ECPG_UNSUPPORTED, stmt->lineno, ECPGtype_name(var->ind_type));
+ ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, ECPGtype_name(var->ind_type));
status = false;
break;
}
break;
default:
- ECPGraise(ECPG_UNSUPPORTED, stmt->lineno, ECPGtype_name(var->type));
+ ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, ECPGtype_name(var->type));
status = false;
break;
}
if (status && var != NULL)
{
- ECPGraise(ECPG_TOO_MANY_ARGUMENTS, stmt->lineno, NULL);
+ ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, NULL);
status = false;
}
}
bool
-ECPGdo(int lineno, const char *connection_name, char *query,...)
+ECPGdo(int lineno, const char *connection_name, char *query, ...)
{
va_list args;
struct statement *stmt;
struct assignment *assignments;
-void push_assignment(char *var, char *value)
+void push_assignment(char *var, enum ECPGdtype value)
{
struct assignment *new = (struct assignment *)mm_alloc(sizeof(struct assignment));
new->next = assignments;
- new->variable = mm_alloc(strlen(var)+1);
- strcpy(new->variable,var);
- new->value = mm_alloc(strlen(value)+1);
- strcpy(new->value,value);
+ new->variable = mm_alloc(strlen(var) + 1);
+ strcpy(new->variable, var);
+ new->value = value;
assignments = new;
}
assignments = old_head->next;
free(old_head->variable);
- free(old_head->value);
free(old_head);
}
}
static void ECPGstring_buffer(FILE *f, char *name)
{
- const struct variable *v=find_variable(name);
+ const struct variable *v = find_variable(name);
switch(v->type->typ)
{
void add_descriptor(char *name,char *connection)
{
- struct descriptor *new=(struct descriptor *)mm_alloc(sizeof(struct descriptor));
+ struct descriptor *new = (struct descriptor *)mm_alloc(sizeof(struct descriptor));
- new->next=descriptors;
- new->name=mm_alloc(strlen(name)+1);
+ new->next = descriptors;
+ new->name = mm_alloc(strlen(name) + 1);
strcpy(new->name,name);
if (connection)
- { new->connection=mm_alloc(strlen(connection)+1);
- strcpy(new->connection,connection);
+ {
+ new->connection = mm_alloc(strlen(connection) + 1);
+ strcpy(new->connection, connection);
}
- else new->connection=connection;
- descriptors=new;
+ else new->connection = connection;
+ descriptors = new;
}
void
}
struct descriptor
-*lookup_descriptor(char *name,char *connection)
+*lookup_descriptor(char *name, char *connection)
{
struct descriptor *i;
- for (i=descriptors;i;i=i->next)
+ for (i = descriptors; i; i = i->next)
{
- if (!strcmp(name,i->name))
+ if (!strcmp(name, i->name))
{
if ((!connection && !i->connection)
|| (connection && i->connection
}
}
}
- snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
- mmerror(ET_WARN,errortext);
+ snprintf(errortext, sizeof errortext, "unknown descriptor %s", name);
+ mmerror(ET_WARN, errortext);
return NULL;
}
fprintf(yyout, "{ ECPGget_desc_header(%d, \"%s\", &(", yylineno, desc_name);
for (results = assignments; results != NULL; results = results->next)
{
- if (!strcasecmp(results->value, "count"))
+ if (results->value == ECPGd_count)
ECPGnumeric_lvalue(yyout,results->variable);
else
- { snprintf(errortext, sizeof errortext, "unknown descriptor header item '%s'", results->value);
+ {
+ snprintf(errortext, sizeof errortext, "unknown descriptor header item '%d'", results->value);
mmerror(ET_WARN, errortext);
}
}
}
void
-output_get_descr(char *desc_name)
+output_get_descr(char *desc_name, char *index)
{
struct assignment *results;
- int flags=0;
- const int DATA_SEEN=1;
- const int INDICATOR_SEEN=2;
-
- fprintf(yyout,"{\tPGresult *ECPGresult=ECPGresultByDescriptor(%d, \"%s\");\n"
- ,yylineno,desc_name);
- fputs("\tif (ECPGresult)\n\t{",yyout);
- fprintf(yyout,"\tif (PQntuples(ECPGresult)<1) ECPGraise(%d,ECPG_NOT_FOUND);\n",yylineno);
- fprintf(yyout,"\t\telse if (%s<1 || %s>PQnfields(ECPGresult))\n"
- "\t\t\tECPGraise(%d,ECPG_INVALID_DESCRIPTOR_INDEX);\n"
- ,descriptor_index,descriptor_index,yylineno);
- fputs("\t\telse\n\t\t{\n",yyout);
- for (results=assignments;results!=NULL;results=results->next)
+
+ fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index);
+ for (results = assignments; results != NULL; results = results->next)
{
- if (!strcasecmp(results->value,"type"))
- {
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=ECPGDynamicType(PQftype(ECPGresult,(%s)-1));\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"datetime_interval_code"))
- {
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=ECPGDynamicType_DDT(PQftype(ECPGresult,(%s)-1));\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"length"))
- {
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=PQfmod(ECPGresult,(%s)-1)-VARHDRSZ;\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"octet_length"))
- {
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=PQfsize(ECPGresult,(%s)-1);\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"returned_length")
- || !strcasecmp(results->value,"returned_octet_length"))
- {
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=PQgetlength(ECPGresult,0,(%s)-1);\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"precision"))
- {
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=PQfmod(ECPGresult,(%s)-1)>>16;\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"scale"))
- {
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=(PQfmod(ECPGresult,(%s)-1)-VARHDRSZ)&0xffff;\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"nullable"))
- {
- mmerror(ET_WARN,"nullable is always 1");
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=1;\n");
- }
- else if (!strcasecmp(results->value,"key_member"))
- {
- mmerror(ET_WARN,"key_member is always 0");
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=0;\n");
- }
- else if (!strcasecmp(results->value,"name"))
- {
- fputs("\t\t\tstrncpy(",yyout);
- ECPGstring_buffer(yyout,results->variable);
- fprintf(yyout,",PQfname(ECPGresult,(%s)-1),",descriptor_index);
- ECPGstring_length(yyout,results->variable);
- fputs(");\n",yyout);
- }
- else if (!strcasecmp(results->value,"indicator"))
- {
- flags|=INDICATOR_SEEN;
- fputs("\t\t\t",yyout);
- ECPGnumeric_lvalue(yyout,results->variable);
- fprintf(yyout,"=-PQgetisnull(ECPGresult,0,(%s)-1);\n",descriptor_index);
- }
- else if (!strcasecmp(results->value,"data"))
- {
- flags|=DATA_SEEN;
- ECPGdata_assignment(results->variable,descriptor_index);
- }
- else
+ const struct variable *v = find_variable(results->variable);
+
+ switch (results->value)
{
- snprintf(errortext,sizeof errortext,"unknown descriptor header item '%s'",results->value);
- mmerror(ET_WARN,errortext);
+ case ECPGd_nullable:
+ mmerror(ET_WARN,"nullable is always 1");
+ break;
+ case ECPGd_key_member:
+ mmerror(ET_WARN,"key_member is always 0");
+ break;
+ default:
+ break;
}
- }
- if (flags==DATA_SEEN) /* no indicator */
- {
- fprintf(yyout,"\t\t\tif (PQgetisnull(ECPGresult,0,(%s)-1))\n"
- "\t\t\t\tECPGraise(%d,ECPG_MISSING_INDICATOR);\n"
- ,descriptor_index,yylineno);
+ fprintf(yyout, "%s,", get_dtype(results->value));
+ ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL);
}
drop_assignments();
- fputs("\t\t}\n\t}\n",yyout);
+ fputs("ECPGd_EODT);\n",yyout);
whenever_action(2|1);
}
{"connect", SQL_CONNECT},
{"connection", SQL_CONNECTION},
{"continue", SQL_CONTINUE},
+ {"count", SQL_COUNT},
+ {"data", SQL_DATA},
+ {"datetime_interval_code", SQL_DATETIME_INTERVAL_CODE},
+ {"datetime_interval_precision", SQL_DATETIME_INTERVAL_PRECISION},
{"deallocate", SQL_DEALLOCATE},
{"descriptor", SQL_DESCRIPTOR},
{"disconnect", SQL_DISCONNECT},
{"identified", SQL_IDENTIFIED},
{"indicator", SQL_INDICATOR},
{"int", SQL_INT},
+ {"key_member", SQL_KEY_MEMBER},
+ {"length", SQL_LENGTH},
{"long", SQL_LONG},
+ {"name", SQL_NAME},
+ {"nullable", SQL_NULLABLE},
+ {"octet_length", SQL_OCTET_LENGTH},
{"off", SQL_OFF},
{"open", SQL_OPEN},
{"prepare", SQL_PREPARE},
{"reference", SQL_REFERENCE},
{"release", SQL_RELEASE},
+ {"returned_length", SQL_RETURNED_LENGTH},
+ {"returned_octet_length", SQL_RETURNED_OCTET_LENGTH},
+ {"scale", SQL_SCALE},
{"section", SQL_SECTION},
{"short", SQL_SHORT},
{"signed", SQL_SIGNED},
/* functions */
+extern const char *get_dtype(enum ECPGdtype);
extern void lex_init(void);
extern char *make_str(const char *);
extern void output_line_number(void);
extern ScanKeyword *ScanECPGKeywordLookup(char *);
extern ScanKeyword *ScanCKeywordLookup(char *);
extern void output_get_descr_header(char *);
-extern void output_get_descr(char *);
-extern void push_assignment(char *, char *);
+extern void output_get_descr(char *, char *);
+extern void push_assignment(char *, enum ECPGdtype);
extern struct variable * find_variable(char *);
extern void whenever_action(int);
extern void add_descriptor(char *,char *);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.22 2000/02/15 12:15:54 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.23 2000/02/22 19:57:10 meskes Exp $
*
*-------------------------------------------------------------------------
*/
{"fetch", FETCH},
{"float", FLOAT},
{"for", FOR},
+ {"force", FORCE},
{"foreign", FOREIGN},
{"forward", FORWARD},
{"from", FROM},
{"public", PUBLIC},
{"read", READ},
{"references", REFERENCES},
+ {"reindex", REINDEX},
{"relative", RELATIVE},
{"rename", RENAME},
{"reset", RESET},
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.50 2000/01/27 19:00:39 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.51 2000/02/22 19:57:10 meskes Exp $
*
*-------------------------------------------------------------------------
*/
} stacked_if_value[MAX_NESTED_IF];
%}
+
%option yylineno
%s C SQL incl def def_ident
-/* OK, here is a short description of lex/flex rules behavior.
+
+/*
+ * OK, here is a short description of lex/flex rules behavior.
* The longest pattern which matches an input string is always chosen.
* For equal-length patterns, the first occurring in the rules list is chosen.
- * INITIAL is the starting condition, to which all non-conditional rules apply.
- * When in an exclusive condition, only those rules defined for that condition apply.
+ * INITIAL is the starting state, to which all non-conditional rules apply.
+ * Exclusive states change parsing rules while the state is active. When in
+ * an exclusive state, only those rules defined for that state apply.
*
- * Exclusive states change parsing rules while the state is active.
- * There are exclusive states for quoted strings, extended comments,
- * and to eliminate parsing troubles for numeric strings.
+ * We use exclusive states for quoted strings, extended comments,
+ * and to eliminate parsing troubles for numeric strings.
* Exclusive states:
* <xb> binary numeric string - thomas 1997-11-16
* <xc> extended C-style comments - tgl 1997-07-12
* <xd> delimited identifiers (double-quoted identifiers) - tgl 1997-10-27
* <xh> hexadecimal numeric string - thomas 1997-11-16
* <xq> quoted strings - tgl 1997-07-30
- *
- * The "extended comment" syntax closely resembles allowable operator syntax.
- * So, when in condition <xc>, only strings which would terminate the
- * "extended comment" trigger any action other than "ignore".
- * Be sure to match _any_ candidate comment, including those with appended
- * operator-like symbols. - thomas 1997-07-14
*/
%x xb
*/
xbstart [bB]{quote}
xbstop {quote}
-xbinside [^']*
-xbcat {quote}{space}*\n{space}*{quote}
+xbinside [^']+
+xbcat {quote}{whitespace_with_newline}{quote}
/* Hexadecimal number
*/
xhstart [xX]{quote}
xhstop {quote}
-xhinside [^']*
-xhcat {quote}{space}*\n{space}*{quote}
+xhinside [^']+
+xhcat {quote}{whitespace_with_newline}{quote}
/* C version of hex number
*/
xqstart {quote}
xqstop {quote}
xqdouble {quote}{quote}
-xqinside [^\\']*
+xqinside [^\\']+
xqliteral [\\](.|\n)
-xqcat {quote}{space}*\n{space}*{quote}
+xqcat {quote}{whitespace_with_newline}{quote}
/* Delimited quote
* Allows embedded spaces and other special characters into identifiers.
dquote \"
xdstart {dquote}
xdstop {dquote}
-xdinside [^"]*
+xdinside [^"]+
/* special stuff for C strings */
xdcqq \\\\
xdcother [^"]
xdcinside ({xdcqq}|{xdcqdq}|{xdcother})
-/* Comments
+/* C-Style Comments
* Ignored by the scanner and parser.
+ * The "extended comment" syntax closely resembles allowable operator syntax.
+ * The tricky part here is to get lex to recognize a string starting with
+ * slash-star as a comment, when interpreting it as an operator would produce
+ * a longer match --- remember lex will prefer a longer match! So, we have
+ * to provide a special rule for xcline (a complete comment that could
+ * otherwise look like an operator), as well as append {op_and_self}* to
+ * xcstart so that it matches at least as much as {operator} would.
+ * Then the tie-breaker (first matching rule of same length) wins.
+ * There is still a problem if someone writes, eg, slash-star-star-slash-plus.
+ * It'll be taken as an xcstart, rather than xcline and an operator as one
+ * could wish. I don't see any way around that given lex's behavior;
+ * that someone will just have to write a space after the comment.
*/
-xcline [\/][\*].*[\*][\/]{line_end}+
-xcstart [\/][\*]{op_and_self}*
-xcstop {op_and_self}*[\*][\/]{space_or_nl}*
-xcinside [^*]*
-xcstar [^/]
+xcline \/\*{op_and_self}*\*\/
+xcstart \/\*{op_and_self}*
+xcstop \*+\/
+xcinside ([^*]+)|(\*+[^/])
digit [0-9]
letter [\200-\377_A-Za-z]
param \${integer}
-comment ("--"|"//").*
+/*
+ * In order to make the world safe for Windows and Mac clients as well as
+ * Unix ones, we accept either \n or \r as a newline. A DOS-style \r\n
+ * sequence will be seen as two successive newlines, but that doesn't cause
+ * any problems. SQL92-style comments, which start with -- and extend to the
+ * next newline, are treated as equivalent to a single whitespace character.
+ *
+ * NOTE a fine point: if there is no newline following --, we will absorb
+ * everything to the end of the input as a comment. This is correct. Older
+ * versions of Postgres failed to recognize -- as a comment if the input
+ * did not end with a newline.
+ *
+ * XXX perhaps \f (formfeed) should be treated as a newline as well?
+ */
+
ccomment "//".*\n
space [ \t\r\f]
space_or_nl [ \t\r\f\n]
-line_end {space}*\n
+line_end {space}*\n
+horiz_space [ \t\f]
+newline [\n\r]
+non_newline [^\n\r]
+
+comment (("--"|"//"){non_newline}*)
+
+whitespace ({space}|{comment})
+
+/*
+ * SQL92 requires at least one newline in the whitespace separating
+ * string literals that are to be concatenated. Silly, but who are we
+ * to argue? Note that {whitespace_with_newline} should not have * after
+ * it, whereas {whitespace} should generally have a * after it...
+ */
+
+horiz_whitespace ({horiz_space}|{comment})
+whitespace_with_newline ({horiz_whitespace}*{newline}{whitespace}*)
+
other .
/* some stuff needed for ecpg */
* of escaped-quote "\'".
* Other embedded escaped characters are matched explicitly and the leading
* backslash is dropped from the string. - thomas 1997-09-24
+ * Note that xcline must appear before xcstart, which must appear before
+ * operator, as explained above! Also whitespace (comment) must appear
+ * before operator.
*/
%%
-<SQL>{comment} { /* ignore */ }
+<SQL>{whitespace} { /* ignore */ }
{xcline} { ECHO; }
-<xc>{xcstar} { ECHO; }
{xcstart} {
before_comment = YYSTATE;
ECHO;
addlit(yytext, yyleng);
}
<xh>{xhcat} |
-<xb>{xbcat} {
+<xb>{xbcat} { /* ignore */
}
<SQL>{xhstart} {
<xq>{xqliteral} {
addlit(yytext, yyleng);
}
-<xq>{xqcat} {
+<xq>{xqcat} { /* ignore */
}
<SQL>{xdstart} {
return Op;
}
<SQL>{param} {
- yylval.ival = atoi((char*)&yytext[1]);
+ yylval.ival = atol((char*)&yytext[1]);
return PARAM;
}
<C,SQL>{integer} {
char* endptr;
errno = 0;
- yylval.ival = strtol((char *)yytext,&endptr,10);
+ yylval.ival = strtol((char *)yytext, &endptr,10);
if (*endptr != '\0' || errno == ERANGE)
{
errno = 0;
yylval.str = mm_strdup((char*)yytext);
- return SCONST;
+ return FCONST;
}
return ICONST;
}
{decimal} {
- char* endptr;
-
- if (strlen((char *)yytext) <= 17)
- {
- errno = 0;
- yylval.dval = strtod((char *)yytext,&endptr);
- if (*endptr != '\0' || errno == ERANGE)
- mmerror(ET_ERROR, "Bad float8 input");
- return FCONST;
- }
yylval.str = mm_strdup((char*)yytext);
- return SCONST;
+ return FCONST;
}
<C,SQL>{real} {
- char* endptr;
-
- errno = 0;
- yylval.dval = strtod((char *)yytext,&endptr);
- if (*endptr != '\0' || errno == ERANGE)
- mmerror(ET_ERROR, "Bad float input");
+ yylval.str = mm_strdup((char*)yytext);
return FCONST;
}
<SQL>:{identifier}(("->"|\.){identifier})* {
}
}
}
-<SQL>{space_or_nl} { /* ignore */ }
<SQL>{other} { return yytext[0]; }
<C>{exec_sql} { BEGIN SQL; return SQL_START; }
<C>{ccomment} { /* ignore */ }
int struct_level = 0;
int braces_open; /* brace level counter */
char errortext[128];
-char *descriptor_index= NULL;
char *connection = NULL;
char *input_filename = NULL;
int tagname;
struct this_type type;
enum ECPGttype type_enum;
+ enum ECPGdtype dtype_enum;
struct fetch_desc descriptor;
}
/* special embedded SQL token */
%token SQL_ALLOCATE SQL_AT SQL_AUTOCOMMIT SQL_BOOL SQL_BREAK
-%token SQL_CALL SQL_CONNECT SQL_CONNECTION SQL_CONTINUE
+%token SQL_CALL SQL_CONNECT SQL_CONNECTION SQL_CONTINUE SQL_COUNT
+%token SQL_DATA SQL_DATETIME_INTERVAL_CODE SQL_DATETIME_INTERVAL_PRECISION
%token SQL_DEALLOCATE SQL_DESCRIPTOR SQL_DISCONNECT SQL_ENUM
%token SQL_FOUND SQL_FREE SQL_GET SQL_GO SQL_GOTO
-%token SQL_IDENTIFIED SQL_INDICATOR SQL_INT SQL_LONG
-%token SQL_OFF SQL_OPEN SQL_PREPARE SQL_RELEASE SQL_REFERENCE
-%token SQL_SECTION SQL_SHORT SQL_SIGNED SQL_SQL
+%token SQL_IDENTIFIED SQL_INDICATOR SQL_INT SQL_KEY_MEMBER
+%token SQL_LENGTH SQL_LONG
+%token SQL_NAME SQL_NULLABLE
+%token SQL_OCTET_LENGTH SQL_OFF SQL_OPEN SQL_PREPARE
+%token SQL_RELEASE SQL_REFERENCE SQL_RETURNED_LENGTH
+%token SQL_RETURNED_OCTET_LENGTH
+%token SQL_SCALE SQL_SECTION SQL_SHORT SQL_SIGNED SQL_SQL
%token SQL_SQLERROR SQL_SQLPRINT
%token SQL_SQLWARNING SQL_START SQL_STOP SQL_STRUCT SQL_UNSIGNED
%token SQL_VALUE SQL_VAR SQL_WHENEVER
CACHE, CLUSTER, COMMENT, COPY, CREATEDB, CREATEUSER, CYCLE,
DATABASE, DELIMITERS, DO,
EACH, ENCODING, EXCLUSIVE, EXPLAIN, EXTEND,
- FORWARD, FUNCTION, HANDLER,
+ FORCE, FORWARD, FUNCTION, HANDLER,
INCREMENT, INDEX, INHERITS, INSTEAD, ISNULL,
LANCOMPILER, LIMIT, LISTEN, UNLISTEN, LOAD, LOCATION, LOCK_P,
MAXVALUE, MINVALUE, MODE, MOVE,
NEW, NOCREATEDB, NOCREATEUSER, NONE, NOTHING, NOTIFY, NOTNULL,
OFFSET, OIDS, OPERATOR, PASSWORD, PROCEDURAL,
- RENAME, RESET, RETURNS, ROW, RULE,
+ REINDEX, RENAME, RESET, RETURNS, ROW, RULE,
SEQUENCE, SERIAL, SETOF, SHARE, SHOW, START, STATEMENT, STDIN, STDOUT, SYSID
TRUNCATE, TRUSTED,
UNLISTEN, UNTIL, VACUUM, VALID, VERBOSE, VERSION
%type <str> Iconst Fconst Sconst TransactionStmt CreateStmt UserId
%type <str> CreateAsElement OptCreateAs CreateAsList CreateAsStmt
-%type <str> OptInherit key_reference key_action comment_text
+%type <str> OptInherit key_reference comment_text
%type <str> key_match ColLabel SpecialRuleRelation ColId columnDef
%type <str> ColConstraint ColConstraintElem NumericOnly FloatOnly
%type <str> OptTableElementList OptTableElement TableConstraint
-%type <str> ConstraintElem key_actions ColPrimaryKey ColQualList
+%type <str> ConstraintElem key_actions ColQualList
%type <str> target_list target_el update_target_list alias_clause
%type <str> update_target_el opt_id relation_name database_name
%type <str> access_method attr_name class index_name name func_name
%type <str> func_args_list func_args opt_with ProcedureStmt def_arg
%type <str> def_elem def_list definition def_name def_type DefineStmt
%type <str> opt_instead event event_object RuleActionList opt_using
-%type <str> RuleActionStmtOrEmpty RuleActionMulti func_as
+%type <str> RuleActionStmtOrEmpty RuleActionMulti func_as reindex_type
%type <str> RuleStmt opt_column opt_name oper_argtypes sysid_clause
%type <str> MathOp RemoveFuncStmt aggr_argtype for_update_clause
%type <str> RemoveAggrStmt remove_type RemoveStmt ExtendStmt
%type <str> GrantStmt privileges operation_commalist operation
%type <str> opt_cursor opt_lmode ConstraintsSetStmt comment_tg
%type <str> case_expr when_clause_list case_default case_arg when_clause
-%type <str> select_clause opt_select_limit select_limit_value
-%type <str> select_offset_value using_expr join_expr
+%type <str> select_clause opt_select_limit select_limit_value TimeClause
+%type <str> select_offset_value using_expr join_expr ReindexStmt
%type <str> using_list from_expr join_clause join_type
%type <str> join_qual update_list join_clause join_clause_with_union
%type <str> opt_level opt_lock lock_type users_in_new_group_clause
-%type <str> OptConstrFromTable comment_op ConstraintAttributeSpec
+%type <str> OptConstrFromTable comment_op ConstraintAttribute
%type <str> constraints_set_list constraints_set_namelist comment_fn
%type <str> constraints_set_mode comment_type comment_cl comment_ag
-%type <str> ConstraintDeferrabilitySpec ConstraintTimeSpec
-%type <str> CreateGroupStmt AlterGroupStmt DropGroupStmt
-%type <str> ColConstraintWithNull ColConstraintElemWithNull
-%type <str> join_expr_with_union
+%type <str> CreateGroupStmt AlterGroupStmt DropGroupStmt key_delete
+%type <str> ColConstraintWithNull ColConstraintElemWithNull NotNull
+%type <str> join_expr_with_union DefaultClause DefaultExpr PrimaryKey
+%type <str> DeferrabilityClause opt_force key_update
/***
#ifdef ENABLE_ORACLE_JOIN_SYNTAX
%type <str> oracle_list oracle_expr oracle_outer
%type <str> struct_type s_struct declaration declarations variable_declarations
%type <str> s_struct s_union union_type ECPGSetAutocommit on_off
%type <str> ECPGAllocateDescr ECPGDeallocateDescr
-%type <str> ECPGGetDescriptor ECPGGetDescriptorHeader
+%type <str> ECPGGetDescriptorHeader
-%type <descriptor> ECPGFetchDescStmt
+%type <descriptor> ECPGFetchDescStmt ECPGGetDescriptor
%type <type_enum> simple_type signed_type unsigned_type varchar_type
+%type <dtype_enum> descriptor_item desc_header_item
+
%type <type> type
%type <action> action
| UnlistenStmt { output_statement($1, 0, NULL); }
| LockStmt { output_statement($1, 0, NULL); }
| ProcedureStmt { output_statement($1, 0, NULL); }
+ | ReindexStmt { output_statement($1, 0, NULL); }
| RemoveAggrStmt { output_statement($1, 0, NULL); }
| RemoveOperStmt { output_statement($1, 0, NULL); }
| RemoveFuncStmt { output_statement($1, 0, NULL); }
free($1);
}
| ECPGExecute { output_statement($1, 0, NULL); }
- | ECPGFetchDescStmt { output_statement($1.str, 1, $1.name); }
+ | ECPGFetchDescStmt {
+ output_statement($1.str, 1, $1.name);
+ free($1.str);
+ free($1.name);
+ }
| ECPGFree {
fprintf(yyout, "{ ECPGdeallocate(__LINE__, \"%s\");", $1);
free($1);
}
| ECPGGetDescriptor {
- lookup_descriptor($1,connection);
- output_get_descr($1);
+ lookup_descriptor($1.name, connection);
+ output_get_descr($1.name, $1.str);
+ free($1.name);
+ free($1.str);
}
| ECPGGetDescriptorHeader {
- lookup_descriptor($1,connection);
+ lookup_descriptor($1, connection);
output_get_descr_header($1);
+ free($1);
}
| ECPGOpen {
struct cursor *ptr;
| TableConstraint { $$ = $1; }
;
-columnDef: ColId Typename ColQualifier
+columnDef: ColId Typename ColQualifier opt_collate
{
- $$ = cat_str(3, $1, $2, $3);
+ if (strlen($4) > 0)
+ {
+ sprintf(errortext, "CREATE TABLE/COLLATE %s not yet implemented; clause ignored", $4);
+ mmerror(ET_WARN, errortext);
+ }
+ $$ = cat_str(4, $1, $2, $3, $4);
}
- | ColId SERIAL ColPrimaryKey
+ | ColId SERIAL ColQualifier opt_collate
{
- $$ = cat_str(3, $1, make_str(" serial "), $3);
+ if (strlen($4) > 0)
+ {
+ sprintf(errortext, "CREATE TABLE/COLLATE %s not yet implemented; clause ignored", $4);
+ mmerror(ET_WARN, errortext);
+ }
+ $$ = cat_str(4, $1, make_str(" serial "), $3, $4);
}
;
-ColQualifier: ColQualList { $$ = $1; }
- | NULL_P ColQualListWithNull { $$ = cat2_str(make_str("null"), $2); }
- | NULL_P { $$ = make_str("null"); }
- | /*EMPTY*/ { $$ = EMPTY; }
+/*
+ * ColQualifier encapsulates an entire column qualification,
+ * including DEFAULT, constraints, and constraint attributes.
+ * Note that the DefaultClause handles the empty case.
+ */
+ColQualifier: DefaultClause ColQualList { $$ = cat2_str($1, $2); }
+ | NotNull DefaultClause ColQualListWithNull { $$ = cat_str(3, $1, $2, $3); }
+ | DefaultExpr NotNull ColQualListWithNull { $$ = cat_str(3, $1, $2, $3); }
+ | DefaultExpr NotNull { $$ = cat2_str($1, $2); }
+ | NotNull DefaultClause { $$ = cat2_str($1, $2); }
+ | NULL_P DefaultClause ColQualListWithNull { $$ = cat_str(3, make_str("null"), $2, $3); }
+ | NULL_P DefaultClause { $$ = cat2_str(make_str("null"), $2); }
+ | DefaultClause { $$ = $1; }
+ ;
+
+/*
+ * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
+ * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
+ * or be part of a_expr NOT LIKE or similar constructs).
+ */
+DefaultClause: DefaultExpr { $$ = $1; }
+ | /*EMPTY*/ { $$ = EMPTY; }
+ ;
+
+DefaultExpr: DEFAULT NULL_P { $$ = make_str("default null"); }
+ | DEFAULT b_expr { $$ = cat2_str(make_str("default"), $2); }
;
ColQualList: ColQualList ColConstraint { $$ = cat2_str($1,$2); }
| ColConstraint { $$ = $1; }
;
-ColQualListWithNull: ColQualListWithNull ColConstraintWithNull
+ColQualListWithNull: ColConstraintWithNull ColQualListWithNull
{ $$ = cat2_str($1, $2); }
| ColConstraintWithNull
{ $$ = $1; }
-ColPrimaryKey: PRIMARY KEY
- {
- $$ = make_str("primary key");
- }
- | /*EMPTY*/
- {
- $$ = EMPTY;
- }
- ;
-ColConstraint:
- CONSTRAINT name ColConstraintElem
+ColConstraint: CONSTRAINT name ColConstraintElem
{
$$ = cat_str(3, make_str("constraint"), $2, $3);
}
{ $$ = $1; }
;
-ColConstraintWithNull:
- CONSTRAINT name ColConstraintElemWithNull
+ColConstraintWithNull: CONSTRAINT name ColConstraintElemWithNull
{ $$ = cat_str(3, make_str("constraint"), $2, $3); }
| ColConstraintElemWithNull
{ $$ = $1; }
* that a column may have that value. WITH NULL leads to
* shift/reduce conflicts with WITH TIME ZONE anyway.
* - thomas 1999-01-08
- *
- * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
- * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
- * or be part of a_expr NOT LIKE or similar constructs).
*/
ColConstraintElem: ColConstraintElemWithNull
{
$$ = $1;
}
- | NOT NULL_P
- {
- $$ = make_str("not null");
- }
| UNIQUE
{
$$ = make_str("unique");
}
- | PRIMARY KEY
+ | PrimaryKey
{
- $$ = make_str("primary key");
+ $$ = $1;
}
;
{
$$ = cat_str(3, make_str("check("), $3, make_str(")"));
}
- | DEFAULT NULL_P
- {
- $$ = make_str("default null");
- }
- | DEFAULT b_expr
+ | REFERENCES ColId opt_column_list
+ key_match key_actions ConstraintAttribute
{
- $$ = cat2_str(make_str("default"), $2);
+ $$ = cat_str(6, make_str("references"), $2, $3, $4, $5, $6);
}
- | REFERENCES ColId opt_column_list key_match key_actions
+ | REFERENCES ColId opt_column_list
+ key_match key_actions
{
$$ = cat_str(5, make_str("references"), $2, $3, $4, $5);
}
;
+PrimaryKey: PRIMARY KEY { $$ = make_str("primary key"); }
+
+NotNull: NOT NULL_P { $$ = make_str("not null"); }
+
/* ConstraintElem specifies constraint syntax which is not embedded into
* a column definition. ColConstraintElem specifies the embedded form.
* - thomas 1997-12-03
{
$$ = cat_str(3, make_str("unique("), $3, make_str(")"));
}
- | PRIMARY KEY '(' columnList ')'
+ | PrimaryKey '(' columnList ')'
+ {
+ $$ = cat_str(3, make_str("primary key("), $3, make_str(")"));
+ }
+ | FOREIGN KEY '(' columnList ')' REFERENCES ColId opt_column_list
+ key_match key_actions ConstraintAttribute
{
- $$ = cat_str(3, make_str("primary key("), $4, make_str(")"));
+ $$ = cat_str(8, make_str("foreign key("), $4, make_str(") references"), $7, $8, $9, $10, $11);
}
- | FOREIGN KEY '(' columnList ')' REFERENCES ColId opt_column_list key_match key_actions
+ | FOREIGN KEY '(' columnList ')' REFERENCES ColId opt_column_list
+ key_match key_actions
{
$$ = cat_str(7, make_str("foreign key("), $4, make_str(") references"), $7, $8, $9, $10);
}
}
| MATCH PARTIAL
{
- mmerror(ET_WARN, "FOREIGN KEY match type PARTIAL not implemented yet");
+ mmerror(ET_WARN, "FOREIGN KEY/MATCH PARTIAL not yet implemented");
$$ = make_str("match partial");
}
| /*EMPTY*/
}
;
-key_actions: key_action key_action { $$ = cat2_str($1, $2); }
- | key_action { $$ = $1; }
+key_actions: key_delete { $$ = $1; }
+ | key_update { $$ = $1; }
+ | key_delete key_update { $$ = cat2_str($1, $2); }
+ | key_update key_delete { $$ = cat2_str($1, $2); }
| /*EMPTY*/ { $$ = EMPTY; }
;
-key_action: ON DELETE key_reference { $$ = cat2_str(make_str("on delete"), $3); }
- | ON UPDATE key_reference { $$ = cat2_str(make_str("on update"), $3); }
- ;
+key_delete: ON DELETE key_reference { $$ = cat2_str(make_str("on delete"), $3); }
+
+key_update: ON UPDATE key_reference { $$ = cat2_str(make_str("on update"), $3); }
key_reference: NO ACTION { $$ = make_str("no action"); }
| RESTRICT { $$ = make_str("restrict"); }
}
| CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
relation_name OptConstrFromTable
- ConstraintAttributeSpec
+ ConstraintAttribute
FOR EACH ROW EXECUTE PROCEDURE
name '(' TriggerFuncArgs ')'
{
}
;
-ConstraintAttributeSpec: ConstraintDeferrabilitySpec
+ConstraintAttribute: DeferrabilityClause
{ $$ = $1; }
- | ConstraintDeferrabilitySpec ConstraintTimeSpec
+ | TimeClause
+ { $$ = $1; }
+ | DeferrabilityClause TimeClause
{
if (strcmp($1, "deferrable") != 0 && strcmp($2, "initially deferrable") == 0 )
mmerror(ET_ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
$$ = cat2_str($1, $2);
}
- | ConstraintTimeSpec
- { $$ = $1; }
- | ConstraintTimeSpec ConstraintDeferrabilitySpec
+ | TimeClause DeferrabilityClause
{
if (strcmp($2, "deferrable") != 0 && strcmp($1, "initially deferrable") == 0 )
mmerror(ET_ERROR, "INITIALLY DEFERRED constraint must be DEFERRABLE");
$$ = cat2_str($1, $2);
}
- | /* Empty */
- { $$ = 0; }
;
-ConstraintDeferrabilitySpec: NOT DEFERRABLE
- {
- $$ = make_str("not deferrable");
- }
- | DEFERRABLE
- {
- $$ = make_str("deferrable");
- }
+DeferrabilityClause: NOT DEFERRABLE { $$ = make_str("not deferrable"); }
+ | DEFERRABLE { $$ = make_str("deferrable"); }
;
-ConstraintTimeSpec: INITIALLY IMMEDIATE
- {
- $$ = make_str("initially immediate");
- }
- | INITIALLY DEFERRED
- {
- $$ = make_str("initially deferrable");
- }
+TimeClause: INITIALLY IMMEDIATE { $$ = make_str("initially immediate"); }
+ | INITIALLY DEFERRED { $$ = make_str("initially deferrable"); }
;
DropTrigStmt: DROP TRIGGER name ON relation_name
{ $$ = cat2_str($1, make_str(", none")); }
;
+/*****************************************************************************
+ *
+ * QUERY:
+ *
+ * REINDEX type <typename> [FORCE] [ALL]
+ *
+ *****************************************************************************/
+ReindexStmt: REINDEX reindex_type name opt_force
+ {
+ $$ = cat_str(4, make_str("reindex"), $2, $3, $4);
+ }
+
+reindex_type: INDEX { $$ = make_str("index"); }
+ | TABLE { $$ = make_str("table"); }
+ | DATABASE { $$ = make_str("database"); }
+ ;
+opt_force: FORCE { $$ = make_str("force"); }
+ | /* EMPTY */ { $$ = EMPTY; }
+ ;
/*****************************************************************************
*
| SQL_CONNECT { $$ = make_str("connect"); }
| SQL_CONNECTION { $$ = make_str("connection"); }
| SQL_CONTINUE { $$ = make_str("continue"); }
+ | SQL_COUNT { $$ = make_str("count"); }
+ | SQL_DATA { $$ = make_str("data"); }
+ | SQL_DATETIME_INTERVAL_CODE { $$ = make_str("datetime_interval_code"); }
+ | SQL_DATETIME_INTERVAL_PRECISION { $$ = make_str("datetime_interval_precision"); }
| SQL_DEALLOCATE { $$ = make_str("deallocate"); }
| SQL_DISCONNECT { $$ = make_str("disconnect"); }
| SQL_FOUND { $$ = make_str("found"); }
| SQL_IDENTIFIED { $$ = make_str("identified"); }
| SQL_INDICATOR { $$ = make_str("indicator"); }
| SQL_INT { $$ = make_str("int"); }
+ | SQL_KEY_MEMBER { $$ = make_str("key_member"); }
+ | SQL_LENGTH { $$ = make_str("length"); }
| SQL_LONG { $$ = make_str("long"); }
+ | SQL_NAME { $$ = make_str("name"); }
+ | SQL_NULLABLE { $$ = make_str("nullable"); }
+ | SQL_OCTET_LENGTH { $$ = make_str("octet_length"); }
| SQL_OFF { $$ = make_str("off"); }
| SQL_OPEN { $$ = make_str("open"); }
| SQL_PREPARE { $$ = make_str("prepare"); }
| SQL_RELEASE { $$ = make_str("release"); }
+ | SQL_RETURNED_LENGTH { $$ = make_str("returned_length"); }
+ | SQL_RETURNED_OCTET_LENGTH { $$ = make_str("returned_octet_length"); }
+ | SQL_SCALE { $$ = make_str("scale"); }
| SQL_SECTION { $$ = make_str("section"); }
| SQL_SHORT { $$ = make_str("short"); }
| SQL_SIGNED { $$ = make_str("signed"); }
}
;
-character: CHARACTER opt_varying opt_charset opt_collate
+character: CHARACTER opt_varying opt_charset
{
- if (strlen($4) > 0)
- {
- sprintf(errortext, "COLLATE %s not yet implemented", $4);
- mmerror(ET_WARN, errortext);
- }
-
- $$ = cat_str(4, make_str("character"), $2, $3, $4);
+ $$ = cat_str(3, make_str("character"), $2, $3);
}
| CHAR opt_varying { $$ = cat2_str(make_str("char"), $2); }
| VARCHAR { $$ = make_str("varchar"); }
{ $$ = cat2_str($1, make_str("()")); }
| func_name '(' expr_list ')'
{ $$ = cat_str(4, $1, make_str("("), $3, make_str(")")); }
+ | func_name '(' ALL expr_list ')'
+ { $$ = cat_str(4, $1, make_str("( all"), $4, make_str(")")); }
| func_name '(' DISTINCT expr_list ')'
{ $$ = cat_str(4, $1, make_str("( distinct"), $4, make_str(")")); }
| func_name '(' '*' ')'
| SQL_CALL { $$ = make_str("call"); }
| SQL_CONNECT { $$ = make_str("connect"); }
| SQL_CONTINUE { $$ = make_str("continue"); }
+ | SQL_COUNT { $$ = make_str("count"); }
+ | SQL_DATA { $$ = make_str("data"); }
+ | SQL_DATETIME_INTERVAL_CODE { $$ = make_str("datetime_interval_code"); }
+ | SQL_DATETIME_INTERVAL_PRECISION { $$ = make_str("datetime_interval_precision"); }
| SQL_DEALLOCATE { $$ = make_str("deallocate"); }
| SQL_DISCONNECT { $$ = make_str("disconnect"); }
| SQL_FOUND { $$ = make_str("found"); }
| SQL_IDENTIFIED { $$ = make_str("identified"); }
| SQL_INDICATOR { $$ = make_str("indicator"); }
| SQL_INT { $$ = make_str("int"); }
+ | SQL_KEY_MEMBER { $$ = make_str("key_member"); }
+ | SQL_LENGTH { $$ = make_str("length"); }
| SQL_LONG { $$ = make_str("long"); }
+ | SQL_NAME { $$ = make_str("name"); }
+ | SQL_NULLABLE { $$ = make_str("nullable"); }
+ | SQL_OCTET_LENGTH { $$ = make_str("octet_length"); }
| SQL_OFF { $$ = make_str("off"); }
| SQL_OPEN { $$ = make_str("open"); }
| SQL_PREPARE { $$ = make_str("prepare"); }
| SQL_RELEASE { $$ = make_str("release"); }
+ | SQL_RETURNED_LENGTH { $$ = make_str("returned_length"); }
+ | SQL_RETURNED_OCTET_LENGTH { $$ = make_str("returned_octet_length"); }
+ | SQL_SCALE { $$ = make_str("scale"); }
| SQL_SECTION { $$ = make_str("section"); }
| SQL_SHORT { $$ = make_str("short"); }
| SQL_SIGNED { $$ = make_str("signed"); }
* read from descriptor
*/
-ECPGGetDescHeaderItem: cvariable '=' ident {
- push_assignment($1,$3);
+ECPGGetDescHeaderItem: cvariable '=' desc_header_item {
+ push_assignment($1, $3);
}
-ECPGGetDescItem: cvariable '=' ident {
- push_assignment($1,$3);
-}
- | cvariable '=' TYPE_P {
- push_assignment($1,"type");
-}
- | cvariable '=' PRECISION {
- push_assignment($1,"precision");
-}
- | cvariable '=' SQL_INDICATOR {
- push_assignment($1,"indicator");
+desc_header_item: SQL_COUNT { $$ = ECPGd_count; }
+
+ECPGGetDescItem: cvariable '=' descriptor_item {
+ push_assignment($1, $3);
}
+descriptor_item: SQL_DATA { $$ = ECPGd_data; }
+ | SQL_DATETIME_INTERVAL_CODE { $$ = ECPGd_di_code; }
+ | SQL_DATETIME_INTERVAL_PRECISION { $$ = ECPGd_di_precision; }
+ | SQL_INDICATOR { $$ = ECPGd_indicator; }
+ | SQL_KEY_MEMBER { $$ = ECPGd_key_member; }
+ | SQL_LENGTH { $$ = ECPGd_length; }
+ | SQL_NAME { $$ = ECPGd_name; }
+ | SQL_NULLABLE { $$ = ECPGd_nullable; }
+ | SQL_OCTET_LENGTH { $$ = ECPGd_octet; }
+ | PRECISION { $$ = ECPGd_precision; }
+ | SQL_RETURNED_LENGTH { $$ = ECPGd_length; }
+ | SQL_RETURNED_OCTET_LENGTH { $$ = ECPGd_ret_octet; }
+ | SQL_SCALE { $$ = ECPGd_scale; }
+ | TYPE_P { $$ = ECPGd_type; }
+ ;
+
ECPGGetDescHeaderItems: ECPGGetDescHeaderItem
| ECPGGetDescHeaderItems ',' ECPGGetDescHeaderItem;
{ $$ = $3; }
ECPGGetDescriptor: SQL_GET SQL_DESCRIPTOR ident SQL_VALUE cvariable ECPGGetDescItems
- { $$ = $3; descriptor_index = $5; }
+ { $$.str = $5; $$.name = $3; }
| SQL_GET SQL_DESCRIPTOR ident SQL_VALUE Iconst ECPGGetDescItems
- { $$ = $3; descriptor_index = $5; }
+ { $$.str = $5; $$.name = $3; }
/*****************************************************************************
*
* C stuff
*/
-symbol: IDENT { $$ = $1; }
+symbol: ident { $$ = $1; }
cpp_line: CPP_LINE { $$ = $1; }
return ("ECPGt_NO_INDICATOR");
break;
case ECPGt_char_variable: /* string that should not be
- * quoted */
+ * quoted */
return ("ECPGt_char_variable");
break;
default:
void
ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *ind_name, struct ECPGtype * ind_typ, const char *prefix, const char *ind_prefix)
{
+#if 0
if (ind_typ == NULL)
{
ind_typ = &ecpg_no_indicator;
ind_name = "no_indicator";
}
-
+#endif
switch (typ->typ)
{
case ECPGt_array:
break;
default:
ECPGdump_a_simple(o, name, typ->typ, typ->size, -1, NULL, prefix);
- ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
+ if (ind_typ != NULL)
+ ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
break;
}
}
}
free(typ);
}
+
+const char *
+get_dtype(enum ECPGdtype typ)
+{
+ switch (typ)
+ {
+ case ECPGd_count:
+ return ("ECPGd_countr");
+ break;
+ case ECPGd_data:
+ return ("ECPGd_data");
+ break;
+ case ECPGd_di_code:
+ return ("ECPGd_di_code");
+ break;
+ case ECPGd_di_precision:
+ return ("ECPGd_di_precision");
+ break;
+ case ECPGd_indicator:
+ return ("ECPGd_indicator");
+ break;
+ case ECPGd_key_member:
+ return ("ECPGd_key_member");
+ break;
+ case ECPGd_length:
+ return ("ECPGd_length");
+ break;
+ case ECPGd_name:
+ return ("ECPGd_name");
+ break;
+ case ECPGd_nullable:
+ return ("ECPGd_nullable");
+ break;
+ case ECPGd_octet:
+ return ("ECPGd_octet");
+ break;
+ case ECPGd_precision:
+ return ("ECPGd_precision");
+ break;
+ case ECPGd_ret_length:
+ return ("ECPGd_ret_length");
+ case ECPGd_ret_octet:
+ return ("ECPGd_ret_octet");
+ break;
+ case ECPGd_scale:
+ return ("ECPGd_scale");
+ break;
+ case ECPGd_type:
+ return ("ECPGd_type");
+ break;
+ default:
+ sprintf(errortext, "illegal descriptor item %d\n", typ);
+ yyerror(errortext);
+ }
+
+ return NULL;
+}
struct assignment
{
- char *variable;
- char *value;
- struct assignment *next;
+ char *variable;
+ enum ECPGdtype value;
+ struct assignment *next;
};
enum errortype {ET_WARN, ET_ERROR, ET_FATAL};
/* Then the current element and its indicator */
ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
- (list->indicator->type->typ != ECPGt_NO_INDICATOR) ? list->indicator->name : NULL,
- (list->indicator->type->typ != ECPGt_NO_INDICATOR) ? list->indicator->type : NULL, NULL, NULL);
+/* (list->indicator->type->typ != ECPGt_NO_INDICATOR) ? list->indicator->name : NULL,
+ (list->indicator->type->typ != ECPGt_NO_INDICATOR) ? list->indicator->type : NULL, NULL, NULL);*/
+ list->indicator->name, list->indicator->type, NULL, NULL);
/* Then release the list element. */
if (mode != 0)
*
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest.pgc,v 1.2 2000/02/17 19:48:58 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest.pgc,v 1.3 2000/02/22 19:57:12 meskes Exp $
*/
#include <stdio.h>
char QUERY[1024];
exec sql end declare section;
int done=0;
+ FILE *dbgs;
+
+ if ((dbgs = fopen("log", "w")) != NULL)
+ ECPGdebug(1, dbgs);
snprintf(QUERY,sizeof QUERY,"select * from %s",argc>1?argv[1]:"pg_tables");
exec sql close MYCURS;
exec sql deallocate descriptor MYDESC;
+
+ if (dbgs != NULL)
+ fclose(dbgs);
+
return 0;
}
strcpy(msg, "insert");
exec sql insert into meskes(name, married, children) values ('Petra', '19900404', 3);
- exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 33, '19900404', 3);
- exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8);
+ exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 34, '19900404', 3);
+ exec sql insert into meskes(name, born, age) values ('Carsten', 19910103,9);
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 6);
exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 2);
strcpy(msg, "insert");
exec sql insert into meskes(name, married, children) values (:wifesname, '19900404', 3);
- exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 33, '19900404', 3);
- exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8);
+ exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 34, '19900404', 3);
+ exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 9);
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 6);
exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 2);