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
|
$NetBSD: patch-am,v 1.6 2001/11/04 21:25:48 darcy Exp $
--- src/interfaces/python/pgmodule.c.orig Thu Aug 16 14:36:44 2001
+++ src/interfaces/python/pgmodule.c
@@ -27,25 +27,16 @@
*/
#include <Python.h>
-#include <postgres.h>
-#include <libpq-fe.h>
-#include <libpq/libpq-fs.h>
+#include "postgres.h"
+#include "libpq-fe.h"
+#include "libpq/libpq-fs.h"
+#include "catalog/pg_type.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-/* really bad stuff here - I'm so naughty */
-/* If you need to you can run mkdefines to get */
-/* current defines but it should not have changed */
-#define INT2OID 21
-#define INT4OID 23
-#define OIDOID 26
-#define FLOAT4OID 700
-#define FLOAT8OID 701
-#define CASHOID 790
-
static PyObject *PGError;
-static const char *PyPgVersion = "3.1";
+static const char *PyPgVersion = "3.2";
/* taken from fileobject.c */
#define BUF(v) PyString_AS_STRING((PyStringObject *)(v))
@@ -103,14 +94,16 @@
static PyObject *pg_default_host; /* default database host */
static PyObject *pg_default_base; /* default database name */
-static PyObject *pg_default_opt;/* default connection options */
-static PyObject *pg_default_tty;/* default debug tty */
+static PyObject *pg_default_opt; /* default connection options */
+static PyObject *pg_default_tty; /* default debug tty */
static PyObject *pg_default_port; /* default connection port */
static PyObject *pg_default_user; /* default username */
static PyObject *pg_default_passwd; /* default password */
-
#endif /* DEFAULT_VARS */
+DL_EXPORT(void) init_pg(void);
+int *get_type_array(PGresult *result, int nfields);
+
/* --------------------------------------------------------------------- */
/* OBJECTS DECLARATION */
@@ -242,7 +235,6 @@
return 1;
}
-
#endif /* LARGE_OBJECTS */
/* checks source object validity */
@@ -292,12 +284,14 @@
{
case INT2OID:
case INT4OID:
+ case INT8OID:
case OIDOID:
typ[j] = 1;
break;
case FLOAT4OID:
case FLOAT8OID:
+ case NUMERICOID:
typ[j] = 2;
break;
@@ -484,7 +478,6 @@
pgsource_oidstatus(pgsourceobject * self, PyObject * args)
{
long oid;
- const char *status;
/* checks validity */
if (!check_source_obj(self, CHECK_RESULT))
@@ -566,6 +559,7 @@
}
PyList_Append(reslist, rowtuple);
+ Py_DECREF(rowtuple);
self->current_row++;
}
@@ -947,11 +941,7 @@
/* query type definition */
staticforward PyTypeObject PgSourceType = {
-#ifndef MS_WIN32
- PyObject_HEAD_INIT(&PyType_Type)
-#else
PyObject_HEAD_INIT(NULL)
-#endif
0, /* ob_size */
"pgsourceobject", /* tp_name */
@@ -1460,7 +1450,6 @@
0, /* tp_as_mapping */
0, /* tp_hash */
};
-
#endif /* LARGE_OBJECTS */
@@ -1803,12 +1792,14 @@
{
case INT2OID:
case INT4OID:
+ case INT8OID:
case OIDOID:
typ[j] = 1;
break;
case FLOAT4OID:
case FLOAT8OID:
+ case NUMERICOID:
typ[j] = 2;
break;
@@ -1853,21 +1844,33 @@
val = PyFloat_FromDouble(strtod(s, NULL));
break;
- case 3: /* get rid of the '$' and commas */
- if (*s == '$') /* there's talk of getting rid of
- * it */
+ case 3:
+ {
+ int mult = 1;
+
+ if (*s == '$') /* there's talk of getting
+ * rid of it */
s++;
- if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
- *(++s) = '-';
+ if (*s == '-' || *s == '(')
+ {
+ s++;
+ mult = -1;
+ }
+
+ /* get rid of the '$' and commas */
+ if (*s == '$') /* Just in case we exposed
+ * one */
+ s++;
for (k = 0; *s; s++)
if (*s != ',')
cashbuf[k++] = *s;
cashbuf[k] = 0;
- val = PyFloat_FromDouble(strtod(cashbuf, NULL));
+ val = PyFloat_FromDouble(strtod(cashbuf, NULL) * mult);
break;
+ }
default:
val = PyString_FromString(s);
@@ -1938,12 +1941,14 @@
{
case INT2OID:
case INT4OID:
+ case INT8OID:
case OIDOID:
typ[j] = 1;
break;
case FLOAT4OID:
case FLOAT8OID:
+ case NUMERICOID:
typ[j] = 2;
break;
@@ -1988,21 +1993,33 @@
val = PyFloat_FromDouble(strtod(s, NULL));
break;
- case 3: /* get rid of the '$' and commas */
- if (*s == '$') /* there's talk of getting rid of
- * it */
+ case 3:
+ {
+ int mult = 1;
+
+ if (*s == '$') /* there's talk of getting
+ * rid of it */
s++;
- if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
- *(++s) = '-';
+ if (*s == '-' || *s == '(')
+ {
+ s++;
+ mult = -1;
+ }
+
+ /* get rid of the '$' and commas */
+ if (*s == '$') /* Just in case we exposed
+ * one */
+ s++;
for (k = 0; *s; s++)
if (*s != ',')
cashbuf[k++] = *s;
cashbuf[k] = 0;
- val = PyFloat_FromDouble(strtod(cashbuf, NULL));
+ val = PyFloat_FromDouble(strtod(cashbuf, NULL) * mult);
break;
+ }
default:
val = PyString_FromString(s);
@@ -2318,7 +2335,6 @@
Py_INCREF(Py_None);
return Py_None;
}
-
#endif /* DIRECT_ACCESS */
@@ -2622,7 +2638,6 @@
static PyObject *
pg_getattr(pgobject * self, char *name)
{
-
/*
* Although we could check individually, there are only a few
* attributes that don't require a live connection and unless someone
@@ -3104,7 +3119,6 @@
return old;
}
-
#endif /* DEFAULT_VARS */
/* List of functions defined in the module */
@@ -3141,7 +3155,8 @@
*v;
/* Initialize here because some WIN platforms get confused otherwise */
- PglargeType.ob_type = PgType.ob_type = PgQueryType.ob_type = &PyType_Type;
+ PglargeType.ob_type = PgType.ob_type = PgQueryType.ob_type =
+ PgSourceType.ob_type = &PyType_Type;
/* Create the module and add the functions */
mod = Py_InitModule4("_pg", pg_methods, pg__doc__, NULL, PYTHON_API_VERSION);
|