diff options
author | Thies C. Arntzen <thies@php.net> | 1999-09-13 11:49:07 +0000 |
---|---|---|
committer | Thies C. Arntzen <thies@php.net> | 1999-09-13 11:49:07 +0000 |
commit | c21663b3e786b5fdfdc8a96a5ed82fd5d566cd98 (patch) | |
tree | 78aac476bb77f47b756faec2cbdc958783063dbc /ext/oci8 | |
parent | af1e5ad88148fc7aa23879ce2ef69d422a3a8f39 (diff) | |
download | php-git-c21663b3e786b5fdfdc8a96a5ed82fd5d566cd98.tar.gz |
ported $lob->savefile($filename) method from PHP3
Diffstat (limited to 'ext/oci8')
-rw-r--r-- | ext/oci8/oci8.c | 108 |
1 files changed, 103 insertions, 5 deletions
diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index 69288b315d..12b3586346 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -77,6 +77,8 @@ static zend_class_entry *oci_lob_class_entry_ptr; #include "build-defs.h" #endif +#include <fcntl.h> + #include "snprintf.h" /* }}} */ @@ -172,6 +174,7 @@ PHP_FUNCTION(ociplogon); PHP_FUNCTION(ocierror); PHP_FUNCTION(ocifreedesc); PHP_FUNCTION(ocisavelob); +PHP_FUNCTION(ocisavelobfile); PHP_FUNCTION(ociloadlob); PHP_FUNCTION(ocicommit); PHP_FUNCTION(ocirollback); @@ -224,9 +227,10 @@ static zend_function_entry php_oci_functions[] = { PHP_FE(ocinlogon, NULL) PHP_FE(ociplogon, NULL) PHP_FE(ocierror, NULL) - PHP_FE(ocifreedesc,NULL) - PHP_FE(ocisavelob, NULL) - PHP_FE(ociloadlob, NULL) + PHP_FE(ocifreedesc, NULL) + PHP_FE(ocisavelob, NULL) + PHP_FE(ocisavelobfile, NULL) + PHP_FE(ociloadlob, NULL) PHP_FE(ocicommit, NULL) PHP_FE(ocirollback, NULL) PHP_FE(ocinewdescriptor, NULL) @@ -235,8 +239,9 @@ static zend_function_entry php_oci_functions[] = { }; static zend_function_entry php_oci_lob_class_functions[] = { - PHP_FALIAS(load, ociloadlob, NULL) - PHP_FALIAS(save, ocisavelob, NULL) + PHP_FALIAS(load, ociloadlob, NULL) + PHP_FALIAS(save, ocisavelob, NULL) + PHP_FALIAS(savefile,ocisavelobfile, NULL) PHP_FALIAS(free, ocifreedesc, NULL) {NULL,NULL,NULL} }; @@ -2532,6 +2537,99 @@ PHP_FUNCTION(ocisavelob) } /* }}} */ +/* {{{ proto string ocisavelobfile(object lob) + */ + +PHP_FUNCTION(ocisavelobfile) +{ + pval *id, **tmp, **conn, *arg; + OCILobLocator *mylob; + oci_connection *connection; + oci_descriptor *descr; + char *filename; + int fp; + char buf[8192]; + ub4 offset = 1; + ub4 loblen; + + if ((id = getThis()) != 0) { + if (zend_hash_find(id->value.obj.properties, "connection", sizeof("connection"), (void **)&conn) == FAILURE) { + php_error(E_WARNING, "unable to find my statement property"); + RETURN_FALSE; + } + + connection = oci_get_conn((*conn)->value.lval, "OCIsavelob", list); + if (connection == NULL) { + RETURN_FALSE; + } + + if (zend_hash_find(id->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { + php_error(E_WARNING, "unable to find my locator property"); + RETURN_FALSE; + } + + if (zend_hash_index_find(connection->descriptors, (*tmp)->value.lval, (void **)&descr) == FAILURE) { + php_error(E_WARNING, "unable to find my descriptor %d",(*tmp)->value.lval); + RETURN_FALSE; + } + + mylob = (OCILobLocator *) descr->ocidescr; + + if (! mylob) { + RETURN_FALSE; + } + + if (getParameters(ht, 1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string(arg); + + if (_php3_check_open_basedir(arg->value.str.val)) { + RETURN_FALSE; + } + + filename = arg->value.str.val; + + if ((fp = open(filename, O_RDONLY)) == -1) { + php_error(E_WARNING, "Can't open file %s", filename); + RETURN_FALSE; + } + + while ((loblen = read(fp, &buf, sizeof(buf))) > 0) { + connection->error = + OCILobWrite(connection->pServiceContext, + connection->pError, + mylob, + &loblen, + (ub4) offset, + (dvoid *) &buf, + (ub4) loblen, + OCI_ONE_PIECE, + (dvoid *)0, + (OCICallbackLobWrite) 0, + (ub2) 0, + (ub1) SQLCS_IMPLICIT); + + oci_debug("OCIsavelob: size=%d",loblen); + + if (connection->error) { + oci_error(connection->pError, "OCILobWrite", connection->error); + close(fp); + RETURN_FALSE; + } + + offset += loblen; + } + close(fp); + + RETURN_TRUE; + } + + RETURN_FALSE; +} + +/* }}} */ /* {{{ proto string ociloadlob(object lob) */ |