]> granicus.if.org Git - php/commitdiff
- Added functions pg_loimport(), pg_loexport().
authorJouni Ahto <jah@php.net>
Sun, 4 Jun 2000 20:24:07 +0000 (20:24 +0000)
committerJouni Ahto <jah@php.net>
Sun, 4 Jun 2000 20:24:07 +0000 (20:24 +0000)
@- Added functions pg_loimport(), pg_loexport(). (Jouni)

ext/pgsql/pgsql.c
ext/pgsql/php_pgsql.h

index fbe0d6fe4c318835e8e1b5592a440464f3b23ab3..c0d11b9e5766efdae7a4d57b62d1f3139a0153ac 100644 (file)
@@ -76,6 +76,8 @@ function_entry pgsql_functions[] = {
        PHP_FE(pg_loread,               NULL)
        PHP_FE(pg_lowrite,              NULL)
        PHP_FE(pg_loreadall,    NULL)
+       PHP_FE(pg_loimport,             NULL)
+       PHP_FE(pg_loexport,             NULL)
        {NULL, NULL, NULL}
 };
 
@@ -1510,6 +1512,95 @@ PHP_FUNCTION(pg_loreadall)
        return_value->type = IS_LONG;
 }
 /* }}} */
+
+/* {{{ proto int pg_loimport(string filename[, resource connection])
+   Import large object direct from filesystem */
+PHP_FUNCTION(pg_loimport)
+{
+       zval **pgsql_link, **file_in;
+       int id = -1;
+       PGconn *pgsql;
+       Oid oid;
+       PLS_FETCH();
+       PGLS_FETCH();
+       
+       switch (ZEND_NUM_ARGS()) {
+               case 1:
+                       if (zend_get_parameters_ex(1, &file_in) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+                       id = PGG(default_link);
+                       break;
+               case 2:
+                       if (zend_get_parameters_ex(2, &file_in, &pgsql_link) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+                       convert_to_string_ex(file_in);
+                       break;
+               default:
+                       WRONG_PARAM_COUNT;
+                       break;
+       }
+       
+       if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(file_in), 2))) {
+               RETURN_FALSE;
+       }
+
+       ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink);
+
+       oid = lo_import(pgsql, Z_STRVAL_PP(file_in));
+
+       if (oid > 0) {
+               RETURN_LONG((int)oid);
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
+/* {{{ proto int pg_loexport(int objoid, string filename[, resource connection])
+   Emport large object direct to filesystem */
+PHP_FUNCTION(pg_loexport)
+{
+       zval **pgsql_link, **oid_id, **file_out;
+       int id = -1;
+       Oid oid;
+       PGconn *pgsql;
+       PGLS_FETCH();
+       
+       switch (ZEND_NUM_ARGS()) {
+               case 2:
+                       if (zend_get_parameters_ex(2, &oid_id, &file_out) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+                       convert_to_long_ex(oid_id);
+                       convert_to_string_ex(file_out);
+                       id = PGG(default_link);
+                       break;
+               case 3:
+                       if (zend_get_parameters_ex(3, &oid_id, &file_out, &pgsql_link) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+                       convert_to_long_ex(oid_id);
+                       convert_to_string_ex(file_out);
+                       break;
+               default:
+                       WRONG_PARAM_COUNT;
+                       break;
+       }
+       
+       ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink);
+
+       oid = (Oid) Z_LVAL_PP(oid_id);
+
+       if (lo_export(pgsql, oid, Z_STRVAL_PP(file_out))) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
        
 #endif
 
@@ -1519,3 +1610,4 @@ PHP_FUNCTION(pg_loreadall)
  * c-basic-offset: 4
  * End:
  */
+
index c645eaafb8e39a953f2d2b6858952e4671e0408b..e637532e93e6259812ed34f862086bd30ccb4b1b 100644 (file)
@@ -1,29 +1,19 @@
 /*
    +----------------------------------------------------------------------+
-   | PHP HTML Embedded Scripting Language Version 3.0                     |
+   | PHP version 4.0                                                      |
    +----------------------------------------------------------------------+
-   | Copyright (c) 1997,1998 PHP Development Team (See Credits file)      |
+   | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
    +----------------------------------------------------------------------+
-   | This program is free software; you can redistribute it and/or modify |
-   | it under the terms of one of the following licenses:                 |
-   |                                                                      |
-   |  A) the GNU General Public License as published by the Free Software |
-   |     Foundation; either version 2 of the License, or (at your option) |
-   |     any later version.                                               |
-   |                                                                      |
-   |  B) the PHP License as published by the PHP Development Team and     |
-   |     included in the distribution in the file: LICENSE                |
-   |                                                                      |
-   | This program is distributed in the hope that it will be useful,      |
-   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
-   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
-   | GNU General Public License for more details.                         |
-   |                                                                      |
-   | You should have received a copy of both licenses referred to here.   |
-   | If you did not, or have any questions about PHP licensing, please    |
-   | contact core@php.net.                                                |
+   | This source file is subject to version 2.02 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available at through the world-wide-web at                           |
+   | http://www.php.net/license/2_02.txt.                                 |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
    +----------------------------------------------------------------------+
-   | Authors: Jouni Ahto                                                  |
+   | Authors: Zeev Suraski <zeev@zend.com>                                |
+   |          Jouni Ahto <jah@mork.net>                                   |
    +----------------------------------------------------------------------+
  */
  
@@ -98,6 +88,8 @@ PHP_FUNCTION(pg_loclose);
 PHP_FUNCTION(pg_loread);
 PHP_FUNCTION(pg_lowrite);
 PHP_FUNCTION(pg_loreadall);
+PHP_FUNCTION(pg_loimport);
+PHP_FUNCTION(pg_loexport);
 
 void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
 int php_pgsql_get_default_link(INTERNAL_FUNCTION_PARAMETERS);