Commit 186aeb1d authored by Marc G. Fournier's avatar Marc G. Fournier

From: Dr. Michael Meskes <meskes@online-club.de>

So this should finally get cursors working. There was an ugly bug in it.
parent 1c9a1250
......@@ -258,3 +258,15 @@ Tue Jul 7 15:14:14 CEST 1998
- Fixed some bugs in preproc.y
- Set version to 2.3.4
Mon Jul 27 17:13:11 CEST 1998
- Changed text of error message to make emacs happy
Mon Aug 3 17:23:18 CEST 1998
- Added latest changes from gram.y resp. scan.l to
preproc.y resp. pgc.l
- Fixed cursor handling
- Set version to 2.3.5
- Set library version to 2.4
What happens to a cursor declaration with variables?
The complete structure definition has to be listed inside the declare
section of the structure variable for ecpg to be able to understand it.
......
......@@ -23,6 +23,7 @@
#define ECPG_CONVERT_BOOL -207
#define ECPG_EMPTY -208
#define ECPG_NO_CONN -209
#define ECPG_UNDECLARED_CURSOR -210
/* finally the backend error messages, they start at 300 */
#define ECPG_PGSQL -300
......
......@@ -13,6 +13,9 @@ bool ECPGdisconnect(int, const char *);
void ECPGlog(const char *format,...);
bool ECPGdeclare(int, const char *, char *);
bool ECPGopen(int, const char *);
#ifdef LIBPQ_FE_H
bool ECPGsetdb(PGconn *);
......@@ -32,6 +35,11 @@ struct ECPGgeneric_varchar
/* print an error message */
void sqlprint(void);
struct cursor { const char *name;
char *command;
struct cursor *next;
};
/* define this for simplicity as well as compatibility */
#define SQLCODE sqlca.sqlcode
......
......@@ -4,7 +4,7 @@ include $(SRCDIR)/Makefile.global
PQ_INCLUDE=-I$(SRCDIR)/interfaces/libpq
SO_MAJOR_VERSION=2
SO_MINOR_VERSION=3
SO_MINOR_VERSION=4
PORTNAME=@PORTNAME@
......
......@@ -940,3 +940,56 @@ sqlprint(void)
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
printf("sql error %s\n", sqlca.sqlerrm.sqlerrmc);
}
/* keep a list of cursors */
struct cursor *cur = NULL;
bool ECPGdeclare(int lineno, const char *name, char *command)
{
struct cursor *ptr;
for (ptr = cur; ptr != NULL; ptr = ptr->next)
{
if (strcmp(name, ptr->name) == 0)
{
/* re-definition */
free(ptr->command);
ptr->command = command;
break;
}
}
if (ptr == NULL)
{
struct cursor *this = (struct cursor *) malloc(sizeof(struct cursor));
if (!this)
{
ECPGlog("out of memory\n");
register_error(ECPG_OUT_OF_MEMORY, "out of memory in line %d", lineno);
return false;
}
/* initial definition */
this->next = cur;
this->name = name;
this->command = command;
cur = this;
}
return(true);
}
bool ECPGopen(int lineno, const char *name)
{
struct cursor *ptr;
for (ptr = cur; ptr != NULL; ptr=ptr->next)
{
if (strcmp(ptr->name, name) == 0)
return(ECPGdo(lineno, ptr->command, ECPGt_EOIT, ECPGt_EORT));
}
ECPGlog("trying to open undeclared cursor %s\n", name);
register_error(ECPG_UNDECLARED_CURSOR, "trying to open undeclared cursor %s in line %d", name, lineno);
return(false);
}
......@@ -3,11 +3,11 @@ include $(SRCDIR)/Makefile.global
MAJOR_VERSION=2
MINOR_VERSION=3
PATCHLEVEL=4
PATCHLEVEL=5
CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION) \
-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
-DINCLUDE_PATH=\"$(DESTDIR)$(HEADERDIR)\"
-DINCLUDE_PATH=\"$(DESTDIR)$(HEADERDIR)\"
OBJ=y.tab.o pgc.o type.o ecpg.o ecpg_keywords.o ../../../backend/parser/scansup.o \
keywords.o c_keywords.o ../lib/typename.o
......
......@@ -141,20 +141,6 @@ main(int argc, char *const argv[])
/* initialize lex */
lex_init();
/* initialize cursor list */
for (ptr = cur; ptr != NULL;)
{
struct cursor *c;
free(ptr->name);
free(ptr->command);
c = ptr;
ptr = ptr->next;
free(c);
}
cur = NULL;
/* we need two includes and a constant */
fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/*These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n\nconst int no_auto_trans = %d;\n\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL, no_auto_trans);
......
......@@ -16,13 +16,6 @@ struct _include_path { char * path;
extern struct _include_path *include_paths;
struct cursor { char *name;
char *command;
struct cursor *next;
};
extern struct cursor *cur;
/* This is a linked list of the variable names and types. */
struct variable
{
......
......@@ -335,7 +335,7 @@ cppline {space}*#.*(\\{space}*\n)*\n*
BEGIN(xm);
for(i = 0; yytext[i]; i++)
if (isupper(yytext[i]))
if (isascii((unsigned char)yytext[i]) && isupper(yytext[i]))
yytext[i] = tolower(yytext[i]);
keyword = ScanKeywordLookup((char*)yytext);
......@@ -417,7 +417,7 @@ cppline {space}*#.*(\\{space}*\n)*\n*
ScanKeyword *keyword;
for(i = 0; yytext[i]; i++)
if (isupper(yytext[i]))
if (isascii((unsigned char)yytext[i]) && isupper(yytext[i]))
yytext[i] = tolower(yytext[i]);
keyword = ScanKeywordLookup((char*)yytext);
......
This diff is collapsed.
......@@ -42,8 +42,8 @@ exec sql end declare section;
exec sql commit;
strcpy(msg, "declare");
exec sql declare cur cursor for
select name, born, age, married from meskes;
exec sql declare cur cursor for
select name, born, age, married from meskes;
strcpy(msg, "open");
exec sql open cur;
......
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