PostgreSQL 8.0.0 �����ĵ���PostgreSQL �й� ������ | ||||
---|---|---|---|---|
Prev | Fast Backward | Chapter 32. ������ | Fast Forward | Next |
�������������������ĵͲ�ϸ�ڡ�ֻ�е�����C��д������������ʱ�����Ҫ��Щ��Ϣ�� �������ij�ָ�����д����������ôϵͳ�ͻ�Ϊ�㴦����Щϸ�ڡ� ÿ�ֹ������Ե��ĵ������й�������ø�������д�������Ľ��͡�
��������������ʹ��"�汾 1��version 1��"�ĺ����������ӿڡ�
��һ������������������������ʱ���������յ��κ���ͨ�����������յ�һ��ָ��TriggerData�ṹ��"����"ָ�롣 C ��������ͨ��ִ��ʵ���ϱ���չΪ
(fcinfo)->context != NULL && IsA((fcinfo)->context, TriggerData))
�ĺ�
CALLED_AS_TRIGGER(fcinfo)
CALLED_AS_TRIGGER(fcinfo)�� ���ж��Լ��Ƿ�Ӵ������������е��õġ� ����˺귵����(TRUE)�������ȫ�ذ�fcinfo->contextת�������� TriggerData * Ȼ��ʹ�����ָ�� TriggerData �Ľṹ�� ����������������� TriggerData �ṹ������ָ����κ����ݡ�
struct TriggerData ���� commands/trigger.h ���涨��ģ�
typedef struct TriggerData { NodeTag type; TriggerEvent tg_event; Relation tg_relation; HeapTuple tg_trigtuple; HeapTuple tg_newtuple; Trigger *tg_trigger; Buffer tg_trigtuplebuf; Buffer tg_newtuplebuf; } TriggerData;
��Щ��Ա�Ķ������£�
���� T_TriggerData��
�������ú������¼��������������ĺ��� tg_event��
������������ڲ���ǰ�����������档
������������ڲ������������档
������������м����¼������������档
�������������伶���¼������������档
�������������INSERT�����������档
�������������UPDATE�����������档
�������������DELETE�����������档
��һ��ָ�������������Ĺ�ϵ�Ľṹ��ָ�롣 ��ο�utils/rel.h��ȡ���ڴ˽ṹ����ϸ��Ϣ�� �����˸���Ȥ�������� tg_relation->rd_att����ϵ�е������� ��tg_relation->rd_rel->relname����ϵ����������������Ͳ��� char*������NameData�� �������Ҫһ�����ֵĿ������� SPI_getrelname(tg_relation)��ȡchar* ����
��һ��ָ�����������е�ָ�롣����һ�����ڱ����루INSERT���� ɾ����DELETE������£�UPDATE�����С������ INSERT��DELETE�� ��ô������㽫���ظ�ִ���ߵĶ��� — ����㲻������һ���и��Ǵ��У�INSERT������Բ�������DELETE��ʱ��
�����UPDATE������һ��ָ���°汾���е�ָ�룬�����INSERT ��DELETE�� ����NULL��������㽫���ظ�ִ���ߵĶ��� — ����¼��� UPDATE �����㲻������һ�����滻�����л���Բ�����
��һ��ָ��ṹTrigger��ָ�룬�ýṹ��utils/rel.h�ﶨ�壺
typedef struct Trigger { Oid tgoid; char *tgname; Oid tgfoid; int16 tgtype; bool tgenabled; bool tgisconstraint; Oid tgconstrrelid; bool tgdeferrable; bool tginitdeferred; int16 tgnargs; int16 tgattr[FUNC_MAX_ARGS]; char **tgargs; } Trigger;
tgname�Ǵ����������ƣ�tgnargs ����tgargs������������� tgargs��һ��ָ�����飬������ÿ��ָ��ָ���� CREATE TRIGGER����������IJ�����������Աֻ���ڲ�ʹ�á�
���û��������Զ�����û�д洢�ڴ��̻������ ���ǰ��� tg_trigtuple ���� InvalidBuffer �Ļ�������
���û��������Զ���������δ�洢�ڴ��̻��������ô���ǰ��� tg_newtuple�� ���� InvalidBuffer �Ļ�������
һ���������������뷵��һ�� HeapTuple ָ�����һ�� NULL ָ�� ������ SQL NULL��Ҳ����˵����Ҫ���� isNull Ϊ�棩�� ��ע������㲻�������ڱ��������У���ôҪ����������� tg_trigtuple ���� tg_newtuple��