summaryrefslogtreecommitdiff
path: root/src/interfaces/libpgtcl/pgtcl.c
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1996-10-30 06:18:42 +0000
committerMarc G. Fournier <scrappy@hub.org>1996-10-30 06:18:42 +0000
commit552620c8b24a53c13da540fc0d5f316597e9d2e8 (patch)
treedf4dd916d5cc643fd79a4ae0be2d1ee3cb3f789b /src/interfaces/libpgtcl/pgtcl.c
parent582982e613693c8d4d5a375b9212b33906def0b7 (diff)
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/pgtcl.c')
-rw-r--r--src/interfaces/libpgtcl/pgtcl.c91
1 files changed, 72 insertions, 19 deletions
diff --git a/src/interfaces/libpgtcl/pgtcl.c b/src/interfaces/libpgtcl/pgtcl.c
index f3758cd8fb1..d4021894e44 100644
--- a/src/interfaces/libpgtcl/pgtcl.c
+++ b/src/interfaces/libpgtcl/pgtcl.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.2 1996/10/07 21:19:06 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.3 1996/10/30 06:18:38 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -19,92 +19,145 @@
#include "pgtclCmds.h"
/*
- * PG_Init
+ * Pgtcl_Init
* initialization package for the PGLITE Tcl package
*
*/
+/*
+ * Tidy up forgotten postgres connection at Tcl_Exit
+ */
+void
+Pgtcl_AtExit (ClientData cData)
+{
+ Pg_clientData *cd = (Pg_clientData *)cData;
+ Tcl_HashEntry *hent;
+ Tcl_HashSearch hsearch;
+ Pg_ConnectionId *connid;
+ PGconn *conn;
+
+ while((hent = Tcl_FirstHashEntry(&(cd->dbh_hash), &hsearch)) != NULL) {
+ connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent);
+ conn = connid->conn;
+ PgDelConnectionId(cd, connid->id);
+ PQfinish(conn);
+ }
+
+ Tcl_DeleteHashTable(&(cd->dbh_hash));
+ Tcl_DeleteHashTable(&(cd->res_hash));
+
+ Tcl_DeleteExitHandler(Pgtcl_AtExit, cData);
+}
+
+/*
+ * Tidy up forgotten postgres connections on Interpreter deletion
+ */
+void
+Pgtcl_Shutdown (ClientData cData, Tcl_Interp *interp)
+{
+ Pgtcl_AtExit(cData);
+}
+
int
-Pg_Init (Tcl_Interp *interp)
+Pgtcl_Init (Tcl_Interp *interp)
{
- /* register all pgtcl commands */
+ Pg_clientData *cd;
+
+ /* Create and initialize the client data area */
+ cd = (Pg_clientData *)ckalloc(sizeof(Pg_clientData));
+ Tcl_InitHashTable(&(cd->dbh_hash), TCL_STRING_KEYS);
+ Tcl_InitHashTable(&(cd->res_hash), TCL_STRING_KEYS);
+ cd->dbh_count = 0L;
+ cd->res_count = 0L;
+
+ /* Arrange for tidy up when interpreter is deleted or Tcl exits */
+ Tcl_CallWhenDeleted(interp, Pgtcl_Shutdown, (ClientData)cd);
+ Tcl_CreateExitHandler(Pgtcl_AtExit, (ClientData)cd);
+ /* register all pgtcl commands */
Tcl_CreateCommand(interp,
"pg_connect",
Pg_connect,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_disconnect",
Pg_disconnect,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_exec",
Pg_exec,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_select",
Pg_select,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_result",
Pg_result,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_open",
Pg_lo_open,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_close",
Pg_lo_close,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_read",
Pg_lo_read,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_write",
Pg_lo_write,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_lseek",
Pg_lo_lseek,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_creat",
Pg_lo_creat,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_tell",
Pg_lo_tell,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_unlink",
Pg_lo_unlink,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_import",
Pg_lo_import,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_lo_export",
Pg_lo_export,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
+ Tcl_PkgProvide(interp, "Pgtcl", "1.0");
+
return TCL_OK;
}
+int
+Pgtcl_SafeInit (Tcl_Interp *interp)
+{
+ return Pgtcl_Init(interp);
+}