diff options
Diffstat (limited to 'src/interfaces/libpgtcl/pgtclId.c')
-rw-r--r-- | src/interfaces/libpgtcl/pgtclId.c | 260 |
1 files changed, 136 insertions, 124 deletions
diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c index f39342c002e..d6265974b43 100644 --- a/src/interfaces/libpgtcl/pgtclId.c +++ b/src/interfaces/libpgtcl/pgtclId.c @@ -1,18 +1,18 @@ /*------------------------------------------------------------------------- * * pgtclId.c-- - * useful routines to convert between strings and pointers - * Needed because everything in tcl is a string, but we want pointers - * to data structures + * useful routines to convert between strings and pointers + * Needed because everything in tcl is a string, but we want pointers + * to data structures * - * ASSUMPTION: sizeof(long) >= sizeof(void*) + * ASSUMPTION: sizeof(long) >= sizeof(void*) * * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.3 1996/11/11 12:14:45 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.4 1997/09/07 05:03:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,39 +29,40 @@ * Create the Id for a new connection and hash it */ void -PgSetConnectionId(Pg_clientData *cd, char *id, PGconn *conn) +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); + 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) +PGconn * +PgGetConnectionId(Pg_clientData * cd, char *id) { - Tcl_HashEntry *hent; - Pg_ConnectionId *connid; + Tcl_HashEntry *hent; + Pg_ConnectionId *connid; - hent = Tcl_FindHashEntry(&(cd->dbh_hash), id); - if(hent == NULL) { - return (PGconn *)NULL; - } + hent = Tcl_FindHashEntry(&(cd->dbh_hash), id); + if (hent == NULL) + { + return (PGconn *) NULL; + } - connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent); - return connid->conn; + connid = (Pg_ConnectionId *) Tcl_GetHashValue(hent); + return connid->conn; } @@ -70,36 +71,39 @@ PgGetConnectionId(Pg_clientData *cd, char *id) * close all portals the user forgot. */ void -PgDelConnectionId(Pg_clientData *cd, char *id) +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); + 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; } - ckfree(resid); - hent2 = Tcl_NextHashEntry(&hsearch); - } - Tcl_DeleteHashTable(&(connid->res_hash)); - Tcl_DeleteHashEntry(hent); - ckfree(connid); + + 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); } @@ -107,52 +111,57 @@ PgDelConnectionId(Pg_clientData *cd, char *id) * Create a new result Id and hash it */ void -PgSetResultId(Pg_clientData *cd, char *id, char *connid_c, PGresult *res) +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); - } + 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) +PGresult * +PgGetResultId(Pg_clientData * cd, char *id) { - Tcl_HashEntry *hent; - Pg_ResultId *resid; + Tcl_HashEntry *hent; + Pg_ResultId *resid; - hent = Tcl_FindHashEntry(&(cd->res_hash), id); - if(hent == NULL) { - return (PGresult *)NULL; - } + hent = Tcl_FindHashEntry(&(cd->res_hash), id); + if (hent == NULL) + { + return (PGresult *) NULL; + } - resid = (Pg_ResultId *)Tcl_GetHashValue(hent); - return resid->result; + resid = (Pg_ResultId *) Tcl_GetHashValue(hent); + return resid->result; } @@ -160,27 +169,30 @@ PgGetResultId(Pg_clientData *cd, char *id) * Remove a result Id from the hash tables */ void -PgDelResultId(Pg_clientData *cd, char *id) +PgDelResultId(Pg_clientData * cd, char *id) { - 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_HashEntry *hent; + Tcl_HashEntry *hent2; + Pg_ResultId *resid; + + hent = Tcl_FindHashEntry(&(cd->res_hash), id); + if (hent == NULL) + { + return; } - } - Tcl_DeleteHashEntry(hent); - ckfree(resid); + 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); } @@ -188,20 +200,20 @@ PgDelResultId(Pg_clientData *cd, char *id) * Get the connection Id from the result Id */ void -PgGetConnByResultId(Pg_clientData *cd, char *id, char *resid_c) +PgGetConnByResultId(Pg_clientData * cd, char *id, char *resid_c) { - 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); - } -} + 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); + } +} |