Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -3350,9 +3350,8 @@ PHP_FUNCTION(pg_copy_to)
pgsql_link_handle *link;
zend_string *table_name;
zend_string *pg_delimiter = NULL;
char *pg_null_as = NULL;
char *pg_null_as = "\\\\N";
size_t pg_null_as_len = 0;
bool free_pg_null = false;
char *query;
PGconn *pgsql;
PGresult *pgsql_result;
Expand All @@ -3377,20 +3376,13 @@ PHP_FUNCTION(pg_copy_to)
zend_argument_value_error(3, "must be one character");
RETURN_THROWS();
}
if (!pg_null_as) {
pg_null_as = estrdup("\\\\N");
free_pg_null = true;
}

spprintf(&query, 0, "COPY %s TO STDOUT DELIMITER E'%c' NULL AS E'%s'", ZSTR_VAL(table_name), *ZSTR_VAL(pg_delimiter), pg_null_as);

while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
}
pgsql_result = PQexec(pgsql, query);
if (free_pg_null) {
efree(pg_null_as);
}
efree(query);

if (pgsql_result) {
Expand Down Expand Up @@ -3475,9 +3467,8 @@ PHP_FUNCTION(pg_copy_from)
zval *value;
zend_string *table_name;
zend_string *pg_delimiter = NULL;
char *pg_null_as = NULL;
char *pg_null_as = "\\\\N";
size_t pg_null_as_len;
bool pg_null_as_free = false;
char *query;
PGconn *pgsql;
PGresult *pgsql_result;
Expand All @@ -3502,20 +3493,13 @@ PHP_FUNCTION(pg_copy_from)
zend_argument_value_error(4, "must be one character");
RETURN_THROWS();
}
if (!pg_null_as) {
pg_null_as = estrdup("\\\\N");
pg_null_as_free = true;
}

spprintf(&query, 0, "COPY %s FROM STDIN DELIMITER E'%c' NULL AS E'%s'", ZSTR_VAL(table_name), *ZSTR_VAL(pg_delimiter), pg_null_as);
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
}
pgsql_result = PQexec(pgsql, query);

if (pg_null_as_free) {
efree(pg_null_as);
}
efree(query);

if (pgsql_result) {
Expand Down