php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #6219 PQendcopy /PQputline missing
Submitted: 2000-08-17 12:18 UTC Modified: 2000-09-11 23:40 UTC
From: dirk at rackspace dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.1pl2 OS: Linux RH 6.2
Private report: No CVE-ID: None
 [2000-08-17 12:18 UTC] dirk at rackspace dot com
The Postgres module seems to be missing all the copy functions.  I needed the PQendcopy / PQputline.  I haven't writted PQgetline.  I'm not sure what the normal procedure is for submitting code to PHP (first time for me) This is mostly based on the existing postgresql code.

I have included a patch to add these to the current version of php4. I'm using this patch actively , but I wouldn't mind some help testing it.  Please consider this for inclusion into the code base.



--- php-4.0.1pl2/ext/pgsql/pgsql.c  Tue Jun 27 08:26:04 2000
+++ php-4.0.1pl2/ext/pgsql/pgsql.c.dirk Wed Aug  9 10:33:29 2000
@@ -74,6 +74,8 @@
    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)
    {NULL, NULL, NULL}
 };

@@ -636,7 +638,91 @@
    }
 }
 /* }}} */
+/* {{{ 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
--- php-4.0.1pl2/ext/pgsql/php_pgsql.h  Sat Jun 10 03:47:57 2000
+++ php-4.0.1pl2/ext/pgsql/php_pgsql.h.dirk Wed Aug  9 10:33:29 2000
@@ -85,6 +85,8 @@
 PHP_FUNCTION(pg_loreadall);
 PHP_FUNCTION(pg_loimport);
 PHP_FUNCTION(pg_loexport);
+PHP_FUNCTION(pg_putline);
+PHP_FUNCTION(pg_endcopy);

 void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
 int php_pgsql_get_default_link(INTERNAL_FUNCTION_PARAMETERS);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-21 10:45 UTC] dirk at rackspace dot com
Sorry nothing seemed to happen to this patch while it was under the postgresql.
 [2000-09-11 23:40 UTC] derick@php.net
Added in CVS
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Fri Jun 19 09:00:02 2026 UTC