aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/lib/ecpglib.c
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1998-08-05 04:47:54 +0000
committerMarc G. Fournier <scrappy@hub.org>1998-08-05 04:47:54 +0000
commit186aeb1d671d68bb0c5f8e6d31b091add3a80f81 (patch)
tree9736c28e102d701e624cf45337fef6fe095f161d /src/interfaces/ecpg/lib/ecpglib.c
parent1c9a1250964528274dd785da83cfc16f29cd1bec (diff)
downloadpostgresql-186aeb1d671d68bb0c5f8e6d31b091add3a80f81.tar.gz
postgresql-186aeb1d671d68bb0c5f8e6d31b091add3a80f81.zip
From: Dr. Michael Meskes <meskes@online-club.de>
So this should finally get cursors working. There was an ugly bug in it.
Diffstat (limited to 'src/interfaces/ecpg/lib/ecpglib.c')
-rw-r--r--src/interfaces/ecpg/lib/ecpglib.c53
1 files changed, 53 insertions, 0 deletions
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);
+}