Date: 08/07/99
- Next message: Stig Venaas: "[PHP-DEV] cvs: /php3/functions ldap.c php3_ldap.h"
- Previous message: animate2 <email protected>: "[PHP-DEV] Bug #1987: ImageTTFBBox does not return correct bounding box."
- Next in thread: Andreas Karajannis: "[PHP-DEV] cvs: /php3/functions oci8.c"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
kara Sat Aug 7 07:47:38 1999 EDT
Modified files:
/php3/functions oci8.c
Log:
Direct LOB upload changed to having it's own method: $lob->savefile($filename)
Index: php3/functions/oci8.c
diff -u php3/functions/oci8.c:1.116 php3/functions/oci8.c:1.117
--- php3/functions/oci8.c:1.116 Wed Aug 4 14:23:57 1999
+++ php3/functions/oci8.c Sat Aug 7 07:47:38 1999
@@ -33,7 +33,7 @@
#define OCI8_USE_EMALLOC 0 /* set this to 1 if you want to use the php memory manager! */
-/* $Id: oci8.c,v 1.116 1999/08/04 18:23:57 kara Exp $ */
+/* $Id: oci8.c,v 1.117 1999/08/07 11:47:38 kara Exp $ */
/* TODO list:
*
@@ -234,6 +234,7 @@
PHP_FUNCTION(oci8_error);
PHP_FUNCTION(oci8_freedesc);
PHP_FUNCTION(oci8_savedesc);
+PHP_FUNCTION(oci8_savedescfile);
PHP_FUNCTION(oci8_loaddesc);
PHP_FUNCTION(oci8_commit);
PHP_FUNCTION(oci8_rollback);
@@ -289,6 +290,7 @@
{"ocierror", php3_oci8_error, NULL},
{"ocifreedescriptor",php3_oci8_freedesc, NULL},
{"ocisavedesc", php3_oci8_savedesc, NULL},
+ {"ocisavedescfile", php3_oci8_savedescfile, NULL},
{"ociloaddesc", php3_oci8_loaddesc, NULL},
{"ocicommit", php3_oci8_commit, NULL},
{"ocirollback", php3_oci8_rollback, NULL},
@@ -929,6 +931,7 @@
if (column->data_type != SQLT_RDD) { /* ROWIDs don't have any user-callable methods */
if ((column->data_type != SQLT_BFILEE) && (column->data_type != SQLT_CFILEE)) {
add_method(value, "save", php3_oci8_savedesc); /* oracle does not support writing of files as of now */
+ add_method(value, "savefile", php3_oci8_savedescfile);
}
add_method(value, "load", php3_oci8_loaddesc);
}
@@ -2613,23 +2616,100 @@
WRONG_PARAM_COUNT;
}
- if(arg->value.str.val[0] == '\'') {
- char buf[8192];
- int fp;
- ub4 offset = 1;
- char *filename;
+ loblen = arg->value.str.len;
+
+ if (loblen < 1) {
+ php3_error(E_WARNING, "Cannot save a lob wich size is less than 1 byte");
+ RETURN_FALSE;
+ }
- /* read directly from file */
- filename = &arg->value.str.val[1];
-
- filename[arg->value.str.len - 2] = '\0';
- if ((fp = open(filename, O_RDONLY)) == -1) {
- php3_error(E_WARNING, "Can't open file %s", filename);
- RETURN_FALSE;
- }
- while((loblen = read(fp, &buf, 8192)) > 0){
- connection->error =
- OCILobWrite(connection->pServiceContext,
+ connection->error =
+ OCILobWrite(connection->pServiceContext,
+ connection->pError,
+ mylob,
+ &loblen,
+ (ub4) 1,
+ (dvoid *) arg->value.str.val,
+ (ub4) loblen,
+ OCI_ONE_PIECE,
+ (dvoid *)0,
+ (OCICallbackLobWrite) 0,
+ (ub2) 0,
+ (ub1) SQLCS_IMPLICIT );
+
+ oci8_debug("OCIsavedesc: size=%d",loblen);
+
+ if (connection->error) {
+ oci8_error(connection->pError, "OCILobWrite", connection->error);
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+ }
+ RETURN_FALSE;
+}
+
+/* }}} */
+/* {{{ proto string ocisavedescfile(object lob)
+ * */
+
+PHP_FUNCTION(oci8_savedescfile)
+{
+ pval *id, *tmp, *conn, *arg;
+ OCILobLocator *mylob;
+ oci8_connection *connection;
+ oci8_descriptor *descr;
+ ub4 loblen;
+ int fp;
+ ub4 offset = 1;
+ char *filename;
+ char buf[8192];
+
+ OCI8_TLS_VARS;
+
+#if PHP_API_VERSION < 19990421
+ if (getThis(&id) == SUCCESS) {
+#else
+ if ((id = getThis()) != 0) {
+#endif
+ if (_php3_hash_find(id->value.ht, "connection", sizeof("connection"), (void **)&conn) == FAILURE) {
+ php3_error(E_WARNING, "unable to find my statement property");
+ RETURN_FALSE;
+ }
+
+ connection = oci8_get_conn(conn->value.lval, "OCIsavedescfile", list);
+ if (connection == NULL) {
+ RETURN_FALSE;
+ }
+
+ if (_php3_hash_find(id->value.ht, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
+ php3_error(E_WARNING, "unable to find my locator property");
+ RETURN_FALSE;
+ }
+
+ if (_php3_hash_index_find(connection->descriptors, tmp->value.lval, (void **)&descr) == FAILURE) {
+ php3_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;
+ }
+
+ filename = arg->value.str.val;
+
+ if ((fp = open(filename, O_RDONLY)) == -1) {
+ php3_error(E_WARNING, "Can't open file %s", filename);
+ RETURN_FALSE;
+ }
+ while((loblen = read(fp, &buf, 8192)) > 0){
+ connection->error =
+ OCILobWrite(connection->pServiceContext,
connection->pError,
mylob,
&loblen,
@@ -2642,48 +2722,17 @@
(ub2) 0,
(ub1) SQLCS_IMPLICIT
);
- if (connection->error) {
- oci8_error(connection->pError, "OCILobWrite", connection->error);
- close(fp);
- RETURN_FALSE;
- }
- offset += loblen;
- }
- close(fp);
- }else{
- loblen = arg->value.str.len;
-
- if (loblen < 1) {
- php3_error(E_WARNING, "Cannot save a lob wich size is less than 1 byte");
- RETURN_FALSE;
- }
-
-
- connection->error =
- OCILobWrite(connection->pServiceContext,
- connection->pError,
- mylob,
- &loblen,
- (ub4) 1,
- (dvoid *) arg->value.str.val,
- (ub4) loblen,
- OCI_ONE_PIECE,
- (dvoid *)0,
- (OCICallbackLobWrite) 0,
- (ub2) 0,
- (ub1) SQLCS_IMPLICIT );
-
- oci8_debug("OCIsavedesc: size=%d",loblen);
-
if (connection->error) {
oci8_error(connection->pError, "OCILobWrite", connection->error);
+ close(fp);
RETURN_FALSE;
}
+ offset += loblen;
}
- RETURN_TRUE;
+ close(fp);
+ RETURN_TRUE;
}
-
- RETURN_FALSE;
+ RETURN_FALSE;
}
/* }}} */
@@ -2800,6 +2849,7 @@
switch (descr.type) {
case OCI_DTYPE_LOB :
add_method(return_value, "save", php3_oci8_savedesc);
+ add_method(return_value, "savefile", php3_oci8_savedescfile);
/* breaktruh */
case OCI_DTYPE_FILE :
add_method(return_value, "load", php3_oci8_loaddesc);
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Stig Venaas: "[PHP-DEV] cvs: /php3/functions ldap.c php3_ldap.h"
- Previous message: animate2 <email protected>: "[PHP-DEV] Bug #1987: ImageTTFBBox does not return correct bounding box."
- Next in thread: Andreas Karajannis: "[PHP-DEV] cvs: /php3/functions oci8.c"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

