summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2009-08-09 15:13:42 +0200
committerFederico Di Gregorio <fog@initd.org>2009-08-09 15:13:42 +0200
commit4c3e2ad94ba7434e02f77b34f0cc032363316ee9 (patch)
tree2e440be7e1abe0db167946a781977545320f2b3d
parente5a696ad58733e22928b23a1cf55ba72d01f7260 (diff)
downloadpsycopg2-4c3e2ad94ba7434e02f77b34f0cc032363316ee9.tar.gz
Fixed problem with lots of columns in COPY operations
-rw-r--r--ChangeLog6
-rw-r--r--psycopg/cursor.h2
-rw-r--r--psycopg/cursor_type.c22
-rw-r--r--psycopg2.cproj3
4 files changed, 19 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 04500a4..cf28058 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-08-08 Federico Di Gregorio <fog@initd.org>
+
+ * psycopg/cursor_type.c: unified size macro definitions in COPY TO
+ and COPY FROM operations: now the buffer for column names is 8192
+ bytes that should be enough even for very large tables.
+
2009-05-19 Federico Di Gregorio <fog@initd.org>
* Applied patch from Robert Munro to fix version check
diff --git a/psycopg/cursor.h b/psycopg/cursor.h
index 355dd27..c5b3426 100644
--- a/psycopg/cursor.h
+++ b/psycopg/cursor.h
@@ -64,7 +64,7 @@ typedef struct {
PyObject *copyfile; /* file-like used during COPY TO/FROM ops */
Py_ssize_t copysize; /* size of the copy buffer during COPY TO/FROM ops */
#define DEFAULT_COPYSIZE 16384
-#define DEFAULT_COPYBUFF 1024
+#define DEFAULT_COPYBUFF 8132
PyObject *tuple_factory; /* factory for result tuples */
PyObject *tzinfo_factory; /* factory for tzinfo objects */
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c
index 82e390b..b79446d 100644
--- a/psycopg/cursor_type.c
+++ b/psycopg/cursor_type.c
@@ -1127,8 +1127,6 @@ psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs)
#ifdef PSYCOPG_EXTENSIONS
-#define COPY_BUFFER_SIZE 8192
-
static int _psyco_curs_copy_columns(PyObject *columns, char *columnlist)
{
PyObject *col, *coliter;
@@ -1201,7 +1199,7 @@ _psyco_curs_has_read_check(PyObject* o, void* var)
static PyObject *
psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
{
- char query_buffer[COPY_BUFFER_SIZE];
+ char query_buffer[DEFAULT_COPYBUFF];
Py_ssize_t query_size;
char *query;
const char *table_name;
@@ -1241,10 +1239,10 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
PyErr_NoMemory();
return NULL;
}
- query_size = PyOS_snprintf(query, COPY_BUFFER_SIZE,
+ query_size = PyOS_snprintf(query, DEFAULT_COPYBUFF,
"COPY %s%s FROM stdin WITH DELIMITER AS %s NULL AS %s",
table_name, columnlist, quoted_delimiter, quoted_null);
- if (query_size >= COPY_BUFFER_SIZE) {
+ if (query_size >= DEFAULT_COPYBUFF) {
/* Got truncated, allocate dynamically */
query = (char *)PyMem_Malloc((query_size + 1) * sizeof(char));
PyOS_snprintf(query, query_size + 1,
@@ -1254,10 +1252,10 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
PyMem_Free(quoted_null);
}
else {
- query_size = PyOS_snprintf(query, COPY_BUFFER_SIZE,
+ query_size = PyOS_snprintf(query, DEFAULT_COPYBUFF,
"COPY %s%s FROM stdin WITH DELIMITER AS %s",
table_name, columnlist, quoted_delimiter);
- if (query_size >= COPY_BUFFER_SIZE) {
+ if (query_size >= DEFAULT_COPYBUFF) {
/* Got truncated, allocate dynamically */
query = (char *)PyMem_Malloc((query_size + 1) * sizeof(char));
PyOS_snprintf(query, query_size + 1,
@@ -1310,7 +1308,7 @@ static PyObject *
psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
{
char *query = NULL;
- char query_buffer[COPY_BUFFER_SIZE];
+ char query_buffer[DEFAULT_COPYBUFF];
size_t query_size;
char columnlist[DEFAULT_COPYBUFF];
const char *table_name;
@@ -1344,10 +1342,10 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
PyErr_NoMemory();
return NULL;
}
- query_size = PyOS_snprintf(query, COPY_BUFFER_SIZE,
+ query_size = PyOS_snprintf(query, DEFAULT_COPYBUFF,
"COPY %s%s TO stdout WITH DELIMITER AS %s"
" NULL AS %s", table_name, columnlist, quoted_delimiter, quoted_null);
- if (query_size >= COPY_BUFFER_SIZE) {
+ if (query_size >= DEFAULT_COPYBUFF) {
/* Got truncated, allocate dynamically */
query = (char *)PyMem_Malloc((query_size + 1) * sizeof(char));
PyOS_snprintf(query, query_size + 1,
@@ -1357,10 +1355,10 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
PyMem_Free(quoted_null);
}
else {
- query_size = PyOS_snprintf(query, COPY_BUFFER_SIZE,
+ query_size = PyOS_snprintf(query, DEFAULT_COPYBUFF,
"COPY %s%s TO stdout WITH DELIMITER AS %s",
table_name, columnlist, quoted_delimiter);
- if (query_size >= COPY_BUFFER_SIZE) {
+ if (query_size >= DEFAULT_COPYBUFF) {
/* Got truncated, allocate dynamically */
query = (char *)PyMem_Malloc((query_size + 1) * sizeof(char));
PyOS_snprintf(query, query_size + 1,
diff --git a/psycopg2.cproj b/psycopg2.cproj
index 23f5b35..a61d7a7 100644
--- a/psycopg2.cproj
+++ b/psycopg2.cproj
@@ -175,7 +175,8 @@
<ChangeLogPolicy UpdateMode="Nearest" VcsIntegration="None" inheritsSet="Mono">
<MessageStyle FileSeparator=", " LineAlign="0" />
</ChangeLogPolicy>
- <TextStylePolicy FileWidth="144" TabWidth="4" TabsToSpaces="True" NoTabsAfterNonTabs="False" RemoveTrailingWhitespace="True" EolMarker="Native" />
+ <TextStylePolicy FileWidth="144" RemoveTrailingWhitespace="True" inheritsSet="VisualStudio" inheritsScope="text/plain" />
+ <TextStylePolicy NoTabsAfterNonTabs="True" RemoveTrailingWhitespace="True" inheritsSet="Mono" inheritsScope="text/plain" scope="text/x-changelog" />
</Policies>
</Properties>
</MonoDevelop>