77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.8 1996/12/19 05:02:49 scrappy Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.9 1997/01/03 18:48:30 scrappy Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
2424#include "pgtclCmds.h"
2525#include "pgtclId.h"
2626
27- static Tcl_HashTable notifyTable = {NULL };
28-
2927#ifdef TCL_ARRAYS
3028#define ISOCTAL (c )(((c) >= '0') && ((c) <= '7'))
3129#define DIGIT (c )((c) - '0')
@@ -1215,6 +1213,7 @@ Pg_select(ClientData cData, Tcl_Interp *interp, int argc, char **argv)
12151213int
12161214Pg_listen (ClientData cData ,Tcl_Interp * interp ,int argc ,char * argv [])
12171215{
1216+ Pg_clientData * cd = (Pg_clientData * )cData ;
12181217int new ;
12191218char * relname ;
12201219char * callback = NULL ;
@@ -1228,22 +1227,15 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12281227return TCL_ERROR ;
12291228 }
12301229
1231- /*
1232- * Initialize the notify hash table if not already done.
1233- */
1234- if (notifyTable .buckets == NULL ) {
1235- Tcl_InitHashTable (& notifyTable ,TCL_STRING_KEYS );
1236- }
1237-
12381230/*
12391231 * Get the command arguments. Note that relname will copied by
12401232 * Tcl_CreateHashEntry while callback must be allocated.
12411233 */
1242- if (!PgValidId (argv [1 ])) {
1243- Tcl_AppendResult (interp ,"not a valid connection\n" ,0 );
1234+ conn = (PGconn * )PgGetConnectionId (cd ,argv [1 ]);
1235+ if (conn == (PGconn * )NULL ) {
1236+ Tcl_AppendResult (interp ,"First argument is not a valid connection\n" ,0 );
12441237return TCL_ERROR ;
12451238 }
1246- conn = (PGconn * )PgGetId (argv [1 ]);
12471239relname = argv [2 ];
12481240if ((argc > 3 )&& * argv [3 ]) {
12491241callback = (char * )ckalloc ((unsigned ) (strlen (argv [3 ])+ 1 ));
@@ -1254,7 +1246,7 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12541246 * Set or update a callback for a relation;
12551247 */
12561248if (callback ) {
1257- entry = Tcl_CreateHashEntry (& notifyTable ,relname ,& new );
1249+ entry = Tcl_CreateHashEntry (& ( cd -> notify_hash ) ,relname ,& new );
12581250if (new ) {
12591251/* New callback, execute a listen command on the relation */
12601252char * cmd = (char * )ckalloc ((unsigned ) (strlen (argv [2 ])+ 8 ));
@@ -1284,7 +1276,7 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12841276 * the notify hash table.
12851277 */
12861278if (callback == NULL ) {
1287- entry = Tcl_FindHashEntry (& notifyTable ,relname );
1279+ entry = Tcl_FindHashEntry (& ( cd -> notify_hash ) ,relname );
12881280if (entry == NULL ) {
12891281Tcl_AppendResult (interp ,"not listening on " ,relname ,0 );
12901282return TCL_ERROR ;
@@ -1296,11 +1288,12 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12961288return TCL_OK ;
12971289}
12981290
1291+ int
12991292Pg_notifies (ClientData cData ,Tcl_Interp * interp ,int argc ,char * argv [])
13001293{
1294+ Pg_clientData * cd = (Pg_clientData * )cData ;
13011295int count ;
13021296char buff [12 ];
1303- char * relname ;
13041297char * callback ;
13051298Tcl_HashEntry * entry ;
13061299PGconn * conn ;
@@ -1313,21 +1306,14 @@ Pg_notifies(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
13131306return TCL_ERROR ;
13141307 }
13151308
1316- /*
1317- * Initialize the notify hash table if not already done.
1318- */
1319- if (notifyTable .buckets == NULL ) {
1320- Tcl_InitHashTable (& notifyTable ,TCL_STRING_KEYS );
1321- }
1322-
13231309/*
13241310 * Get the connection argument.
13251311 */
1326- if (!PgValidId (argv [1 ])) {
1327- Tcl_AppendResult (interp ,"not a valid connection\n" ,0 );
1312+ conn = (PGconn * )PgGetConnectionId (cd ,argv [1 ]);
1313+ if (conn == (PGconn * )NULL ) {
1314+ Tcl_AppendResult (interp ,"First argument is not a valid connection\n" ,0 );
13281315return TCL_ERROR ;
13291316 }
1330- conn = (PGconn * )PgGetId (argv [1 ]);
13311317
13321318/* Execute an empty command to retrieve asynchronous notifications */
13331319result = PQexec (conn ," " );
@@ -1347,7 +1333,7 @@ Pg_notifies(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
13471333if (notify == NULL ) {
13481334break ;
13491335}
1350- entry = Tcl_FindHashEntry (& notifyTable ,notify -> relname );
1336+ entry = Tcl_FindHashEntry (& ( cd -> notify_hash ) ,notify -> relname );
13511337if (entry != NULL ) {
13521338callback = Tcl_GetHashValue (entry );
13531339if (callback ) {