OSDN Git Service

In reading the 7.4.2 docs, the sql reference page for PREPARE doesn't
[pg-rex/syncrep.git] / src / interfaces / libpgtcl / pgtclCmds.h
1 /*-------------------------------------------------------------------------
2  *
3  * pgtclCmds.h
4  *        declarations for the C functions which implement pg_* tcl commands
5  *
6  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * $PostgreSQL: pgsql/src/interfaces/libpgtcl/pgtclCmds.h,v 1.32 2003/11/29 22:41:25 pgsql Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #ifndef PGTCLCMDS_H
15 #define PGTCLCMDS_H
16
17 #include <tcl.h>
18
19 #include "libpq-fe.h"
20
21 /* Hack to deal with Tcl 8.4 const-ification without losing compatibility */
22 #ifndef CONST84
23 #define CONST84
24 #endif
25
26 #define RES_HARD_MAX 128
27 #define RES_START 16
28
29 /*
30  * From Tcl version 8.0 on we can make large object access binary.
31  */
32 #ifdef TCL_MAJOR_VERSION
33 #if (TCL_MAJOR_VERSION >= 8)
34 #define PGTCL_USE_TCLOBJ
35 #endif
36 #endif
37
38 /*
39  * Each Pg_ConnectionId has a list of Pg_TclNotifies structs, one for each
40  * Tcl interpreter that has executed any pg_listens on the connection.
41  * We need this arrangement to be able to clean up if an interpreter is
42  * deleted while the connection remains open.  A free side benefit is that
43  * multiple interpreters can be registered to listen for the same notify
44  * name.  (All their callbacks will be called, but in an unspecified order.)
45  *
46  * We use the same approach for pg_on_connection_loss callbacks, but they
47  * are not kept in a hashtable since there's no name associated.
48  */
49
50 typedef struct Pg_TclNotifies_s
51 {
52         struct Pg_TclNotifies_s *next;          /* list link */
53         Tcl_Interp *interp;                     /* This Tcl interpreter */
54
55         /*
56          * NB: if interp == NULL, the interpreter is gone but we haven't yet
57          * got round to deleting the Pg_TclNotifies structure.
58          */
59         Tcl_HashTable notify_hash;      /* Active pg_listen requests */
60
61         char       *conn_loss_cmd;      /* pg_on_connection_loss cmd, or NULL */
62 }       Pg_TclNotifies;
63
64 typedef struct Pg_ConnectionId_s
65 {
66         char            id[32];
67         PGconn     *conn;
68         int                     res_max;                /* Max number of results allocated */
69         int                     res_hardmax;    /* Absolute max to allow */
70         int                     res_count;              /* Current count of active results */
71         int                     res_last;               /* Optimize where to start looking */
72         int                     res_copy;               /* Query result with active copy */
73         int                     res_copyStatus; /* Copying status */
74         PGresult  **results;            /* The results */
75
76         Pg_TclNotifies *notify_list;    /* head of list of notify info */
77         int                     notifier_running;               /* notify event source is live */
78 #if TCL_MAJOR_VERSION >= 8
79         Tcl_Channel notifier_channel;           /* Tcl_Channel on which notifier
80                                                                                  * is listening */
81 #else
82         int                     notifier_socket;        /* PQsocket on which notifier is listening */
83 #endif
84 }       Pg_ConnectionId;
85
86 /* Values of res_copyStatus */
87 #define RES_COPY_NONE   0
88 #define RES_COPY_INPROGRESS 1
89 #define RES_COPY_FIN    2
90
91
92 /* **************************/
93 /* registered Tcl functions */
94 /* **************************/
95 extern int Pg_conndefaults(ClientData cData, Tcl_Interp *interp,
96                                 int argc, CONST84 char *argv[]);
97 extern int Pg_connect(ClientData cData, Tcl_Interp *interp,
98                    int argc, CONST84 char *argv[]);
99 extern int Pg_disconnect(ClientData cData, Tcl_Interp *interp,
100                           int argc, CONST84 char *argv[]);
101 extern int Pg_exec(ClientData cData, Tcl_Interp *interp,
102                 int argc, CONST84 char *argv[]);
103 extern int Pg_execute(ClientData cData, Tcl_Interp *interp,
104                    int argc, CONST84 char *argv[]);
105 extern int Pg_select(ClientData cData, Tcl_Interp *interp,
106                   int argc, CONST84 char *argv[]);
107 extern int Pg_result(ClientData cData, Tcl_Interp *interp,
108                   int argc, CONST84 char *argv[]);
109 extern int Pg_lo_open(ClientData cData, Tcl_Interp *interp,
110                    int argc, CONST84 char *argv[]);
111 extern int Pg_lo_close(ClientData cData, Tcl_Interp *interp,
112                         int argc, CONST84 char *argv[]);
113
114 #ifdef PGTCL_USE_TCLOBJ
115 extern int Pg_lo_read(ClientData cData, Tcl_Interp *interp, int objc,
116                    Tcl_Obj *CONST objv[]);
117 extern int Pg_lo_write(ClientData cData, Tcl_Interp *interp, int objc,
118                         Tcl_Obj *CONST objv[]);
119
120 #else
121 extern int Pg_lo_read(ClientData cData, Tcl_Interp *interp,
122                    int argc, CONST84 char *argv[]);
123 extern int Pg_lo_write(ClientData cData, Tcl_Interp *interp,
124                         int argc, CONST84 char *argv[]);
125 #endif
126 extern int Pg_lo_lseek(ClientData cData, Tcl_Interp *interp,
127                         int argc, CONST84 char *argv[]);
128 extern int Pg_lo_creat(ClientData cData, Tcl_Interp *interp,
129                         int argc, CONST84 char *argv[]);
130 extern int Pg_lo_tell(ClientData cData, Tcl_Interp *interp,
131                    int argc, CONST84 char *argv[]);
132 extern int Pg_lo_unlink(ClientData cData, Tcl_Interp *interp,
133                          int argc, CONST84 char *argv[]);
134 extern int Pg_lo_import(ClientData cData, Tcl_Interp *interp,
135                          int argc, CONST84 char *argv[]);
136 extern int Pg_lo_export(ClientData cData, Tcl_Interp *interp,
137                          int argc, CONST84 char *argv[]);
138 extern int Pg_listen(ClientData cData, Tcl_Interp *interp,
139                   int argc, CONST84 char *argv[]);
140 extern int Pg_on_connection_loss(ClientData cData, Tcl_Interp *interp,
141                                           int argc, CONST84 char *argv[]);
142
143 #endif   /* PGTCLCMDS_H */