/[rserv]/lib/rserv.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/rserv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dpavlin, Wed Aug 6 16:14:53 2003 UTC revision 1.5 by dpavlin, Mon Nov 3 21:30:37 2003 UTC
# Line 3  Line 3 
3   * (c) 2000 Vadim Mikheev, PostgreSQL Inc.   * (c) 2000 Vadim Mikheev, PostgreSQL Inc.
4   */   */
5    
6  #include "executor/spi.h"               /* this is what you need to work with SPI */  #include "executor/spi.h"       /* this is what you need to work with SPI */
7  #include "commands/trigger.h"   /* -"- and triggers */  #include "commands/trigger.h"   /* -"- and triggers */
8  #include "utils/tqual.h"                /* -"- and SnapshotData */  #include "utils/tqual.h"        /* -"- and SnapshotData */
9  #include <ctype.h>                              /* tolower () */  #include <ctype.h>              /* tolower () */
10    
11  #ifdef PG_FUNCTION_INFO_V1  #ifdef PG_FUNCTION_INFO_V1
12  #define CurrentTriggerData ((TriggerData *) fcinfo->context)  #define CurrentTriggerData ((TriggerData *) fcinfo->context)
# Line 16  Line 16 
16  PG_FUNCTION_INFO_V1(_rserv_log_);  PG_FUNCTION_INFO_V1(_rserv_log_);
17  PG_FUNCTION_INFO_V1(_rserv_sync_);  PG_FUNCTION_INFO_V1(_rserv_sync_);
18  PG_FUNCTION_INFO_V1(_rserv_debug_);  PG_FUNCTION_INFO_V1(_rserv_debug_);
19    PG_FUNCTION_INFO_V1(_rserv_xid_);
20  Datum           _rserv_log_(PG_FUNCTION_ARGS);  Datum           _rserv_log_(PG_FUNCTION_ARGS);
21  Datum           _rserv_sync_(PG_FUNCTION_ARGS);  Datum           _rserv_sync_(PG_FUNCTION_ARGS);
22  Datum           _rserv_debug_(PG_FUNCTION_ARGS);  Datum           _rserv_debug_(PG_FUNCTION_ARGS);
23    Datum           _rserv_xid_(PG_FUNCTION_ARGS);
24    
25  #else  #else
26  HeapTuple       _rserv_log_(void);  HeapTuple       _rserv_log_(void);
27  int32           _rserv_sync_(int32);  int32           _rserv_sync_(int32);
28  int32           _rserv_debug_(int32);  int32           _rserv_debug_(int32);
29    int32           _rserv_xid_(void);
30  #endif  #endif
31    
32  static int      debug = 0;  static int      debug = 0;
# Line 54  _rserv_log_() Line 57  _rserv_log_()
57          char            outbuf[8192];          char            outbuf[8192];
58          char            oidbuf[64];          char            oidbuf[64];
59          int                     ret;          int                     ret;
60            int             server;
61    
62          /* Called by trigger manager ? */          /* Called by trigger manager ? */
63          if (!CurrentTriggerData)          if (!CurrentTriggerData)
# Line 69  _rserv_log_() Line 73  _rserv_log_()
73          nargs = trigger->tgnargs;          nargs = trigger->tgnargs;
74          args = trigger->tgargs;          args = trigger->tgargs;
75    
76          if (nargs != 1)                         /* odd number of arguments! */          if (nargs != 2)                         /* odd number of arguments! */
77                  elog(ERROR, "_rserv_log_: need in *one* argument");                  elog(ERROR, "_rserv_log_: need in *two* arguments, key number and server number");
78    
79          keynum = atoi(args[0]);          keynum = atoi(args[0]);
80            server = atoi(args[1]);
81    
82          if (keynum < 0 && keynum != ObjectIdAttributeNumber)          if (keynum < 0 && keynum != ObjectIdAttributeNumber)
83                  elog(ERROR, "_rserv_log_: invalid keynum %d", keynum);                  elog(ERROR, "_rserv_log_: invalid keynum %d", keynum);
# Line 152  _rserv_log_() Line 157  _rserv_log_()
157          else if (SPI_processed == 0)          else if (SPI_processed == 0)
158          {          {
159                  snprintf(sql, 8192, "insert into _RSERV_LOG_ "                  snprintf(sql, 8192, "insert into _RSERV_LOG_ "
160                                  "(reloid, logid, logtime, insert, update, delete, key) "                                  "(reloid, logid, logtime, insert, update, delete, key, server) "
161                                  "values (%u, %d, now(), %d, %d, %d, '%s')",                                  "values (%u, %d, now(), %d, %d, %d, '%s', %d)",
162                                   rel->rd_id, GetCurrentTransactionId(),                                   rel->rd_id, GetCurrentTransactionId(),
163                                  inserted, updated, deleted, okey);                                  inserted, updated, deleted, okey, server);
164    
165                  if (debug)                  if (debug)
166                          elog(DEBUG3, "sql: %s", sql);                          elog(DEBUG3, "sql: %s", sql);
# Line 177  _rserv_log_() Line 182  _rserv_log_()
182                          okey = newkey;                          okey = newkey;
183    
184                  snprintf(sql, 8192, "insert into _RSERV_LOG_ "                  snprintf(sql, 8192, "insert into _RSERV_LOG_ "
185                                   "(reloid, logid, logtime, insert, update, deleted, key) "                                   "(reloid, logid, logtime, insert, update, deleted, key, server) "
186                                   "values (%u, %d, now(), %d, %d, 0, '%s')",                                   "values (%u, %d, now(), %d, %d, 0, '%s', %d)",
187                                   rel->rd_id, GetCurrentTransactionId(), inserted, updated, okey);                                   rel->rd_id, GetCurrentTransactionId(), inserted, updated, okey, server);
188    
189                  if (debug)                  if (debug)
190                          elog(DEBUG3, "sql: %s", sql);                          elog(DEBUG3, "sql: %s", sql);
# Line 333  OutputValue(char *key, char *buf, int si Line 338  OutputValue(char *key, char *buf, int si
338          return (out);          return (out);
339    
340  }  }
341    
342    #ifdef PG_FUNCTION_INFO_V1
343    Datum
344    _rserv_xid_(PG_FUNCTION_ARGS)
345    #else
346    int32
347    _rserv_xid_(void)
348    #endif
349    {
350            int32   curr_xid = GetCurrentTransactionId();
351    
352            return (curr_xid);
353    }
354    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.26