Re: [HACKERS] pg_listener attribute number #defines

2009-07-21 Thread Peter Eisentraut
On Wednesday 24 June 2009 08:09:57 Robert Haas wrote:
 It appears that, for no particularly good reason, pg_listener.h
 deviates from the usual convention for declaring attribute number
 constants.  Normally, it's

 #define Anum_{catalog-name}_{column-name}  {attribute-number}

 pg_listener.h, however substitutes a different string that is similar,
 but not the same as, the column name.

 Suggested patch attached.

Fixed.

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] pg_listener attribute number #defines

2009-06-23 Thread Robert Haas
It appears that, for no particularly good reason, pg_listener.h
deviates from the usual convention for declaring attribute number
constants.  Normally, it's

#define Anum_{catalog-name}_{column-name}  {attribute-number}

pg_listener.h, however substitutes a different string that is similar,
but not the same as, the column name.

Suggested patch attached.

...Robert
*** a/src/backend/commands/async.c
--- b/src/backend/commands/async.c
***
*** 486,493  Exec_Listen(Relation lRel, const char *relname)
  
  	namestrcpy(condname, relname);
  	values[Anum_pg_listener_relname - 1] = NameGetDatum(condname);
! 	values[Anum_pg_listener_pid - 1] = Int32GetDatum(MyProcPid);
! 	values[Anum_pg_listener_notify - 1] = Int32GetDatum(0);		/* no notifies pending */
  
  	tuple = heap_form_tuple(RelationGetDescr(lRel), values, nulls);
  
--- 486,493 
  
  	namestrcpy(condname, relname);
  	values[Anum_pg_listener_relname - 1] = NameGetDatum(condname);
! 	values[Anum_pg_listener_listenerpid - 1] = Int32GetDatum(MyProcPid);
! 	values[Anum_pg_listener_notification - 1] = Int32GetDatum(0);		/* no notifies pending */
  
  	tuple = heap_form_tuple(RelationGetDescr(lRel), values, nulls);
  
***
*** 567,573  Exec_UnlistenAll(Relation lRel)
  
  	/* Find and delete all entries with my listenerPID */
  	ScanKeyInit(key[0],
! Anum_pg_listener_pid,
  BTEqualStrategyNumber, F_INT4EQ,
  Int32GetDatum(MyProcPid));
  	scan = heap_beginscan(lRel, SnapshotNow, 1, key);
--- 567,573 
  
  	/* Find and delete all entries with my listenerPID */
  	ScanKeyInit(key[0],
! Anum_pg_listener_listenerpid,
  BTEqualStrategyNumber, F_INT4EQ,
  Int32GetDatum(MyProcPid));
  	scan = heap_beginscan(lRel, SnapshotNow, 1, key);
***
*** 598,606  Send_Notify(Relation lRel)
  	/* preset data to update notify column to MyProcPid */
  	memset(nulls, false, sizeof(nulls));
  	memset(repl, false, sizeof(repl));
! 	repl[Anum_pg_listener_notify - 1] = true;
  	memset(value, 0, sizeof(value));
! 	value[Anum_pg_listener_notify - 1] = Int32GetDatum(MyProcPid);
  
  	scan = heap_beginscan(lRel, SnapshotNow, 0, NULL);
  
--- 598,606 
  	/* preset data to update notify column to MyProcPid */
  	memset(nulls, false, sizeof(nulls));
  	memset(repl, false, sizeof(repl));
! 	repl[Anum_pg_listener_notification - 1] = true;
  	memset(value, 0, sizeof(value));
! 	value[Anum_pg_listener_notification - 1] = Int32GetDatum(MyProcPid);
  
  	scan = heap_beginscan(lRel, SnapshotNow, 0, NULL);
  
***
*** 978,984  ProcessIncomingNotify(void)
  
  	/* Scan only entries with my listenerPID */
  	ScanKeyInit(key[0],
! Anum_pg_listener_pid,
  BTEqualStrategyNumber, F_INT4EQ,
  Int32GetDatum(MyProcPid));
  	scan = heap_beginscan(lRel, SnapshotNow, 1, key);
--- 978,984 
  
  	/* Scan only entries with my listenerPID */
  	ScanKeyInit(key[0],
! Anum_pg_listener_listenerpid,
  BTEqualStrategyNumber, F_INT4EQ,
  Int32GetDatum(MyProcPid));
  	scan = heap_beginscan(lRel, SnapshotNow, 1, key);
***
*** 986,994  ProcessIncomingNotify(void)
  	/* Prepare data for rewriting 0 into notification field */
  	memset(nulls, false, sizeof(nulls));
  	memset(repl, false, sizeof(repl));
! 	repl[Anum_pg_listener_notify - 1] = true;
  	memset(value, 0, sizeof(value));
! 	value[Anum_pg_listener_notify - 1] = Int32GetDatum(0);
  
  	while ((lTuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
  	{
--- 986,994 
  	/* Prepare data for rewriting 0 into notification field */
  	memset(nulls, false, sizeof(nulls));
  	memset(repl, false, sizeof(repl));
! 	repl[Anum_pg_listener_notification - 1] = true;
  	memset(value, 0, sizeof(value));
! 	value[Anum_pg_listener_notification - 1] = Int32GetDatum(0);
  
  	while ((lTuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
  	{
*** a/src/include/catalog/pg_listener.h
--- b/src/include/catalog/pg_listener.h
***
*** 48,55  typedef FormData_pg_listener *Form_pg_listener;
   */
  #define Natts_pg_listener		3
  #define Anum_pg_listener_relname1
! #define Anum_pg_listener_pid	2
! #define Anum_pg_listener_notify	3
  
  /* 
   *		initial contents of pg_listener are NOTHING.
--- 48,55 
   */
  #define Natts_pg_listener		3
  #define Anum_pg_listener_relname1
! #define Anum_pg_listener_listenerpid			2
! #define Anum_pg_listener_notification			3
  
  /* 
   *		initial contents of pg_listener are NOTHING.

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers