Testing functionality of COPY ... FROM ... WITH FORMAT CSV QUOTE AS %s (without paramterizing the function yet...)

This commit is contained in:
Sean Harrington 2016-07-29 10:53:26 -04:00
parent 90ee1ebba5
commit b6a7470454

View File

@ -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;