mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-08-04 04:10:09 +03:00
Testing functionality of COPY ... FROM ... WITH FORMAT CSV QUOTE AS %s (without paramterizing the function yet...)
This commit is contained in:
parent
90ee1ebba5
commit
b6a7470454
|
@ -1343,14 +1343,17 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
const char *sep = "\t";
|
const char *sep = "\t";
|
||||||
const char *null = "\\N";
|
const char *null = "\\N";
|
||||||
|
const char *quote = "'";
|
||||||
|
|
||||||
const char *command =
|
const char *command =
|
||||||
"COPY %s%s FROM stdin WITH DELIMITER AS %s NULL AS %s";
|
"COPY %s%s FROM stdin WITH DELIMITER AS %s NULL AS %s FORMAT AS CSV QUOTE AS %s";
|
||||||
|
|
||||||
Py_ssize_t query_size;
|
Py_ssize_t query_size;
|
||||||
char *query = NULL;
|
char *query = NULL;
|
||||||
char *columnlist = NULL;
|
char *columnlist = NULL;
|
||||||
char *quoted_delimiter = NULL;
|
char *quoted_delimiter = NULL;
|
||||||
char *quoted_null = NULL;
|
char *quoted_null = NULL;
|
||||||
|
char *quoted_quote = NULL;
|
||||||
|
|
||||||
const char *table_name;
|
const char *table_name;
|
||||||
Py_ssize_t bufsize = DEFAULT_COPYBUFF;
|
Py_ssize_t bufsize = DEFAULT_COPYBUFF;
|
||||||
|
@ -1382,15 +1385,19 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(quoted_quote = psycopg_escape_string(
|
||||||
|
self->conn, quote, 0, NULL, NULL))) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
query_size = strlen(command) + strlen(table_name) + strlen(columnlist)
|
query_size = strlen(command) + strlen(table_name) + strlen(columnlist)
|
||||||
+ strlen(quoted_delimiter) + strlen(quoted_null) + 1;
|
+ strlen(quoted_delimiter) + strlen(quoted_null) strlen(quoted_quote) + 1;
|
||||||
if (!(query = PyMem_New(char, query_size))) {
|
if (!(query = PyMem_New(char, query_size))) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyOS_snprintf(query, query_size, command,
|
PyOS_snprintf(query, query_size, command,
|
||||||
table_name, columnlist, quoted_delimiter, quoted_null);
|
table_name, columnlist, quoted_delimiter, quoted_null, quoted_quote);
|
||||||
|
|
||||||
Dprintf("psyco_curs_copy_from: query = %s", query);
|
Dprintf("psyco_curs_copy_from: query = %s", query);
|
||||||
|
|
||||||
|
@ -1409,6 +1416,7 @@ exit:
|
||||||
PyMem_Free(columnlist);
|
PyMem_Free(columnlist);
|
||||||
PyMem_Free(quoted_delimiter);
|
PyMem_Free(quoted_delimiter);
|
||||||
PyMem_Free(quoted_null);
|
PyMem_Free(quoted_null);
|
||||||
|
PyMem_Free(quoted_quote);
|
||||||
PyMem_Free(query);
|
PyMem_Free(query);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user