diff options
author | Marc G. Fournier <scrappy@hub.org> | 1996-10-30 06:18:42 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1996-10-30 06:18:42 +0000 |
commit | 552620c8b24a53c13da540fc0d5f316597e9d2e8 (patch) | |
tree | df4dd916d5cc643fd79a4ae0be2d1ee3cb3f789b /src/interfaces/libpgtcl/pgtclId.c | |
parent | 582982e613693c8d4d5a375b9212b33906def0b7 (diff) | |
download | postgresql-552620c8b24a53c13da540fc0d5f316597e9d2e8.tar.gz postgresql-552620c8b24a53c13da540fc0d5f316597e9d2e8.zip |
Changes to libpgtcl submitted by: wieck@sapserv.debis.de (Jan Wieck)
Adds:
-lAttributes
Returns another format of the results attribute list. Per
attribute a sublist of {{attname} atttype attlen} is
returned and an empty string if no attributes where
received.
-numAttrs
Returns the number of attributes in the result.
Diffstat (limited to 'src/interfaces/libpgtcl/pgtclId.c')
-rw-r--r-- | src/interfaces/libpgtcl/pgtclId.c | 189 |
1 files changed, 172 insertions, 17 deletions
diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c index 00dffe7a883..53654b6da7f 100644 --- a/src/interfaces/libpgtcl/pgtclId.c +++ b/src/interfaces/libpgtcl/pgtclId.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.1.1.1 1996/07/09 06:22:16 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.2 1996/10/30 06:18:41 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -21,31 +21,186 @@ #include <string.h> #include "tcl.h" +#include "pgtclCmds.h" #include "pgtclId.h" -/* convert a pointer into a string */ +/* + * Create the Id for a new connection and hash it + */ +void +PgSetConnectionId(Pg_clientData *cd, char *id, PGconn *conn) +{ + Tcl_HashEntry *hent; + Pg_ConnectionId *connid; + int hnew; + + connid = (Pg_ConnectionId *)ckalloc(sizeof(Pg_ConnectionId)); + connid->conn = conn; + Tcl_InitHashTable(&(connid->res_hash), TCL_STRING_KEYS); + sprintf(connid->id, "pgc%ld", cd->dbh_count++); + strcpy(id, connid->id); + + hent = Tcl_CreateHashEntry(&(cd->dbh_hash), connid->id, &hnew); + Tcl_SetHashValue(hent, (ClientData)connid); +} + + +/* + * Get back the connection from the Id + */ +PGconn * +PgGetConnectionId(Pg_clientData *cd, char *id) +{ + Tcl_HashEntry *hent; + Pg_ConnectionId *connid; + + hent = Tcl_FindHashEntry(&(cd->dbh_hash), id); + if(hent == NULL) { + return (PGconn *)NULL; + } + + connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent); + return connid->conn; +} + + +/* + * Remove a connection Id from the hash table and + * close all portals the user forgot. + */ +void +PgDelConnectionId(Pg_clientData *cd, char *id) +{ + Tcl_HashEntry *hent; + Tcl_HashEntry *hent2; + Tcl_HashEntry *hent3; + Tcl_HashSearch hsearch; + Pg_ConnectionId *connid; + Pg_ResultId *resid; + + hent = Tcl_FindHashEntry(&(cd->dbh_hash), id); + if(hent == NULL) { + return; + } + + connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent); + + hent2 = Tcl_FirstHashEntry(&(connid->res_hash), &hsearch); + while(hent2 != NULL) { + resid = (Pg_ResultId *)Tcl_GetHashValue(hent2); + PQclear(resid->result); + hent3 = Tcl_FindHashEntry(&(cd->res_hash), resid->id); + if(hent3 != NULL) { + Tcl_DeleteHashEntry(hent3); + } + ckfree(resid); + hent2 = Tcl_NextHashEntry(&hsearch); + } + Tcl_DeleteHashTable(&(connid->res_hash)); + Tcl_DeleteHashEntry(hent); + ckfree(connid); +} + + +/* + * Create a new result Id and hash it + */ void -PgSetId(char *id, void *ptr) +PgSetResultId(Pg_clientData *cd, char *id, char *connid_c, PGresult *res) +{ + Tcl_HashEntry *hent; + Pg_ConnectionId *connid; + Pg_ResultId *resid; + int hnew; + + hent = Tcl_FindHashEntry(&(cd->dbh_hash), connid_c); + if(hent == NULL) { + connid = NULL; + } else { + connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent); + } + + resid = (Pg_ResultId *)ckalloc(sizeof(Pg_ResultId)); + resid->result = res; + resid->connection = connid; + sprintf(resid->id, "pgr%ld", cd->res_count++); + strcpy(id, resid->id); + + hent = Tcl_CreateHashEntry(&(cd->res_hash), resid->id, &hnew); + Tcl_SetHashValue(hent, (ClientData)resid); + + if(connid != NULL) { + hent = Tcl_CreateHashEntry(&(connid->res_hash), resid->id, &hnew); + Tcl_SetHashValue(hent, (ClientData)resid); + } +} + + +/* + * Get back the result pointer from the Id + */ +PGresult * +PgGetResultId(Pg_clientData *cd, char *id) { - (void) sprintf(id, "pgp%lx", (long) ptr); + Tcl_HashEntry *hent; + Pg_ResultId *resid; + + hent = Tcl_FindHashEntry(&(cd->res_hash), id); + if(hent == NULL) { + return (PGresult *)NULL; + } + + resid = (Pg_ResultId *)Tcl_GetHashValue(hent); + return resid->result; } -/* get back a pointer from a string */ -void * -PgGetId(char *id) +/* + * Remove a result Id from the hash tables + */ +void +PgDelResultId(Pg_clientData *cd, char *id) { - long ptr; - ptr = strtol(id+3, NULL, 16); - return (void *) ptr; + Tcl_HashEntry *hent; + Tcl_HashEntry *hent2; + Pg_ResultId *resid; + + hent = Tcl_FindHashEntry(&(cd->res_hash), id); + if(hent == NULL) { + return; + } + + resid = (Pg_ResultId *)Tcl_GetHashValue(hent); + if (resid->connection != NULL) { + hent2 = Tcl_FindHashEntry(&(resid->connection->res_hash), id); + if(hent2 != NULL) { + Tcl_DeleteHashEntry(hent2); + } + } + + Tcl_DeleteHashEntry(hent); + ckfree(resid); } -/* check to see if the string is a valid pgtcl pointer */ -int -PgValidId(char* id) + +/* + * Get the connection Id from the result Id + */ +void +PgGetConnByResultId(Pg_clientData *cd, char *id, char *resid_c) { - if ( (strlen(id) > 3) && id[0]=='p' && id[1] == 'g' && id[2] == 'p') - return 1; - else - return 0; + Tcl_HashEntry *hent; + Pg_ResultId *resid; + + hent = Tcl_FindHashEntry(&(cd->res_hash), id); + if(hent == NULL) { + return; + } + + resid = (Pg_ResultId *)Tcl_GetHashValue(hent); + if (resid->connection != NULL) { + strcpy(id, resid->connection->id); + } } + + |