-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgtcl.c
375 lines (318 loc) · 8.86 KB
/
pgtcl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*-------------------------------------------------------------------------
*
* pgtcl.c
*
* libpgtcl is a tcl package for front-ends to interface with PostgreSQL.
* It's a Tcl wrapper for libpq.
*
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Id: pgtcl.c 334 2013-10-04 15:04:44Z lbayuk $
*
*-------------------------------------------------------------------------
*/
#include "libpgtcl.h"
#include "pgtclCmds.h"
#include "pgtclId.h"
/* Runtime Tcl version, set below */
double pgtcl_tcl_version;
/*
* Pgtcl_Init
* initialization package for the PGTCL Tcl package
*
*/
#ifdef _WINDOWS
__declspec(dllexport)
#endif
Pgtcl_Init(Tcl_Interp *interp)
{
/*
* The version required really should be TCL_VERSION, but this
* can be compiled under 8.5 with stubs and still mostly works
* with a Tcl 8.4 interpreter, so let 8.4 be the minimum version.
*/
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.6-", 0) == NULL)
return TCL_ERROR;
#endif
/*
* Get the Tcl version at runtime, which may differ from the compile-time
* version due to use of Tcl stubs. This is used in some commands to
* prevent crashes due to missing stubs functions.
*/
if (Tcl_GetDouble(interp,
Tcl_GetVar(interp, "tcl_version", TCL_GLOBAL_ONLY),
&pgtcl_tcl_version) != TCL_OK)
pgtcl_tcl_version = 8.4; /* A reasonable fallback */
/*
* Note: Removed code to set PGCLIENTENCODING=UNICODE if tcl_version >= 8.1.
* That did not work for Windows because the libpq DLL didn't see the
* environment change. So now this is done when connecting to the database.
*/
/* register all pgtcl commands */
Tcl_CreateObjCommand(interp,
"pg_conndefaults",
Pg_conndefaults,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_connect",
Pg_connect,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_disconnect",
Pg_disconnect,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_exec",
Pg_exec,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_select",
Pg_select,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_result",
Pg_result,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_execute",
Pg_execute,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_open",
Pg_lo_open,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_close",
Pg_lo_close,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_read",
Pg_lo_read,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_write",
Pg_lo_write,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_lseek",
Pg_lo_lseek,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_creat",
Pg_lo_creat,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_tell",
Pg_lo_tell,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_unlink",
Pg_lo_unlink,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_import",
Pg_lo_import,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_export",
Pg_lo_export,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_listen",
Pg_listen,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_sendquery",
Pg_sendquery,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_sendquery_prepared",
Pg_sendquery_prepared,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_sendquery_params",
Pg_sendquery_params,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_getresult",
Pg_getresult,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_isbusy",
Pg_isbusy,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_blocking",
Pg_blocking,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_cancelrequest",
Pg_cancelrequest,
(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp,
"pg_on_connection_loss",
Pg_on_connection_loss,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_escape_string",
Pg_escape_string,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_quote",
Pg_quote,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_escape_bytea",
Pg_escape_bytea,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_unescape_bytea",
Pg_unescape_bytea,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_transaction_status",
Pg_transaction_status,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_parameter_status",
Pg_parameter_status,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_exec_prepared",
Pg_exec_prepared,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_exec_params",
Pg_exec_params,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_notice_handler",
Pg_notice_handler,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_result_callback",
Pg_result_callback,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
#ifdef HAVE_PQENCRYPTPASSWORD /* PostgreSQL >= 8.2.0 */
Tcl_CreateObjCommand(interp,
"pg_encrypt_password",
Pg_encrypt_password,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
#endif
#ifdef HAVE_LO_TRUNCATE /* PostgreSQL >= 8.3.0 */
Tcl_CreateObjCommand(interp,
"pg_lo_truncate",
Pg_lo_truncate,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
#endif
#ifdef HAVE_PQDESCRIBEPREPARED /* PostgreSQL >= 8.2.0 */
Tcl_CreateObjCommand(interp,
"pg_describe_cursor",
Pg_describe_cursor,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_describe_prepared",
Pg_describe_prepared,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
#endif
Tcl_CreateObjCommand(interp,
"pg_backend_pid",
Pg_backend_pid,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_server_version",
Pg_server_version,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
#ifdef HAVE_LO_TELL64 /* PostgreSQL >= 9.3.0 */
Tcl_CreateObjCommand(interp,
"pg_lo_tell64",
Pg_lo_tell64,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_lseek64",
Pg_lo_lseek64,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_lo_truncate64",
Pg_lo_truncate64,
(ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
#endif
#ifdef HAVE_PQESCAPELITERAL /* PostgreSQL >= 9.0 */
Tcl_CreateObjCommand(interp,
"pg_escape_literal",
Pg_escape_l_i,
(ClientData) 1,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp,
"pg_escape_identifier",
Pg_escape_l_i,
(ClientData) 2,
(Tcl_CmdDeleteProc *) NULL);
#endif
/* Note PACKAGE_VERSION (or VERSION) is provided by the TEA Makefile */
#ifndef PACKAGE_VERSION
#ifdef VERSION
#define PACKAGE_VERSION VERSION
#else
#define PACKAGE_VERSION "0.0"
#endif
#endif
Tcl_PkgProvide(interp, "Pgtcl", PACKAGE_VERSION);
return TCL_OK;
}
#ifdef _WINDOWS
__declspec(dllexport)
#endif
Pgtcl_SafeInit(Tcl_Interp *interp)
{
return Pgtcl_Init(interp);
}