Commit ab0c8c69 authored by Michael Meskes's avatar Michael Meskes

*** empty log message ***

parent e3a97b37
......@@ -814,5 +814,10 @@ Wed Feb 16 17:04:41 CET 2000
- Apply patch by Christof Petig <christof.petig@wtal.de> that adds
descriptors.
Thu Feb 17 19:37:44 CET 2000
- Synced preproc.y with gram.y.
- Started to clean up preproc.y.
- Set library version to 3.1.0.
- Set ecpg version to 2.7.0.
......@@ -26,6 +26,8 @@ Add a semantic check level, e.g. check if a table really exists.
It would be nice if there was a alternative library using SPI functions
instead of libpq so we can write backend functions using ecpg.
make ECPGnumeric_lvalue more accurate by using something like ECPGdump_a_*
Missing statements:
- exec sql ifdef
- SQLSTATE
......@@ -16,8 +16,8 @@ extern "C"
bool ECPGdisconnect(int, const char *);
bool ECPGprepare(int, char *, char *);
bool ECPGdeallocate(int, char *);
char *ECPGprepared_statement(char *);
char *ECPGprepared_statement(char *);
void ECPGlog(const char *format,...);
#ifdef LIBPQ_FE_H
......@@ -54,12 +54,14 @@ extern "C"
unsigned int ECPGDynamicType(Oid type);
unsigned int ECPGDynamicType_DDT(Oid type);
PGresult * ECPGresultByDescriptor(int line,const char *name);
bool ECPGdo_descriptor(int line,const char *connection,
PGresult * ECPGresultByDescriptor(int line,const char *name);
bool ECPGdo_descriptor(int line,const char *connection,
const char *descriptor,const char *query);
bool ECPGdeallocate_desc(int line,const char *name);
bool ECPGallocate_desc(int line,const char *name);
void ECPGraise(int line,int code);
bool ECPGdeallocate_desc(int line,const char *name);
bool ECPGallocate_desc(int line,const char *name);
void ECPGraise(int line,int code);
bool ECPGget_desc_header(int, char *, int *);
#ifdef __cplusplus
}
......
#include <ecpgtype.h>
#include <ecpglib.h>
bool
ECPGget_desc_header(int lineno, char * desc_name, int *count)
{
PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
if (!ECPGresult)
return false;
*count = PQnfields(ECPGresult);
ECPGlog("ECPGget-desc_header: found %d sttributes.\n", *count);
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.2 2000/02/17 19:48:41 meskes Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.3 2000/02/18 14:34:05 meskes Exp $
*/
/* I borrowed the include files from ecpglib.c, maybe we don't need all of them */
......@@ -211,11 +211,15 @@ bool ECPGdo_descriptor(int line,const char *connection,
PGresult *ECPGresultByDescriptor(int line,const char *name)
{
struct descriptor *i;
for (i=all_descriptors;i!=NULL;i=i->next)
{ if (!strcmp(name,i->name)) return i->result;
for (i = all_descriptors; i != NULL; i = i->next)
{
if (!strcmp(name, i->name)) return i->result;
}
ECPGraise(line,ECPG_UNKNOWN_DESCRIPTOR);
return 0;
return NULL;
}
......@@ -248,10 +252,12 @@ bool ECPGallocate_desc(int line,const char *name)
return true;
}
void ECPGraise(int line,int code)
{ sqlca.sqlcode=code;
void ECPGraise(int line, int code)
{
sqlca.sqlcode=code;
switch (code)
{ case ECPG_NOT_FOUND:
{
case ECPG_NOT_FOUND:
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
"No data found line %d.",line);
break;
......@@ -268,7 +274,7 @@ void ECPGraise(int line,int code)
"descriptor index out of range, line %d.",line);
break;
default:
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
"SQL error #%d, line %d.",code,line);
break;
}
......
......@@ -9,7 +9,7 @@ CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION) \
-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
-DINCLUDE_PATH=\"$(HEADERDIR)\" -g
OBJ=preproc.o pgc.o type.o ecpg.o ecpg_keywords.o \
OBJ=preproc.o pgc.o type.o ecpg.o ecpg_keywords.o output.o\
keywords.o c_keywords.o ../lib/typename.o descriptor.o variable.o
all:: ecpg
......
......@@ -11,33 +11,35 @@
struct assignment *assignments;
void push_assignment(char *var,char *value)
void push_assignment(char *var, char *value)
{
struct assignment *new=(struct assignment *)mm_alloc(sizeof(struct assignment));
struct assignment *new = (struct assignment *)mm_alloc(sizeof(struct assignment));
new->next=assignments;
new->variable=mm_alloc(strlen(var)+1);
new->next = assignments;
new->variable = mm_alloc(strlen(var)+1);
strcpy(new->variable,var);
new->value=mm_alloc(strlen(value)+1);
new->value = mm_alloc(strlen(value)+1);
strcpy(new->value,value);
assignments=new;
assignments = new;
}
static void
drop_assignments(void)
{ while (assignments)
{ struct assignment *old_head=assignments;
{
while (assignments)
{
struct assignment *old_head = assignments;
assignments=old_head->next;
assignments = old_head->next;
free(old_head->variable);
free(old_head->value);
free(old_head);
}
}
/* XXX: these should be more accurate (consider ECPGdump_a_* ) */
static void ECPGnumeric_lvalue(FILE *f,char *name)
{ const struct variable *v=find_variable(name);
{
const struct variable *v=find_variable(name);
switch(v->type->typ)
{
......@@ -54,10 +56,10 @@ static void ECPGnumeric_lvalue(FILE *f,char *name)
,name);
mmerror(ET_ERROR,errortext);
break;
}
}
}
static void ECPGstring_buffer(FILE *f,char *name)
static void ECPGstring_buffer(FILE *f, char *name)
{
const struct variable *v=find_variable(name);
......@@ -167,30 +169,94 @@ static void ECPGdata_assignment(char *variable,char *index_plus_1)
}
}
/*
* descriptor name lookup
*/
static struct descriptor *descriptors;
void add_descriptor(char *name,char *connection)
{
struct descriptor *new=(struct descriptor *)mm_alloc(sizeof(struct descriptor));
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);
}
else new->connection=connection;
descriptors=new;
}
void
drop_descriptor(char *name,char *connection)
{
struct descriptor *i;
struct descriptor **lastptr=&descriptors;
for (i=descriptors;i;lastptr=&i->next,i=i->next)
{
if (!strcmp(name,i->name))
{
if ((!connection && !i->connection)
|| (connection && i->connection
&& !strcmp(connection,i->connection)))
{
*lastptr=i->next;
if (i->connection) free(i->connection);
free(i->name);
free(i);
return;
}
}
}
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
mmerror(ET_WARN,errortext);
}
struct descriptor
*lookup_descriptor(char *name,char *connection)
{
struct descriptor *i;
for (i=descriptors;i;i=i->next)
{
if (!strcmp(name,i->name))
{
if ((!connection && !i->connection)
|| (connection && i->connection
&& !strcmp(connection,i->connection)))
{
return i;
}
}
}
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
mmerror(ET_WARN,errortext);
return NULL;
}
void
output_get_descr_header(char *desc_name)
{
struct assignment *results;
fprintf(yyout,"{\tPGresult *ECPGresult=ECPGresultByDescriptor(%d, \"%s\");\n" ,yylineno,desc_name);
fputs("\tif (ECPGresult)\n\t{",yyout);
for (results=assignments;results!=NULL;results=results->next)
fprintf(yyout, "{ ECPGget_desc_header(%d, \"%s\", &(", yylineno, desc_name);
for (results = assignments; results != NULL; results = results->next)
{
if (!strcasecmp(results->value,"count"))
{
fputs("\t\t",yyout);
if (!strcasecmp(results->value, "count"))
ECPGnumeric_lvalue(yyout,results->variable);
fputs("=PQnfields(ECPGresult);\n",yyout);
}
else
{ snprintf(errortext,sizeof errortext,"unknown descriptor header item '%s'",results->value);
mmerror(ET_WARN,errortext);
{ snprintf(errortext, sizeof errortext, "unknown descriptor header item '%s'", results->value);
mmerror(ET_WARN, errortext);
}
}
drop_assignments();
fputs("}",yyout);
whenever_action(2|1);
drop_assignments();
fprintf(yyout, "));\n");
whenever_action(3);
}
void
......@@ -305,96 +371,3 @@ output_get_descr(char *desc_name)
whenever_action(2|1);
}
/*
* descriptor name lookup
*/
static struct descriptor *descriptors;
void add_descriptor(char *name,char *connection)
{
struct descriptor *new=(struct descriptor *)mm_alloc(sizeof(struct descriptor));
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);
}
else new->connection=connection;
descriptors=new;
}
void drop_descriptor(char *name,char *connection)
{
struct descriptor *i;
struct descriptor **lastptr=&descriptors;
for (i=descriptors;i;lastptr=&i->next,i=i->next)
{
if (!strcmp(name,i->name))
{
if ((!connection && !i->connection)
|| (connection && i->connection
&& !strcmp(connection,i->connection)))
{
*lastptr=i->next;
if (i->connection) free(i->connection);
free(i->name);
free(i);
return;
}
}
}
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
mmerror(ET_WARN,errortext);
}
struct descriptor *lookup_descriptor(char *name,char *connection)
{
struct descriptor *i;
for (i=descriptors;i;i=i->next)
{
if (!strcmp(name,i->name))
{
if ((!connection && !i->connection)
|| (connection && i->connection
&& !strcmp(connection,i->connection)))
{
return i;
}
}
}
snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
mmerror(ET_WARN,errortext);
return NULL;
}
void
output_statement_desc(char * stmt, int mode)
{
int i, j=strlen(stmt);
fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"",
connection ? connection : "NULL", descriptor_name);
/* do this char by char as we have to filter '\"' */
for (i = 0;i < j; i++) {
if (stmt[i] != '\"')
fputc(stmt[i], yyout);
else
fputs("\\\"", yyout);
}
fputs("\");", yyout);
mode |= 2;
whenever_action(mode);
free(stmt);
if (connection != NULL)
free(connection);
free(descriptor_name);
}
......@@ -5,6 +5,7 @@
/* defines */
#define STRUCT_DEPTH 128
#define EMPTY make_str("")
/* variables */
......@@ -12,15 +13,13 @@ extern int braces_open,
autocommit,
ret_value,
struct_level;
extern char *yytext,
errortext[128];
extern int yylineno,
yyleng;
extern FILE *yyin,
*yyout;
extern char *descriptor_index;
extern char *descriptor_name;
extern char *connection;
extern char *input_filename;;
extern char *yytext, errortext[128];
extern int yylineno, yyleng;
extern FILE *yyin, *yyout;
extern struct _include_path *include_paths;
extern struct cursor *cur;
......@@ -36,9 +35,12 @@ extern struct descriptor *descriptors;
/* functions */
extern void output_line_number(void);
extern void lex_init(void);
extern char *input_filename;
extern char *make_str(const char *);
extern void output_line_number(void);
extern void output_statement(char *, int, char *);
extern void output_simple_statement(char *);
extern char *hashline_number(void);
extern int yyparse(void);
extern int yylex(void);
extern void yyerror(char *);
......@@ -55,7 +57,6 @@ extern void whenever_action(int);
extern void add_descriptor(char *,char *);
extern void drop_descriptor(char *,char *);
extern struct descriptor *lookup_descriptor(char *,char *);
extern void output_statement_desc(char *, int);
extern void add_variable(struct arguments ** , struct variable * , struct variable *);
extern void dump_variables(struct arguments *, int);
extern struct typedefs *get_typedef(char *);
......
#include <stdarg.h>
#include "postgres.h"
#include "extern.h"
void
output_line_number()
{
if (input_filename)
fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename);
}
void
output_simple_statement(char *cmd)
{
fputs(cmd, yyout);
output_line_number();
free(cmd);
}
/*
* store the whenever action here
*/
struct when when_error, when_nf, when_warn;
static void
print_action(struct when *w)
{
switch (w->code)
{
case W_SQLPRINT: fprintf(yyout, "sqlprint();");
break;
case W_GOTO: fprintf(yyout, "goto %s;", w->command);
break;
case W_DO: fprintf(yyout, "%s;", w->command);
break;
case W_STOP: fprintf(yyout, "exit (1);");
break;
case W_BREAK: fprintf(yyout, "break;");
break;
default: fprintf(yyout, "{/* %d not implemented yet */}", w->code);
break;
}
}
void
whenever_action(int mode)
{
if ((mode&1) == 1 && when_nf.code != W_NOTHING)
{
output_line_number();
fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
print_action(&when_nf);
}
if (when_warn.code != W_NOTHING)
{
output_line_number();
fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
print_action(&when_warn);
}
if (when_error.code != W_NOTHING)
{
output_line_number();
fprintf(yyout, "\nif (sqlca.sqlcode < 0) ");
print_action(&when_error);
}
if ((mode&2) == 2)
fputc('}', yyout);
output_line_number();
}
char *
hashline_number(void)
{
if (input_filename)
{
char* line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename));
sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);
return line;
}
return EMPTY;
}
void
output_statement(char * stmt, int mode, char *descriptor)
{
int i, j=strlen(stmt);
if (descriptor == NULL)
fprintf(yyout, "{ ECPGdo(__LINE__, %s, \"", connection ? connection : "NULL");
else
fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"",
connection ? connection : "NULL", descriptor);
/* do this char by char as we have to filter '\"' */
for (i = 0;i < j; i++) {
if (stmt[i] != '\"')
fputc(stmt[i], yyout);
else
fputs("\\\"", yyout);
}
if (descriptor == NULL)
{
fputs("\", ", yyout);
/* dump variables to C file */
dump_variables(argsinsert, 1);
fputs("ECPGt_EOIT, ", yyout);
dump_variables(argsresult, 1);
fputs("ECPGt_EORT);", yyout);
}
else
fputs("\");", yyout);
mode |= 2;
whenever_action(mode);
free(stmt);
if (connection != NULL)
free(connection);
}
This diff is collapsed.
......@@ -154,3 +154,9 @@ struct assignment
};
enum errortype {ET_WARN, ET_ERROR, ET_FATAL};
struct fetch_desc
{
char *str;
char *name;
};
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