*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.6 1996/12/19 05:02:47 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.7 1997/01/03 18:48:28 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
Tcl_DeleteHashTable(&(cd->dbh_hash));
Tcl_DeleteHashTable(&(cd->res_hash));
+ Tcl_DeleteHashTable(&(cd->notify_hash));
Tcl_DeleteExitHandler(Pgtcl_AtExit, cData);
}
cd = (Pg_clientData *)ckalloc(sizeof(Pg_clientData));
Tcl_InitHashTable(&(cd->dbh_hash), TCL_STRING_KEYS);
Tcl_InitHashTable(&(cd->res_hash), TCL_STRING_KEYS);
+ Tcl_InitHashTable(&(cd->notify_hash), TCL_STRING_KEYS);
cd->dbh_count = 0L;
cd->res_count = 0L;
Tcl_CreateCommand(interp,
"pg_listen",
Pg_listen,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp,
"pg_notifies",
Pg_notifies,
- (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ (ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_PkgProvide(interp, "Pgtcl", "1.0");
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.8 1996/12/19 05:02:49 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.9 1997/01/03 18:48:30 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgtclCmds.h"
#include "pgtclId.h"
-static Tcl_HashTable notifyTable = { NULL };
-
#ifdef TCL_ARRAYS
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
#define DIGIT(c) ((c) - '0')
int
Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
{
+ Pg_clientData *cd = (Pg_clientData *)cData;
int new;
char *relname;
char *callback = NULL;
return TCL_ERROR;
}
- /*
- * Initialize the notify hash table if not already done.
- */
- if (notifyTable.buckets == NULL) {
- Tcl_InitHashTable(¬ifyTable, TCL_STRING_KEYS);
- }
-
/*
* Get the command arguments. Note that relname will copied by
* Tcl_CreateHashEntry while callback must be allocated.
*/
- if (!PgValidId(argv[1])) {
- Tcl_AppendResult(interp, "not a valid connection\n", 0);
+ conn = (PGconn*)PgGetConnectionId(cd, argv[1]);
+ if (conn == (PGconn *)NULL) {
+ Tcl_AppendResult(interp, "First argument is not a valid connection\n", 0);
return TCL_ERROR;
}
- conn = (PGconn*)PgGetId(argv[1]);
relname = argv[2];
if ((argc > 3) && *argv[3]) {
callback = (char *) ckalloc((unsigned) (strlen(argv[3])+1));
* Set or update a callback for a relation;
*/
if (callback) {
- entry = Tcl_CreateHashEntry(¬ifyTable, relname, &new);
+ entry = Tcl_CreateHashEntry(&(cd->notify_hash), relname, &new);
if (new) {
/* New callback, execute a listen command on the relation */
char *cmd = (char *) ckalloc((unsigned) (strlen(argv[2])+8));
* the notify hash table.
*/
if (callback == NULL) {
- entry = Tcl_FindHashEntry(¬ifyTable, relname);
+ entry = Tcl_FindHashEntry(&(cd->notify_hash), relname);
if (entry == NULL) {
Tcl_AppendResult(interp, "not listening on ", relname, 0);
return TCL_ERROR;
return TCL_OK;
}
+int
Pg_notifies(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
{
+ Pg_clientData *cd = (Pg_clientData *)cData;
int count;
char buff[12];
- char *relname;
char *callback;
Tcl_HashEntry *entry;
PGconn *conn;
return TCL_ERROR;
}
- /*
- * Initialize the notify hash table if not already done.
- */
- if (notifyTable.buckets == NULL) {
- Tcl_InitHashTable(¬ifyTable, TCL_STRING_KEYS);
- }
-
/*
* Get the connection argument.
*/
- if (!PgValidId(argv[1])) {
- Tcl_AppendResult(interp, "not a valid connection\n", 0);
+ conn = (PGconn*)PgGetConnectionId(cd, argv[1]);
+ if (conn == (PGconn *)NULL) {
+ Tcl_AppendResult(interp, "First argument is not a valid connection\n", 0);
return TCL_ERROR;
}
- conn = (PGconn*)PgGetId(argv[1]);
/* Execute an empty command to retrieve asynchronous notifications */
result = PQexec(conn, " ");
if (notify == NULL) {
break;
}
- entry = Tcl_FindHashEntry(¬ifyTable, notify->relname);
+ entry = Tcl_FindHashEntry(&(cd->notify_hash), notify->relname);
if (entry != NULL) {
callback = Tcl_GetHashValue(entry);
if (callback) {