1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-26 12:21:12 +03:00

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.
This commit is contained in:
Marc G. Fournier
1996-10-30 06:18:42 +00:00
parent 582982e613
commit 552620c8b2
7 changed files with 369 additions and 120 deletions

View File

@ -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
PgSetId(char *id, void *ptr)
PgSetConnectionId(Pg_clientData *cd, char *id, PGconn *conn)
{
(void) sprintf(id, "pgp%lx", (long) ptr);
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 a pointer from a string */
void *
PgGetId(char *id)
/*
* Get back the connection from the Id
*/
PGconn *
PgGetConnectionId(Pg_clientData *cd, char *id)
{
long ptr;
ptr = strtol(id+3, NULL, 16);
return (void *) ptr;
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;
}
/* check to see if the string is a valid pgtcl pointer */
int
PgValidId(char* id)
/*
* Remove a connection Id from the hash table and
* close all portals the user forgot.
*/
void
PgDelConnectionId(Pg_clientData *cd, char *id)
{
if ( (strlen(id) > 3) && id[0]=='p' && id[1] == 'g' && id[2] == 'p')
return 1;
else
return 0;
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
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)
{
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;
}
/*
* Remove a result Id from the hash tables
*/
void
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_DeleteHashEntry(hent);
ckfree(resid);
}
/*
* Get the connection Id from the result Id
*/
void
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);
}
}