mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
ext/pgsql: adding pg_put_copy_data/pg_put_copy_end.
pg_put_copy_data allows to send COPY commands to the server. pg_put_copy_end signals the end of the n commands. Both return 3 states ; 1, 0 and -1 when 1 is success, 0 the buffer queue is full then -1 for errors. Close GH-14325
This commit is contained in:
parent
cc6d9523d9
commit
162a311cc8
6 changed files with 153 additions and 1 deletions
|
@ -6123,3 +6123,45 @@ PHP_FUNCTION(pg_change_password)
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
PHP_FUNCTION(pg_put_copy_data)
|
||||
{
|
||||
zval *pgsql_link;
|
||||
pgsql_link_handle *link;
|
||||
zend_string *cmd;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(2, 2)
|
||||
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
|
||||
Z_PARAM_STR(cmd)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
link = Z_PGSQL_LINK_P(pgsql_link);
|
||||
CHECK_PGSQL_LINK(link);
|
||||
|
||||
// PQputCopyData accepts empty buffers as well
|
||||
|
||||
RETURN_LONG((zend_long)PQputCopyData(link->conn, ZSTR_VAL(cmd), ZSTR_LEN(cmd)));
|
||||
}
|
||||
|
||||
PHP_FUNCTION(pg_put_copy_end)
|
||||
{
|
||||
zval *pgsql_link;
|
||||
pgsql_link_handle *link;
|
||||
zend_string *error;
|
||||
char *err = NULL;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 2)
|
||||
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
|
||||
Z_PARAM_OPTIONAL
|
||||
Z_PARAM_STR_OR_NULL(error)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
link = Z_PGSQL_LINK_P(pgsql_link);
|
||||
CHECK_PGSQL_LINK(link);
|
||||
|
||||
if (error != NULL && ZSTR_LEN(error) != 0) {
|
||||
err = ZSTR_VAL(error);
|
||||
}
|
||||
|
||||
RETURN_LONG((zend_long)PQputCopyEnd(link->conn, err));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue