PyGreSQL 6.2.2__tar.gz → 6.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pygresql-6.2.2 → pygresql-6.2.3}/PKG-INFO +1 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/PyGreSQL.egg-info/PKG-INFO +1 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/PyGreSQL.egg-info/SOURCES.txt +2 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/changelog.rst +9 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/connection.rst +2 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pgconn.c +47 -12
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pginternal.c +37 -29
- pygresql-6.2.3/ext/pginternal.h +91 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pglarge.c +11 -5
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pgmodule.c +32 -136
- pygresql-6.2.3/ext/pgmodule.h +145 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pgnotice.c +8 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pgquery.c +5 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pgsource.c +7 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/pyproject.toml +1 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/setup.py +9 -1
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_classic_connection.py +65 -38
- {pygresql-6.2.2 → pygresql-6.2.3}/LICENSE.txt +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/MANIFEST.in +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/PyGreSQL.egg-info/dependency_links.txt +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/PyGreSQL.egg-info/not-zip-safe +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/PyGreSQL.egg-info/top_level.txt +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/README.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/Makefile +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/_static/favicon.ico +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/_static/pygresql.png +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/about.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/community/homes.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/community/index.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/community/issues.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/community/mailinglist.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/community/source.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/community/support.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/conf.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/examples.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/general.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/index.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/install.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/adaptation.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/db_types.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/db_wrapper.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/index.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/introduction.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/large_objects.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/module.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/notification.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pg/query.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/adaptation.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/connection.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/cursor.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/index.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/introduction.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/module.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/typecache.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/pgdb/types.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/postgres/advanced.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/postgres/basic.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/postgres/func.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/postgres/index.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/postgres/syscat.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/contents/tutorial.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/copyright.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/download/download.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/download/files.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/download/index.rst +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/make.bat +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/docs/requirements.txt +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/ext/pgtypes.h +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/__init__.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/_pg.pyi +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/adapt.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/attrs.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/cast.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/core.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/db.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/error.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/helpers.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/notify.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/py.typed +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pg/tz.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/__init__.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/adapt.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/cast.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/connect.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/connection.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/constants.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/cursor.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/py.typed +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/pgdb/typecode.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/setup.cfg +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/__init__.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/config.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/dbapi20.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_classic.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_classic_attrdict.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_classic_dbwrapper.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_classic_functions.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_classic_largeobj.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_classic_notification.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_dbapi20.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_dbapi20_copy.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tests/test_tutorial.py +0 -0
- {pygresql-6.2.2 → pygresql-6.2.3}/tox.ini +0 -0
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
ChangeLog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
Version 6.2.3 (2026-01-25)
|
|
5
|
+
--------------------------
|
|
6
|
+
- Minor improvements and fixes (thanks to Justin Pryzby):
|
|
7
|
+
|
|
8
|
+
- The `inserttable()` method in the `pg` module can now directly import
|
|
9
|
+
date, time, datetime and timedelta objects from Python (#93) and was
|
|
10
|
+
slightly improved to avoid memory exhaustion and memory leaks (#92).
|
|
11
|
+
- The C extension has no been properly modularized into separate units (#25).
|
|
12
|
+
|
|
4
13
|
Version 6.2.2 (2026-01-03)
|
|
5
14
|
--------------------------
|
|
6
15
|
- The `inserttable()` method in the `pg` module can now handle rows of
|
|
@@ -495,7 +495,8 @@ This method allows to *quickly* insert large blocks of data in a table.
|
|
|
495
495
|
Internally, it uses the COPY command of the PostgreSQL database.
|
|
496
496
|
The method takes an iterable of row values which must be tuples or lists
|
|
497
497
|
of the same size, containing the values for each inserted row.
|
|
498
|
-
These may contain string, integer, long or double (real) values
|
|
498
|
+
These may contain string, integer, long or double (real) values as well as
|
|
499
|
+
date, time, datetime or timedelta objects.
|
|
499
500
|
``columns`` is an optional tuple or list of column names to be passed on
|
|
500
501
|
to the COPY command.
|
|
501
502
|
The number of rows affected is returned.
|
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
* Please see the LICENSE.TXT file for specific restrictions.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/* Shared headers */
|
|
12
|
+
#include "pginternal.h"
|
|
13
|
+
#include "pgmodule.h"
|
|
14
|
+
|
|
15
|
+
/* Needs to be after Python.h */
|
|
16
|
+
#include "datetime.h"
|
|
17
|
+
|
|
11
18
|
/* Deallocate connection object. */
|
|
12
19
|
static void
|
|
13
20
|
conn_dealloc(connObject *self)
|
|
@@ -27,6 +34,8 @@ static PyObject *
|
|
|
27
34
|
conn_getattr(connObject *self, PyObject *nameobj)
|
|
28
35
|
{
|
|
29
36
|
const char *name = PyUnicode_AsUTF8(nameobj);
|
|
37
|
+
if (!name)
|
|
38
|
+
return NULL;
|
|
30
39
|
|
|
31
40
|
/*
|
|
32
41
|
* Although we could check individually, there are only a few
|
|
@@ -113,7 +122,7 @@ conn_getattr(connObject *self, PyObject *nameobj)
|
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
/* Check connection validity. */
|
|
116
|
-
|
|
125
|
+
int
|
|
117
126
|
_check_cnx_obj(connObject *self)
|
|
118
127
|
{
|
|
119
128
|
if (!self || !self->valid || !self->cnx) {
|
|
@@ -154,7 +163,7 @@ conn_source(connObject *self, PyObject *noargs)
|
|
|
154
163
|
|
|
155
164
|
/* For a non-query result, set the appropriate error status,
|
|
156
165
|
return the appropriate value, and free the result set. */
|
|
157
|
-
|
|
166
|
+
PyObject *
|
|
158
167
|
_conn_non_query_result(int status, PGresult *result, PGconn *cnx)
|
|
159
168
|
{
|
|
160
169
|
switch (status) {
|
|
@@ -783,6 +792,12 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
783
792
|
|
|
784
793
|
encoding = PQclientEncoding(self->cnx);
|
|
785
794
|
|
|
795
|
+
/* import datetime C API (this is not compatible with subinterpreters) */
|
|
796
|
+
PyDateTime_IMPORT;
|
|
797
|
+
if (PyErr_Occurred()) {
|
|
798
|
+
return NULL; /* pass the error */
|
|
799
|
+
}
|
|
800
|
+
|
|
786
801
|
/* pre-allocate some memory for the query buffer */
|
|
787
802
|
if (!init_char_buffer(&buffer, 4096)) {
|
|
788
803
|
Py_DECREF(iter_row);
|
|
@@ -856,6 +871,8 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
856
871
|
Py_END_ALLOW_THREADS
|
|
857
872
|
|
|
858
873
|
if (!result || PQresultStatus(result) != PGRES_COPY_IN) {
|
|
874
|
+
if (result)
|
|
875
|
+
PQclear(result);
|
|
859
876
|
PyMem_Free(buffer.data);
|
|
860
877
|
Py_DECREF(iter_row);
|
|
861
878
|
PyErr_SetString(PyExc_ValueError, PQerrorMessage(self->cnx));
|
|
@@ -864,6 +881,9 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
864
881
|
|
|
865
882
|
PQclear(result);
|
|
866
883
|
|
|
884
|
+
/* empty buffer while keeping allocated memory */
|
|
885
|
+
buffer.size = 0;
|
|
886
|
+
|
|
867
887
|
/* feed table */
|
|
868
888
|
for (i = 0; m < 0 || i < m; ++i) {
|
|
869
889
|
if (!(columns = PyIter_Next(iter_row)))
|
|
@@ -895,9 +915,6 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
895
915
|
return NULL;
|
|
896
916
|
}
|
|
897
917
|
|
|
898
|
-
/* empty buffer while keeping allocated memory */
|
|
899
|
-
buffer.size = 0;
|
|
900
|
-
|
|
901
918
|
/* build insert line */
|
|
902
919
|
|
|
903
920
|
for (j = 0; j < n; ++j) {
|
|
@@ -977,7 +994,9 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
977
994
|
Py_DECREF(s);
|
|
978
995
|
}
|
|
979
996
|
}
|
|
980
|
-
else if (PyLong_Check(item))
|
|
997
|
+
else if (PyLong_Check(item) || PyDate_Check(item) ||
|
|
998
|
+
PyDateTime_Check(item) || PyTime_Check(item) ||
|
|
999
|
+
PyDelta_Check(item)) {
|
|
981
1000
|
PyObject *s = PyObject_Str(item);
|
|
982
1001
|
const char *t = PyUnicode_AsUTF8(s);
|
|
983
1002
|
|
|
@@ -1026,8 +1045,26 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
1026
1045
|
return PyErr_NoMemory();
|
|
1027
1046
|
}
|
|
1028
1047
|
|
|
1029
|
-
|
|
1048
|
+
if (buffer.size > 128 * 1024) {
|
|
1049
|
+
/* send buffered data after reaching 128KB */
|
|
1050
|
+
ret = PQputCopyData(self->cnx, buffer.data, (int)buffer.size);
|
|
1051
|
+
buffer.size = 0;
|
|
1052
|
+
if (ret != 1) {
|
|
1053
|
+
char *errormsg = ret == -1 ? PQerrorMessage(self->cnx)
|
|
1054
|
+
: "Data cannot be queued";
|
|
1055
|
+
PyErr_SetString(PyExc_IOError, errormsg);
|
|
1056
|
+
PQputCopyEnd(self->cnx, errormsg);
|
|
1057
|
+
PyMem_Free(buffer.data);
|
|
1058
|
+
Py_DECREF(iter_row);
|
|
1059
|
+
return NULL;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/* flush any remaining data */
|
|
1065
|
+
if (buffer.size) {
|
|
1030
1066
|
ret = PQputCopyData(self->cnx, buffer.data, (int)buffer.size);
|
|
1067
|
+
buffer.size = 0;
|
|
1031
1068
|
if (ret != 1) {
|
|
1032
1069
|
char *errormsg = ret == -1 ? PQerrorMessage(self->cnx)
|
|
1033
1070
|
: "Data cannot be queued";
|
|
@@ -1039,9 +1076,10 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
1039
1076
|
}
|
|
1040
1077
|
}
|
|
1041
1078
|
|
|
1079
|
+
PyMem_Free(buffer.data);
|
|
1080
|
+
|
|
1042
1081
|
Py_DECREF(iter_row);
|
|
1043
1082
|
if (PyErr_Occurred()) {
|
|
1044
|
-
PyMem_Free(buffer.data);
|
|
1045
1083
|
return NULL; /* pass the iteration error */
|
|
1046
1084
|
}
|
|
1047
1085
|
|
|
@@ -1049,12 +1087,9 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
|
|
|
1049
1087
|
if (ret != 1) {
|
|
1050
1088
|
PyErr_SetString(PyExc_IOError, ret == -1 ? PQerrorMessage(self->cnx)
|
|
1051
1089
|
: "Data cannot be queued");
|
|
1052
|
-
PyMem_Free(buffer.data);
|
|
1053
1090
|
return NULL;
|
|
1054
1091
|
}
|
|
1055
1092
|
|
|
1056
|
-
PyMem_Free(buffer.data);
|
|
1057
|
-
|
|
1058
1093
|
Py_BEGIN_ALLOW_THREADS
|
|
1059
1094
|
result = PQgetResult(self->cnx);
|
|
1060
1095
|
Py_END_ALLOW_THREADS
|
|
@@ -1775,7 +1810,7 @@ static struct PyMethodDef conn_methods[] = {
|
|
|
1775
1810
|
static char conn__doc__[] = "PostgreSQL connection object";
|
|
1776
1811
|
|
|
1777
1812
|
/* Connection type definition */
|
|
1778
|
-
|
|
1813
|
+
PyTypeObject connType = {
|
|
1779
1814
|
PyVarObject_HEAD_INIT(NULL, 0) "pg.Connection", /* tp_name */
|
|
1780
1815
|
sizeof(connObject), /* tp_basicsize */
|
|
1781
1816
|
0, /* tp_itemsize */
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* Please see the LICENSE.TXT file for specific restrictions.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/* Shared headers */
|
|
12
|
+
#include "pginternal.h"
|
|
13
|
+
|
|
11
14
|
/* PyGreSQL internal types */
|
|
12
15
|
|
|
13
16
|
/* Simple types */
|
|
@@ -27,7 +30,7 @@
|
|
|
27
30
|
|
|
28
31
|
/* Shared functions for encoding and decoding strings */
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
PyObject *
|
|
31
34
|
get_decoded_string(const char *str, Py_ssize_t size, int encoding)
|
|
32
35
|
{
|
|
33
36
|
if (encoding == pg_encoding_utf8)
|
|
@@ -41,7 +44,7 @@ get_decoded_string(const char *str, Py_ssize_t size, int encoding)
|
|
|
41
44
|
"strict");
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
PyObject *
|
|
45
48
|
get_encoded_string(PyObject *unicode_obj, int encoding)
|
|
46
49
|
{
|
|
47
50
|
if (encoding == pg_encoding_utf8)
|
|
@@ -176,7 +179,7 @@ get_type(Oid pgtype)
|
|
|
176
179
|
}
|
|
177
180
|
|
|
178
181
|
/* Get PyGreSQL column types for all result columns. */
|
|
179
|
-
|
|
182
|
+
int *
|
|
180
183
|
get_col_types(PGresult *result, int nfields)
|
|
181
184
|
{
|
|
182
185
|
int *types, *t, j;
|
|
@@ -194,7 +197,7 @@ get_col_types(PGresult *result, int nfields)
|
|
|
194
197
|
|
|
195
198
|
/* Cast a bytea encoded text based type to a Python object.
|
|
196
199
|
This assumes the text is null-terminated character string. */
|
|
197
|
-
|
|
200
|
+
PyObject *
|
|
198
201
|
cast_bytea_text(char *s)
|
|
199
202
|
{
|
|
200
203
|
PyObject *obj;
|
|
@@ -212,7 +215,7 @@ cast_bytea_text(char *s)
|
|
|
212
215
|
|
|
213
216
|
/* Cast a text based type to a Python object.
|
|
214
217
|
This needs the character string, size and encoding. */
|
|
215
|
-
|
|
218
|
+
PyObject *
|
|
216
219
|
cast_sized_text(char *s, Py_ssize_t size, int encoding, int type)
|
|
217
220
|
{
|
|
218
221
|
PyObject *obj, *tmp_obj;
|
|
@@ -264,7 +267,7 @@ cast_sized_text(char *s, Py_ssize_t size, int encoding, int type)
|
|
|
264
267
|
/* Cast an arbitrary type to a Python object using a callback function.
|
|
265
268
|
This needs the character string, size, encoding, the Postgres type
|
|
266
269
|
and the external typecast function to be called. */
|
|
267
|
-
|
|
270
|
+
PyObject *
|
|
268
271
|
cast_other(char *s, Py_ssize_t size, int encoding, Oid pgtype,
|
|
269
272
|
PyObject *cast_hook)
|
|
270
273
|
{
|
|
@@ -282,7 +285,7 @@ cast_other(char *s, Py_ssize_t size, int encoding, Oid pgtype,
|
|
|
282
285
|
|
|
283
286
|
/* Cast a simple type to a Python object.
|
|
284
287
|
This needs a character string representation with a given size. */
|
|
285
|
-
|
|
288
|
+
PyObject *
|
|
286
289
|
cast_sized_simple(char *s, Py_ssize_t size, int type)
|
|
287
290
|
{
|
|
288
291
|
PyObject *obj, *tmp_obj;
|
|
@@ -375,7 +378,7 @@ cast_sized_simple(char *s, Py_ssize_t size, int type)
|
|
|
375
378
|
|
|
376
379
|
/* Cast a simple type to a Python object.
|
|
377
380
|
This needs a null-terminated character string representation. */
|
|
378
|
-
|
|
381
|
+
PyObject *
|
|
379
382
|
cast_unsized_simple(char *s, int type)
|
|
380
383
|
{
|
|
381
384
|
PyObject *obj, *tmp_obj;
|
|
@@ -454,7 +457,7 @@ cast_unsized_simple(char *s, int type)
|
|
|
454
457
|
Use internal type or cast function to cast elements.
|
|
455
458
|
The parameter delim specifies the delimiter for the elements,
|
|
456
459
|
since some types do not use the default delimiter of a comma. */
|
|
457
|
-
|
|
460
|
+
PyObject *
|
|
458
461
|
cast_array(char *s, Py_ssize_t size, int encoding, int type, PyObject *cast,
|
|
459
462
|
char delim)
|
|
460
463
|
{
|
|
@@ -721,7 +724,7 @@ cast_array(char *s, Py_ssize_t size, int encoding, int type, PyObject *cast,
|
|
|
721
724
|
functions to cast elements. The parameter len is the record size.
|
|
722
725
|
The parameter delim can specify a delimiter for the elements,
|
|
723
726
|
although composite types always use a comma as delimiter. */
|
|
724
|
-
|
|
727
|
+
PyObject *
|
|
725
728
|
cast_record(char *s, Py_ssize_t size, int encoding, int *type, PyObject *cast,
|
|
726
729
|
Py_ssize_t len, char delim)
|
|
727
730
|
{
|
|
@@ -905,7 +908,7 @@ cast_record(char *s, Py_ssize_t size, int encoding, int *type, PyObject *cast,
|
|
|
905
908
|
|
|
906
909
|
/* Cast string s with size and encoding to a Python dictionary.
|
|
907
910
|
using the input and output syntax for hstore values. */
|
|
908
|
-
|
|
911
|
+
PyObject *
|
|
909
912
|
cast_hstore(char *s, Py_ssize_t size, int encoding)
|
|
910
913
|
{
|
|
911
914
|
PyObject *result;
|
|
@@ -1198,14 +1201,14 @@ set_error_msg_and_state(PyObject *type, const char *msg, int encoding,
|
|
|
1198
1201
|
}
|
|
1199
1202
|
|
|
1200
1203
|
/* Set given database error message. */
|
|
1201
|
-
|
|
1204
|
+
void
|
|
1202
1205
|
set_error_msg(PyObject *type, const char *msg)
|
|
1203
1206
|
{
|
|
1204
1207
|
set_error_msg_and_state(type, msg, pg_encoding_ascii, NULL);
|
|
1205
1208
|
}
|
|
1206
1209
|
|
|
1207
1210
|
/* Set database error from connection and/or result. */
|
|
1208
|
-
|
|
1211
|
+
void
|
|
1209
1212
|
set_error(PyObject *type, const char *msg, PGconn *cnx, PGresult *result)
|
|
1210
1213
|
{
|
|
1211
1214
|
char *sqlstate = NULL;
|
|
@@ -1228,7 +1231,7 @@ set_error(PyObject *type, const char *msg, PGconn *cnx, PGresult *result)
|
|
|
1228
1231
|
}
|
|
1229
1232
|
|
|
1230
1233
|
/* Get SSL attributes and values as a dictionary. */
|
|
1231
|
-
|
|
1234
|
+
PyObject *
|
|
1232
1235
|
get_ssl_attributes(PGconn *cnx)
|
|
1233
1236
|
{
|
|
1234
1237
|
PyObject *attr_dict = NULL;
|
|
@@ -1260,7 +1263,7 @@ get_ssl_attributes(PGconn *cnx)
|
|
|
1260
1263
|
PQprint() is not used because handing over a stream from Python to
|
|
1261
1264
|
PostgreSQL can be problematic if they use different libs for streams
|
|
1262
1265
|
and because using PQprint() and tp_print is not recommended any more. */
|
|
1263
|
-
|
|
1266
|
+
PyObject *
|
|
1264
1267
|
format_result(const PGresult *res)
|
|
1265
1268
|
{
|
|
1266
1269
|
const int n = PQnfields(res);
|
|
@@ -1340,8 +1343,10 @@ format_result(const PGresult *res)
|
|
|
1340
1343
|
const size_t k = sizes[j];
|
|
1341
1344
|
const size_t h = (k - (size_t)strlen(s)) / 2;
|
|
1342
1345
|
|
|
1343
|
-
|
|
1344
|
-
|
|
1346
|
+
snprintf(p, size - (size_t)(p - buffer), "%*s", (int)h,
|
|
1347
|
+
"");
|
|
1348
|
+
snprintf(p + h, size - (size_t)(p + h - buffer), "%-*s",
|
|
1349
|
+
(int)(k - h), s);
|
|
1345
1350
|
p += k;
|
|
1346
1351
|
if (j + 1 < n)
|
|
1347
1352
|
*p++ = '|';
|
|
@@ -1362,12 +1367,14 @@ format_result(const PGresult *res)
|
|
|
1362
1367
|
const size_t k = sizes[j];
|
|
1363
1368
|
|
|
1364
1369
|
if (align) {
|
|
1365
|
-
|
|
1366
|
-
|
|
1370
|
+
snprintf(p, size - (size_t)(p - buffer),
|
|
1371
|
+
align == 'r' ? "%*s" : "%-*s", (int)k,
|
|
1372
|
+
PQgetvalue(res, i, j));
|
|
1367
1373
|
}
|
|
1368
1374
|
else {
|
|
1369
|
-
|
|
1370
|
-
|
|
1375
|
+
snprintf(p, size - (size_t)(p - buffer), "%-*s",
|
|
1376
|
+
(int)k,
|
|
1377
|
+
PQgetisnull(res, i, j) ? "" : "<binary>");
|
|
1371
1378
|
}
|
|
1372
1379
|
p += k;
|
|
1373
1380
|
if (j + 1 < n)
|
|
@@ -1379,7 +1386,8 @@ format_result(const PGresult *res)
|
|
|
1379
1386
|
PyMem_Free(aligns);
|
|
1380
1387
|
PyMem_Free(sizes);
|
|
1381
1388
|
/* create the footer */
|
|
1382
|
-
|
|
1389
|
+
snprintf(p, size - (size_t)(p - buffer), "(%d row%s)", m,
|
|
1390
|
+
m == 1 ? "" : "s");
|
|
1383
1391
|
/* return the result */
|
|
1384
1392
|
result = PyUnicode_FromString(buffer);
|
|
1385
1393
|
PyMem_Free(buffer);
|
|
@@ -1402,7 +1410,7 @@ format_result(const PGresult *res)
|
|
|
1402
1410
|
}
|
|
1403
1411
|
|
|
1404
1412
|
/* Internal function converting a Postgres datestyles to date formats. */
|
|
1405
|
-
|
|
1413
|
+
const char *
|
|
1406
1414
|
date_style_to_format(const char *s)
|
|
1407
1415
|
{
|
|
1408
1416
|
static const char *formats[] = {
|
|
@@ -1435,7 +1443,7 @@ date_style_to_format(const char *s)
|
|
|
1435
1443
|
}
|
|
1436
1444
|
|
|
1437
1445
|
/* Internal function converting a date format to a Postgres datestyle. */
|
|
1438
|
-
|
|
1446
|
+
const char *
|
|
1439
1447
|
date_format_to_style(const char *s)
|
|
1440
1448
|
{
|
|
1441
1449
|
static const char *datestyle[] = {
|
|
@@ -1470,7 +1478,7 @@ date_format_to_style(const char *s)
|
|
|
1470
1478
|
}
|
|
1471
1479
|
|
|
1472
1480
|
/* Internal wrapper for the notice receiver callback. */
|
|
1473
|
-
|
|
1481
|
+
void
|
|
1474
1482
|
notice_receiver(void *arg, const PGresult *res)
|
|
1475
1483
|
{
|
|
1476
1484
|
PyGILState_STATE gstate = PyGILState_Ensure();
|
|
@@ -1495,7 +1503,7 @@ notice_receiver(void *arg, const PGresult *res)
|
|
|
1495
1503
|
}
|
|
1496
1504
|
|
|
1497
1505
|
/* Pre-allocate some memory for a char buffer and return success status. */
|
|
1498
|
-
|
|
1506
|
+
int
|
|
1499
1507
|
init_char_buffer(struct CharBuffer *buf, size_t initial_size)
|
|
1500
1508
|
{
|
|
1501
1509
|
buf->size = 0;
|
|
@@ -1512,8 +1520,8 @@ init_char_buffer(struct CharBuffer *buf, size_t initial_size)
|
|
|
1512
1520
|
}
|
|
1513
1521
|
|
|
1514
1522
|
/* Extend char buffer with given string.
|
|
1515
|
-
|
|
1516
|
-
|
|
1523
|
+
Note: We do not assume or guarantee that the buffer is zero-terminated. */
|
|
1524
|
+
void
|
|
1517
1525
|
ext_char_buffer_s(struct CharBuffer *buf, const char *s)
|
|
1518
1526
|
{
|
|
1519
1527
|
size_t len = strlen(s), need;
|
|
@@ -1546,7 +1554,7 @@ ext_char_buffer_s(struct CharBuffer *buf, const char *s)
|
|
|
1546
1554
|
}
|
|
1547
1555
|
|
|
1548
1556
|
/* Extend char buffer with given character */
|
|
1549
|
-
|
|
1557
|
+
void
|
|
1550
1558
|
ext_char_buffer_c(struct CharBuffer *buf, char c)
|
|
1551
1559
|
{
|
|
1552
1560
|
if (buf->error)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Internal functions header for the PyGreSQL C extension.
|
|
3
|
+
* Provides prototypes for helpers implemented in pginternal.c
|
|
4
|
+
* and extern declarations for module globals used therein.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef PYGRE_SQL_PGINTERNAL_H
|
|
8
|
+
#define PYGRE_SQL_PGINTERNAL_H
|
|
9
|
+
|
|
10
|
+
#define PY_SSIZE_T_CLEAN
|
|
11
|
+
#include <Python.h>
|
|
12
|
+
#include <libpq-fe.h>
|
|
13
|
+
|
|
14
|
+
#include "pgmodule.h"
|
|
15
|
+
|
|
16
|
+
/* Encoding helpers */
|
|
17
|
+
/* PyGreSQL internal types */
|
|
18
|
+
#define PYGRES_INT 1
|
|
19
|
+
#define PYGRES_LONG 2
|
|
20
|
+
#define PYGRES_FLOAT 3
|
|
21
|
+
#define PYGRES_DECIMAL 4
|
|
22
|
+
#define PYGRES_MONEY 5
|
|
23
|
+
#define PYGRES_BOOL 6
|
|
24
|
+
/* Text based types */
|
|
25
|
+
#define PYGRES_TEXT 8
|
|
26
|
+
#define PYGRES_BYTEA 9
|
|
27
|
+
#define PYGRES_JSON 10
|
|
28
|
+
#define PYGRES_OTHER 11
|
|
29
|
+
/* Array types */
|
|
30
|
+
#define PYGRES_ARRAY 16
|
|
31
|
+
PyObject *
|
|
32
|
+
get_decoded_string(const char *str, Py_ssize_t size, int encoding);
|
|
33
|
+
PyObject *
|
|
34
|
+
get_encoded_string(PyObject *unicode_obj, int encoding);
|
|
35
|
+
|
|
36
|
+
/* Result/Type helpers */
|
|
37
|
+
int *
|
|
38
|
+
get_col_types(PGresult *result, int nfields);
|
|
39
|
+
PyObject *
|
|
40
|
+
format_result(const PGresult *res);
|
|
41
|
+
|
|
42
|
+
/* Casting helpers */
|
|
43
|
+
PyObject *
|
|
44
|
+
cast_bytea_text(char *s);
|
|
45
|
+
PyObject *
|
|
46
|
+
cast_sized_text(char *s, Py_ssize_t size, int encoding, int type);
|
|
47
|
+
PyObject *
|
|
48
|
+
cast_other(char *s, Py_ssize_t size, int encoding, Oid pgtype,
|
|
49
|
+
PyObject *cast_hook);
|
|
50
|
+
PyObject *
|
|
51
|
+
cast_sized_simple(char *s, Py_ssize_t size, int type);
|
|
52
|
+
PyObject *
|
|
53
|
+
cast_unsized_simple(char *s, int type);
|
|
54
|
+
PyObject *
|
|
55
|
+
cast_array(char *s, Py_ssize_t size, int encoding, int type, PyObject *cast,
|
|
56
|
+
char delim);
|
|
57
|
+
PyObject *
|
|
58
|
+
cast_record(char *s, Py_ssize_t size, int encoding, int *type, PyObject *cast,
|
|
59
|
+
Py_ssize_t len, char delim);
|
|
60
|
+
PyObject *
|
|
61
|
+
cast_hstore(char *s, Py_ssize_t size, int encoding);
|
|
62
|
+
|
|
63
|
+
/* Error helpers */
|
|
64
|
+
void
|
|
65
|
+
set_error_msg(PyObject *type, const char *msg);
|
|
66
|
+
void
|
|
67
|
+
set_error(PyObject *type, const char *msg, PGconn *cnx, PGresult *result);
|
|
68
|
+
|
|
69
|
+
/* SSL attributes helper */
|
|
70
|
+
PyObject *
|
|
71
|
+
get_ssl_attributes(PGconn *cnx);
|
|
72
|
+
|
|
73
|
+
/* Date style helpers */
|
|
74
|
+
const char *
|
|
75
|
+
date_style_to_format(const char *s);
|
|
76
|
+
const char *
|
|
77
|
+
date_format_to_style(const char *s);
|
|
78
|
+
|
|
79
|
+
/* Notice receiver */
|
|
80
|
+
void
|
|
81
|
+
notice_receiver(void *arg, const PGresult *res);
|
|
82
|
+
|
|
83
|
+
/* Char buffer helpers */
|
|
84
|
+
int
|
|
85
|
+
init_char_buffer(struct CharBuffer *buf, size_t initial_size);
|
|
86
|
+
void
|
|
87
|
+
ext_char_buffer_s(struct CharBuffer *buf, const char *s);
|
|
88
|
+
void
|
|
89
|
+
ext_char_buffer_c(struct CharBuffer *buf, char c);
|
|
90
|
+
|
|
91
|
+
#endif /* PYGRE_SQL_PGINTERNAL_H */
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* Please see the LICENSE.TXT file for specific restrictions.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/* Shared headers */
|
|
12
|
+
#include "pginternal.h"
|
|
13
|
+
#include "pgmodule.h"
|
|
14
|
+
|
|
11
15
|
/* Deallocate large object. */
|
|
12
16
|
static void
|
|
13
17
|
large_dealloc(largeObject *self)
|
|
@@ -28,10 +32,10 @@ static PyObject *
|
|
|
28
32
|
large_str(largeObject *self)
|
|
29
33
|
{
|
|
30
34
|
char str[80];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
snprintf(str, sizeof(str),
|
|
36
|
+
self->lo_fd >= 0 ? "Opened large object, oid %ld"
|
|
37
|
+
: "Closed large object, oid %ld",
|
|
38
|
+
(long)self->lo_oid);
|
|
35
39
|
return PyUnicode_FromString(str);
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -69,6 +73,8 @@ static PyObject *
|
|
|
69
73
|
large_getattr(largeObject *self, PyObject *nameobj)
|
|
70
74
|
{
|
|
71
75
|
const char *name = PyUnicode_AsUTF8(nameobj);
|
|
76
|
+
if (!name)
|
|
77
|
+
return NULL;
|
|
72
78
|
|
|
73
79
|
/* list postgreSQL large object fields */
|
|
74
80
|
|
|
@@ -423,7 +429,7 @@ static struct PyMethodDef large_methods[] = {
|
|
|
423
429
|
static char large__doc__[] = "PostgreSQL large object";
|
|
424
430
|
|
|
425
431
|
/* Large object type definition */
|
|
426
|
-
|
|
432
|
+
PyTypeObject largeType = {
|
|
427
433
|
PyVarObject_HEAD_INIT(NULL, 0) "pg.LargeObject", /* tp_name */
|
|
428
434
|
sizeof(largeObject), /* tp_basicsize */
|
|
429
435
|
0, /* tp_itemsize */
|