Commit 991b9740 authored by Michael Meskes's avatar Michael Meskes

*** empty log message ***

parent 62f06459
......@@ -819,5 +819,10 @@ Thu Feb 17 19:37:44 CET 2000
- 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.
......@@ -28,6 +28,8 @@ instead of libpq so we can write backend functions using ecpg.
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
......@@ -32,6 +32,8 @@
/* 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
......
......@@ -61,6 +61,7 @@ extern "C"
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
......
......@@ -49,6 +49,26 @@ extern "C"
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)
......
......@@ -6,7 +6,7 @@
# 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 $
#
#-------------------------------------------------------------------------
......@@ -23,7 +23,7 @@ ifdef KRBVERS
CFLAGS+= $(KRBFLAGS)
endif
OBJS= ecpglib.o typename.o
OBJS= ecpglib.o typename.o descriptor.o
SHLIB_LINK= -L../../libpq -lpq
......
......@@ -10,6 +10,157 @@ ECPGget_desc_header(int lineno, char * desc_name, int *count)
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);
}
......@@ -2,7 +2,7 @@
*
* 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 */
......@@ -198,7 +198,7 @@ bool ECPGdo_descriptor(int line,const char *connection,
/* free previous result */
if (i->result) PQclear(i->result);
i->result=NULL;
i->result=NULL;
status=do_descriptor2(line,connection,&i->result,query);
......@@ -206,7 +206,8 @@ bool ECPGdo_descriptor(int line,const char *connection,
return (status);
}
}
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, descriptor);
return false;
}
......@@ -219,7 +220,7 @@ PGresult *ECPGresultByDescriptor(int line,const char *name)
if (!strcmp(name, i->name)) return i->result;
}
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
return NULL;
}
......@@ -238,7 +239,7 @@ bool ECPGdeallocate_desc(int line,const char *name)
return true;
}
}
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, NULL);
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
return false;
}
......@@ -259,7 +260,7 @@ ECPGraise(int line, int code, const char *str)
{
struct auto_mem *am;
sqlca.sqlcode=code;
sqlca.sqlcode = code;
switch (code)
{
case ECPG_NOT_FOUND:
......@@ -294,15 +295,25 @@ ECPGraise(int line, int code, const char *str)
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;
......
......@@ -190,7 +190,7 @@ ecpg_alloc(long size, int lineno)
if (!new)
{
ECPGlog("out of memory\n");
ECPGraise(ECPG_OUT_OF_MEMORY, lineno, NULL);
ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL);
return NULL;
}
......@@ -206,7 +206,7 @@ ecpg_strdup(const char *string, int lineno)
if (!new)
{
ECPGlog("out of memory\n");
ECPGraise(ECPG_OUT_OF_MEMORY, lineno, NULL);
ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL);
return NULL;
}
......@@ -634,7 +634,7 @@ ECPGexecute(struct statement * stmt)
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;
}
......@@ -657,7 +657,7 @@ ECPGexecute(struct statement * stmt)
* 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
......@@ -694,7 +694,7 @@ ECPGexecute(struct statement * stmt)
/* 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;
}
......@@ -742,7 +742,7 @@ ECPGexecute(struct statement * stmt)
{
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;
}
......@@ -756,7 +756,7 @@ ECPGexecute(struct statement * stmt)
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);
}
......@@ -778,7 +778,7 @@ ECPGexecute(struct statement * stmt)
{
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;
}
......@@ -853,7 +853,7 @@ ECPGexecute(struct statement * stmt)
}
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;
}
......@@ -1057,7 +1057,7 @@ ECPGexecute(struct statement * stmt)
break;
default:
ECPGraise(ECPG_UNSUPPORTED, stmt->lineno, ECPGtype_name(var->type));
ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, ECPGtype_name(var->type));
status = false;
break;
}
......@@ -1067,7 +1067,7 @@ ECPGexecute(struct statement * stmt)
if (status && var != NULL)
{
ECPGraise(ECPG_TOO_MANY_ARGUMENTS, stmt->lineno, NULL);
ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, NULL);
status = false;
}
......@@ -1123,7 +1123,7 @@ ECPGexecute(struct statement * stmt)
}
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;
......
......@@ -11,15 +11,14 @@
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;
}
......@@ -32,7 +31,6 @@ drop_assignments(void)
assignments = old_head->next;
free(old_head->variable);
free(old_head->value);
free(old_head);
}
}
......@@ -61,7 +59,7 @@ static void ECPGnumeric_lvalue(FILE *f,char *name)
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)
{
......@@ -177,17 +175,18 @@ static struct descriptor *descriptors;
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
......@@ -217,13 +216,13 @@ drop_descriptor(char *name,char *connection)
}
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
......@@ -233,8 +232,8 @@ struct descriptor
}
}
}
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;
}
......@@ -246,10 +245,11 @@ output_get_descr_header(char *desc_name)
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);
}
}
......@@ -260,114 +260,31 @@ output_get_descr_header(char *desc_name)
}
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);
}
......@@ -28,6 +28,10 @@ static ScanKeyword ScanKeywords[] = {
{"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},
......@@ -40,12 +44,20 @@ static ScanKeyword ScanKeywords[] = {
{"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},
......
......@@ -35,6 +35,7 @@ extern struct descriptor *descriptors;
/* 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);
......@@ -50,8 +51,8 @@ extern void mmerror(enum errortype, char * );
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 *);
......
......@@ -8,7 +8,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -108,6 +108,7 @@ static ScanKeyword ScanKeywords[] = {
{"fetch", FETCH},
{"float", FLOAT},
{"for", FOR},
{"force", FORCE},
{"foreign", FOREIGN},
{"forward", FORWARD},
{"from", FROM},
......@@ -197,6 +198,7 @@ static ScanKeyword ScanKeywords[] = {
{"public", PUBLIC},
{"read", READ},
{"references", REFERENCES},
{"reindex", REINDEX},
{"relative", RELATIVE},
{"rename", RENAME},
{"reset", RESET},
......
......@@ -12,7 +12,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -70,29 +70,26 @@ static struct _if_value {
} 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
......@@ -109,15 +106,15 @@ static struct _if_value {
*/
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
*/
......@@ -131,9 +128,9 @@ quote '
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.
......@@ -141,7 +138,7 @@ xqcat {quote}{space}*\n{space}*{quote}
dquote \"
xdstart {dquote}
xdstop {dquote}
xdinside [^"]*
xdinside [^"]+
/* special stuff for C strings */
xdcqq \\\\
......@@ -149,14 +146,25 @@ xdcqdq \\\"
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]
......@@ -181,12 +189,44 @@ real ((({digit}*\.{digit}+)|({digit}+\.{digit}*)|({digit}+))([Ee][-+]?{digit}+
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 */
......@@ -217,14 +257,16 @@ cppline {space}*#(.*\\{line_end})*.*
* 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;
......@@ -254,7 +296,7 @@ cppline {space}*#(.*\\{line_end})*.*
addlit(yytext, yyleng);
}
<xh>{xhcat} |
<xb>{xbcat} {
<xb>{xbcat} { /* ignore */
}
<SQL>{xhstart} {
......@@ -286,7 +328,7 @@ cppline {space}*#(.*\\{line_end})*.*
<xq>{xqliteral} {
addlit(yytext, yyleng);
}
<xq>{xqcat} {
<xq>{xqcat} { /* ignore */
}
<SQL>{xdstart} {
......@@ -331,43 +373,28 @@ cppline {space}*#(.*\\{line_end})*.*
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})* {
......@@ -433,7 +460,6 @@ cppline {space}*#(.*\\{line_end})*.*
}
}
}
<SQL>{space_or_nl} { /* ignore */ }
<SQL>{other} { return yytext[0]; }
<C>{exec_sql} { BEGIN SQL; return SQL_START; }
<C>{ccomment} { /* ignore */ }
......
This diff is collapsed.
......@@ -163,7 +163,7 @@ get_type(enum ECPGttype typ)
return ("ECPGt_NO_INDICATOR");
break;
case ECPGt_char_variable: /* string that should not be
* quoted */
* quoted */
return ("ECPGt_char_variable");
break;
default:
......@@ -198,12 +198,13 @@ static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, l
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:
......@@ -248,7 +249,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in
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;
}
}
......@@ -399,3 +401,60 @@ ECPGfree_type(struct ECPGtype * typ)
}
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;
}
......@@ -148,9 +148,9 @@ struct descriptor
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};
......
......@@ -222,8 +222,9 @@ dump_variables(struct arguments * list, int mode)
/* 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)
......
......@@ -2,7 +2,7 @@
*
* 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>
......@@ -30,6 +30,10 @@ int main(int argc,char **argv)
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");
......@@ -123,5 +127,9 @@ int main(int argc,char **argv)
exec sql close MYCURS;
exec sql deallocate descriptor MYDESC;
if (dbgs != NULL)
fclose(dbgs);
return 0;
}
......@@ -47,8 +47,8 @@ exec sql end declare section;
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);
......
......@@ -39,8 +39,8 @@ exec sql end declare section;
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);
......
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