summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2000-09-11 15:34:14 +0000
committerDerick Rethans <derick@php.net>2000-09-11 15:34:14 +0000
commit68611e2d5545c370449d57aef3db6910d768a6b1 (patch)
tree61611d395589cd54bbca0d4b01e788a20cae9d9e /ext/pgsql
parent2e0ae6d25f6cc2068e1e30c641e870dab52b1721 (diff)
downloadphp-git-68611e2d5545c370449d57aef3db6910d768a6b1.tar.gz
- Added functions pg_putline and pg_endcopy (thanks to Dirk Elmendorf
<delmendo@rackspace.com>) @ Added functions pg_putline and pg_endcopy (Dirk Elmendorf)
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/pgsql.c86
-rw-r--r--ext/pgsql/php_pgsql.h2
2 files changed, 88 insertions, 0 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 947fd2a009..c0afb1989c 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -75,6 +75,8 @@ function_entry pgsql_functions[] = {
PHP_FE(pg_loreadall, NULL)
PHP_FE(pg_loimport, NULL)
PHP_FE(pg_loexport, NULL)
+ PHP_FE(pg_putline, NULL)
+ PHP_FE(pg_endcopy, NULL)
#if HAVE_PQCLIENTENCODING
PHP_FE(pg_clientencoding, NULL)
PHP_FE(pg_setclientencoding, NULL)
@@ -645,7 +647,91 @@ PHP_FUNCTION(pg_exec)
}
}
/* }}} */
+/* {{{ proto int pg_endcopy([int connection])
+ Sync with backend. Completes the Copy command */
+PHP_FUNCTION(pg_endcopy)
+{
+ zval **query, **pgsql_link;
+ int id = -1;
+ PGconn *pgsql;
+ int result = 0;
+ ExecStatusType status;
+ pgsql_result_handle *pg_result;
+ PGLS_FETCH();
+
+ switch(ZEND_NUM_ARGS()) {
+ case 1:
+ if (zend_get_parameters_ex(1, &query)==FAILURE) {
+ RETURN_FALSE;
+ }
+ id = PGG(default_link);
+ break;
+ case 2:
+ if (zend_get_parameters_ex(2, &pgsql_link, &query)==FAILURE) {
+ RETURN_FALSE;
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink);
+
+ convert_to_string_ex(query);
+ result = PQendcopy(pgsql);
+
+/* if (result!=0)
+ {
+ php_error(E_WARNING, "PostgreSQL query failed: %s", PQerrorMessage(pgsql));
+ RETURN_FALSE;
+ } */
+ RETURN_FALSE;
+}
+/* }}} */
+/* {{{ proto int pg_putline([int connection,] string query)
+ Send null-terminated string to backend server*/
+PHP_FUNCTION(pg_putline)
+{
+ zval **query, **pgsql_link;
+ int id = -1;
+ PGconn *pgsql;
+ int result = 0;
+ ExecStatusType status;
+ pgsql_result_handle *pg_result;
+ PGLS_FETCH();
+
+ switch(ZEND_NUM_ARGS()) {
+ case 1:
+ if (zend_get_parameters_ex(1, &query)==FAILURE) {
+ RETURN_FALSE;
+ }
+ id = PGG(default_link);
+ break;
+ case 2:
+ if (zend_get_parameters_ex(2, &pgsql_link, &query)==FAILURE) {
+ RETURN_FALSE;
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink);
+
+ convert_to_string_ex(query);
+ result = PQputline(pgsql, Z_STRVAL_PP(query));
+
+ if (result==EOF)
+ {
+ php_error(E_WARNING, "PostgreSQL query failed: %s", PQerrorMessage(pgsql));
+ RETURN_FALSE;
+ }
+ RETURN_FALSE;
+}
+/* }}} */
#define PHP_PG_NUM_ROWS 1
#define PHP_PG_NUM_FIELDS 2
#define PHP_PG_CMD_TUPLES 3
diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h
index 9101128dc8..445f5664dd 100644
--- a/ext/pgsql/php_pgsql.h
+++ b/ext/pgsql/php_pgsql.h
@@ -85,6 +85,8 @@ PHP_FUNCTION(pg_lowrite);
PHP_FUNCTION(pg_loreadall);
PHP_FUNCTION(pg_loimport);
PHP_FUNCTION(pg_loexport);
+PHP_FUNCTION(pg_putline);
+PHP_FUNCTION(pg_endcopy);
#if HAVE_PQCLIENTENCODING
PHP_FUNCTION(pg_clientencoding);
PHP_FUNCTION(pg_setclientencoding);