From 186aeb1d671d68bb0c5f8e6d31b091add3a80f81 Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Wed, 5 Aug 1998 04:47:54 +0000 Subject: From: Dr. Michael Meskes So this should finally get cursors working. There was an ugly bug in it. --- src/interfaces/ecpg/lib/ecpglib.c | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/interfaces/ecpg/lib/ecpglib.c') diff --git a/src/interfaces/ecpg/lib/ecpglib.c b/src/interfaces/ecpg/lib/ecpglib.c index ecbd2354617..86021d6ee46 100644 --- a/src/interfaces/ecpg/lib/ecpglib.c +++ b/src/interfaces/ecpg/lib/ecpglib.c @@ -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); +} -- cgit v1.2.3