1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pgtcl.c--
|
|
|
|
*
|
|
|
|
* libpgtcl is a tcl package for front-ends to interface with pglite
|
|
|
|
* It's the tcl equivalent of the old libpq C interface.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1996-12-19 06:02:51 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.6 1996/12/19 05:02:47 scrappy Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
1996-11-11 13:14:45 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "postgres.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "tcl.h"
|
|
|
|
#include "libpgtcl.h"
|
|
|
|
#include "pgtclCmds.h"
|
1996-11-11 13:14:45 +01:00
|
|
|
#include "pgtclId.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
1996-10-30 07:18:42 +01:00
|
|
|
* Pgtcl_Init
|
1996-07-09 08:22:35 +02:00
|
|
|
* initialization package for the PGLITE Tcl package
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1996-10-30 07:18:42 +01:00
|
|
|
/*
|
|
|
|
* Tidy up forgotten postgres connection at Tcl_Exit
|
|
|
|
*/
|
1996-11-11 13:14:45 +01:00
|
|
|
static void
|
1996-10-30 07:18:42 +01:00
|
|
|
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
|
|
|
|
*/
|
1996-11-11 13:14:45 +01:00
|
|
|
static void
|
1996-10-30 07:18:42 +01:00
|
|
|
Pgtcl_Shutdown (ClientData cData, Tcl_Interp *interp)
|
|
|
|
{
|
|
|
|
Pgtcl_AtExit(cData);
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
int
|
1996-10-30 07:18:42 +01:00
|
|
|
Pgtcl_Init (Tcl_Interp *interp)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1996-10-30 07:18:42 +01:00
|
|
|
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);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1996-10-30 07:18:42 +01:00
|
|
|
/* register all pgtcl commands */
|
1996-11-09 11:39:54 +01:00
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_conndefaults",
|
|
|
|
Pg_conndefaults,
|
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_connect",
|
|
|
|
Pg_connect,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_disconnect",
|
|
|
|
Pg_disconnect,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_exec",
|
|
|
|
Pg_exec,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1996-10-07 23:19:09 +02:00
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_select",
|
|
|
|
Pg_select,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-10-07 23:19:09 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_result",
|
|
|
|
Pg_result,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_open",
|
|
|
|
Pg_lo_open,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_close",
|
|
|
|
Pg_lo_close,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_read",
|
|
|
|
Pg_lo_read,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_write",
|
|
|
|
Pg_lo_write,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_lseek",
|
|
|
|
Pg_lo_lseek,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_creat",
|
|
|
|
Pg_lo_creat,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_tell",
|
|
|
|
Pg_lo_tell,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_unlink",
|
|
|
|
Pg_lo_unlink,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_import",
|
|
|
|
Pg_lo_import,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_lo_export",
|
|
|
|
Pg_lo_export,
|
1996-10-30 07:18:42 +01:00
|
|
|
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1996-12-19 06:02:51 +01:00
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_listen",
|
|
|
|
Pg_listen,
|
|
|
|
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
|
|
|
|
|
|
|
Tcl_CreateCommand(interp,
|
|
|
|
"pg_notifies",
|
|
|
|
Pg_notifies,
|
|
|
|
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
|
|
|
|
1996-10-30 07:18:42 +01:00
|
|
|
Tcl_PkgProvide(interp, "Pgtcl", "1.0");
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-30 07:18:42 +01:00
|
|
|
int
|
|
|
|
Pgtcl_SafeInit (Tcl_Interp *interp)
|
|
|
|
{
|
|
|
|
return Pgtcl_Init(interp);
|
|
|
|
}
|