CVS update: php3/functions

From: Date: Mon, 15 Feb 1999 10:39:32 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4098@lists.php.net to get a copy of this message
Date: Monday February 15, 1999 @ 5:39 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv25058 Modified Files: oci8.c php3_oci8.h Log Message: removed OCIFlags again (flags are now supplied to each individual function eg. OCIFechInto..) added OCI_RETURN_LOBS flags (for OCIFetchInto) - returns the whole LOB/BFILE inline. (no extra load needed) Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.43 php3/functions/oci8.c:1.44 *** php3/functions/oci8.c:1.43 Fri Feb 12 10:48:43 1999 --- php3/functions/oci8.c Mon Feb 15 05:39:32 1999 *************** *** 32,38 **** +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.43 1999/02/12 15:48:43 thies Exp $ */ #include "php.h" #include "internal_functions.h" --- 32,38 ---- +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.44 1999/02/15 10:39:32 thies Exp $ */ #include "php.h" #include "internal_functions.h" *************** *** 57,65 **** * - Prefetching control * - support LONG > 64K * - binding of arrays ! * - Truncate input values to the bind size???? * - Character sets for NCLOBS * - piecewise operation for longs, lobs etc */ /* {{{ thread safety stuff */ --- 57,68 ---- * - Prefetching control * - support LONG > 64K * - binding of arrays ! * - Truncate input values to the bind size * - Character sets for NCLOBS * - piecewise operation for longs, lobs etc + * - split the module into an upper (php-callable) and lower (c-callable) layer! + * - make_pval needs some cleanup.... + * - improve the NULL handling for LOBS/BFILES */ /* {{{ thread safety stuff */ *************** *** 139,148 **** static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); static oci8_statement *oci8_get_stmt(int, const char *, HashTable *); static oci8_out_column *oci8_get_col(oci8_statement *, int, pval *, char *); ! static pval *oci8_make_pval(pval *,int,oci8_out_column *, char *,HashTable *); static int oci8_parse(oci8_connection *, text *, ub4, HashTable *); static int oci8_execute(oci8_statement *, char *,ub4 mode); static int oci8_fetch(oci8_statement *, ub4, char *); /* bind callback functions */ static sb4 oci8_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **); --- 142,152 ---- static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); static oci8_statement *oci8_get_stmt(int, const char *, HashTable *); static oci8_out_column *oci8_get_col(oci8_statement *, int, pval *, char *); ! static pval *oci8_make_pval(pval *,int,oci8_out_column *, char *,HashTable *, int mode); static int oci8_parse(oci8_connection *, text *, ub4, HashTable *); static int oci8_execute(oci8_statement *, char *,ub4 mode); static int oci8_fetch(oci8_statement *, ub4, char *); + static ub4 oci8_loadlob(oci8_connection *, oci8_descriptor *, char **); /* bind callback functions */ static sb4 oci8_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **); *************** *** 173,179 **** void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS); - void php3_oci8_flags(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_serverversion(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_statementtype(INTERNAL_FUNCTION_PARAMETERS); --- 177,182 ---- *************** *** 184,192 **** #define OCI_ASSOC 1<<0 #define OCI_NUM 1<<1 - #define OCI_RETURN_NULLS 1<<2 #define OCI_BOTH (OCI_ASSOC|OCI_NUM) function_entry oci8_functions[] = { {"ocibindbyname", php3_oci8_bindbyname, refs_aaf}, {"ocicolumnisnull", php3_oci8_columnisnull, NULL}, --- 187,197 ---- #define OCI_ASSOC 1<<0 #define OCI_NUM 1<<1 #define OCI_BOTH (OCI_ASSOC|OCI_NUM) + #define OCI_RETURN_NULLS 1<<2 + #define OCI_RETURN_LOBS 1<<3 + function_entry oci8_functions[] = { {"ocibindbyname", php3_oci8_bindbyname, refs_aaf}, {"ocicolumnisnull", php3_oci8_columnisnull, NULL}, *************** *** 199,205 **** {"ocifreestatement", php3_oci8_freestatement, NULL}, {"ociinternaldebug", php3_oci8_internaldebug, NULL}, {"ocinumcols", php3_oci8_numcols, NULL}, - {"ociflags", php3_oci8_flags, NULL}, {"ociparse", php3_oci8_parse, NULL}, {"ociresult", php3_oci8_result, NULL}, {"ociserverversion", php3_oci8_serverversion, NULL}, --- 204,209 ---- *************** *** 294,304 **** REGISTER_LONG_CONSTANT("SQLT_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT); ! /* for OCIFetchInto & OCIFlags */ REGISTER_LONG_CONSTANT("OCI_ASSOC",OCI_ASSOC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_NUM",OCI_NUM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_BOTH",OCI_BOTH, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_RETURN_NULLS",OCI_RETURN_NULLS, CONST_CS | CONST_PERSISTENT); /* for OCINewDescriptor */ REGISTER_LONG_CONSTANT("OCI_DTYPE_FILE",OCI_DTYPE_FILE, CONST_CS | CONST_PERSISTENT); --- 298,309 ---- REGISTER_LONG_CONSTANT("SQLT_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT); ! /* for OCIFetchInto & OCIResult */ REGISTER_LONG_CONSTANT("OCI_ASSOC",OCI_ASSOC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_NUM",OCI_NUM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_BOTH",OCI_BOTH, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_RETURN_NULLS",OCI_RETURN_NULLS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("OCI_RETURN_LOBS",OCI_RETURN_LOBS, CONST_CS | CONST_PERSISTENT); /* for OCINewDescriptor */ REGISTER_LONG_CONSTANT("OCI_DTYPE_FILE",OCI_DTYPE_FILE, CONST_CS | CONST_PERSISTENT); *************** *** 646,657 **** /* {{{ oci8_make_pval() */ static pval * ! oci8_make_pval(pval *val,int stmt_ind,oci8_out_column *column, char *func,HashTable *list) { size_t size; - pval *value; - int flags; oci8_statement *statement; if (val) { value = val; --- 651,664 ---- /* {{{ oci8_make_pval() */ static pval * ! oci8_make_pval(pval *val,int stmt_ind,oci8_out_column *column, char *func,HashTable *list, int mode) { size_t size; oci8_statement *statement; + oci8_descriptor *descr; + pval *value; + ub4 loblen; + char *buffer; if (val) { value = val; *************** *** 663,677 **** statement = oci8_get_stmt(stmt_ind, "oci8_make_pval", list); - flags = statement->conn->flags; - if (column->is_descr) { ! object_init(value); ! add_property_long(value, "connection", statement->conn->id); ! add_property_long(value, "descriptor", (long) column->data); ! add_method(value, "save", php3_oci8_savelob); ! add_method(value, "load", php3_oci8_loadlob); } else { switch (column->indicator) { case -2: /* truncated value */ --- 670,708 ---- statement = oci8_get_stmt(stmt_ind, "oci8_make_pval", list); if (column->is_descr) { ! if (mode & OCI_RETURN_LOBS) { /* OCI_RETURN_LOBS means that we want the content of the LOB back instead of the locator */ ! if (column->indicator == -1) { /* we hit a NULL value, return empty string or uninitialized value */ ! if (mode & OCI_RETURN_NULLS) { /* OCI_RETURN_NULLS means that we ALWAYS want to get "at least" an empty string */ ! value->type = IS_STRING; ! value->value.str.len = 0; ! value->value.str.val = empty_string; ! } else { ! var_reset(value); ! } ! return value; ! } ! if (_php3_hash_index_find(statement->conn->descriptors,(int) column->data, (void **)&descr) == FAILURE) { ! php3_error(E_WARNING, "unable to find my descriptor %d",column->data); ! return 0; ! } ! ! loblen = oci8_loadlob(statement->conn,descr,&buffer); ! ! if (loblen > 0) { ! value->type = IS_STRING; ! value->value.str.len = loblen; ! value->value.str.val = buffer; ! } ! } else { /* return the locator */ ! object_init(value); ! ! add_property_long(value, "connection", statement->conn->id); ! add_property_long(value, "descriptor", (long) column->data); ! add_method(value, "save", php3_oci8_savelob); ! add_method(value, "load", php3_oci8_loadlob); ! } } else { switch (column->indicator) { case -2: /* truncated value */ *************** *** 686,692 **** case -1: /* we hit a NULL value, return empty string or uninitialized value */ default: /* XXX we SHOULD maybe have a different behaviour for unknown results! */ ! if (flags & OCI_RETURN_NULLS) { /* OCI_RETURN_NULLS means that we ALWAYS want to get "at least" an empty string */ value->type = IS_STRING; value->value.str.len = 0; value->value.str.val = empty_string; --- 717,723 ---- case -1: /* we hit a NULL value, return empty string or uninitialized value */ default: /* XXX we SHOULD maybe have a different behaviour for unknown results! */ ! if (mode & OCI_RETURN_NULLS) { /* OCI_RETURN_NULLS means that we ALWAYS want to get "at least" an empty string */ value->type = IS_STRING; value->value.str.len = 0; value->value.str.val = empty_string; *************** *** 836,843 **** case SQLT_CLOB: /* character LOB */ case SQLT_BFILE: /* binary file LOB */ outcol->is_descr = 1; ! descr.type = OCI_DTYPE_LOB; ! OCIDescriptorAlloc(statement->conn->pEnv,(dvoid *)&(descr.lob), OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); _php3_hash_index_update(statement->conn->descriptors, statement->conn->descriptors_count,&descr,sizeof(oci8_descriptor),(void **)&pdescr); --- 867,880 ---- case SQLT_CLOB: /* character LOB */ case SQLT_BFILE: /* binary file LOB */ outcol->is_descr = 1; ! ! if (outcol->type == SQLT_BFILE) { ! descr.type = OCI_DTYPE_FILE; ! } else { ! descr.type = OCI_DTYPE_LOB; ! } ! ! OCIDescriptorAlloc(statement->conn->pEnv,(dvoid *)&(descr.lob), descr.type, (size_t) 0, (dvoid **) 0); _php3_hash_index_update(statement->conn->descriptors, statement->conn->descriptors_count,&descr,sizeof(oci8_descriptor),(void **)&pdescr); *************** *** 943,948 **** --- 980,1055 ---- } /* }}} */ + /* {{{ oci8_loadlob() */ + static ub4 + oci8_loadlob(oci8_connection *connection, oci8_descriptor *mydescr, char **buffer) + { + sword ociresult; + ub4 loblen; + + OCI8_TLS_VARS; + + ociresult = OCILobGetLength(connection->pServiceContext, connection->pError, mydescr->lob, &loblen); + + if (ociresult) { + oci8_error(connection->pError, "OCILobGetLength", ociresult); + return -1; + } + + *buffer = emalloc(loblen + 1); + + if (! buffer) { + return -2; + } + + if (mydescr->type == OCI_DTYPE_FILE) { + ociresult = OCILobFileOpen(connection->pServiceContext, + connection->pError, + mydescr->lob, + OCI_FILE_READONLY); + if (ociresult) { + oci8_error(connection->pError, "OCILobRead: OCILobFileOpen", ociresult); + efree(buffer); + return -3; + } + } + + ociresult = OCILobRead(connection->pServiceContext, + connection->pError, + mydescr->lob, + &loblen, /* IN/OUT bytes toread/read */ + 1, /* offset (starts with 1) */ + (dvoid *) *buffer, + loblen, /* size of buffer */ + (dvoid *)0, + (OCICallbackLobRead) 0, /* callback... */ + (ub2) 0, /* The character set ID of the buffer data. */ + (ub1) SQLCS_IMPLICIT); /* The character set form of the buffer data. */ + + if (ociresult) { + oci8_error(connection->pError, "OCILobRead", ociresult); + efree(buffer); + return -4; + } + + if (mydescr->type == OCI_DTYPE_FILE) { + ociresult = OCILobFileClose(connection->pServiceContext, + connection->pError, + mydescr->lob); + if (ociresult) { + oci8_error(connection->pError, "OCILobRead: OCILobFileClose", ociresult); + efree(buffer); + return -5; + } + } + + (*buffer)[ loblen ] = 0; + + oci8_debug("OCILoadLob: size=%d",loblen); + + return loblen; + } + /* }}} */ /* {{{ oci8_bind_in_callback() */ static sb4 *************** *** 1351,1422 **** RETURN_FALSE; } ! mylob = (OCILobLocator *) descr->lob; ! ! if (! mylob) { ! RETURN_FALSE; ! } ! ! oci8_debug("OCILoadLob: found lob %x of type %d",descr->lob,descr->type); ! ! ociresult = OCILobGetLength(connection->pServiceContext, connection->pError, mylob, &loblen); ! ! if (ociresult) { ! oci8_error(connection->pError, "OCILobGetLength", ociresult); ! RETURN_FALSE; ! } ! ! buffer = emalloc(loblen + 1); ! if (! buffer) { ! RETURN_FALSE; ! } ! if (descr->type == OCI_DTYPE_FILE) { ! ociresult = OCILobFileOpen(connection->pServiceContext, ! connection->pError, ! mylob, ! OCI_FILE_READONLY); ! if (ociresult) { ! oci8_error(connection->pError, "OCILobRead: OCILobFileOpen", ociresult); ! efree(buffer); ! RETURN_FALSE; ! } ! } ! ! ociresult = OCILobRead(connection->pServiceContext, ! connection->pError, ! mylob, ! &loblen, /* IN/OUT bytes toread/read */ ! 1, /* offset (starts with 1) */ ! (dvoid *) buffer, ! loblen, /* size of buffer */ ! (dvoid *)0, ! (OCICallbackLobRead) 0, /* callback... */ ! (ub2) 0, /* The character set ID of the buffer data. */ ! (ub1) SQLCS_IMPLICIT); /* The character set form of the buffer data. */ ! ! if (descr->type == OCI_DTYPE_FILE) { ! ociresult = OCILobFileClose(connection->pServiceContext, ! connection->pError, ! mylob); ! if (ociresult) { ! oci8_error(connection->pError, "OCILobRead: OCILobFileClose", ociresult); ! efree(buffer); ! RETURN_FALSE; ! } ! } ! ! if (ociresult) { ! oci8_error(connection->pError, "OCILobRead", ociresult); ! efree(buffer); ! RETURN_FALSE; } - - buffer[ loblen ] = 0; - - oci8_debug("OCILoadLob: size=%d",loblen); - - RETURN_STRINGL(buffer,loblen,0); } RETURN_FALSE; --- 1458,1468 ---- RETURN_FALSE; } ! loblen = oci8_loadlob(connection,descr,&buffer); ! if (loblen > 0) { ! RETURN_STRINGL(buffer,loblen,0); } } RETURN_FALSE; *************** *** 1810,1821 **** } if ((column->indicator == -1) ! && ((statement->conn->flags & OCI_RETURN_NULLS) == 0)) { continue; } ! if (mode & OCI_NUM) { ! oci8_make_pval(&element,stmt->value.lval,column, "OCIFetchInto",list); _php3_hash_index_update(array->value.ht, i, (void *)&element, sizeof(pval), NULL); } --- 1856,1867 ---- } if ((column->indicator == -1) ! && ((mode & OCI_RETURN_NULLS) == 0)) { continue; } ! if ((mode & OCI_NUM) || (! (mode & OCI_ASSOC))) { /* OCI_NUM is default */ ! oci8_make_pval(&element,stmt->value.lval,column, "OCIFetchInto",list,mode); _php3_hash_index_update(array->value.ht, i, (void *)&element, sizeof(pval), NULL); } *************** *** 1823,1829 **** memcpy(namebuf,column->name, column->name_len); namebuf[ column->name_len ] = 0; ! oci8_make_pval(&element,stmt->value.lval,column, "OCIFetchInto",list); _php3_hash_update(array->value.ht, namebuf, column->name_len+1, (void *)&element, sizeof(pval), NULL); } } --- 1869,1875 ---- memcpy(namebuf,column->name, column->name_len); namebuf[ column->name_len ] = 0; ! oci8_make_pval(&element,stmt->value.lval,column, "OCIFetchInto",list,mode); _php3_hash_update(array->value.ht, namebuf, column->name_len+1, (void *)&element, sizeof(pval), NULL); } } *************** *** 2108,2152 **** } /* }}} */ - /* {{{ proto string OCIFlags(int connection [, int flags]) - Sets operation-mode returning the old one - */ - - void php3_oci8_flags(INTERNAL_FUNCTION_PARAMETERS) - { - pval *conn, *flags; - oci8_connection *connection; - int oldflags; - int setflags; - int doset = 0; - OCI8_TLS_VARS; - - if (getParameters(ht, 2, &conn, &flags) == SUCCESS) { - convert_to_long(flags); - setflags = flags->value.lval; - doset = 1; - } else if (getParameters(ht, 2, &conn) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long(conn); - - connection = oci8_get_conn(conn->value.lval, "OCIFlags", list, plist); - - if (connection == NULL) { - RETURN_FALSE; - } - - oldflags = connection->flags; - - if (doset) { - connection->flags = setflags; - } - - RETURN_LONG(oldflags); - } - - /* }}} */ /* {{{ proto string OCIResult(int stmt, mixed column) Return a single column of result data. */ --- 2154,2159 ---- *************** *** 2176,2182 **** RETURN_FALSE; } ! oci8_make_pval(return_value,stmt->value.lval,outcol, "OCIResult",list); } /* }}} */ --- 2183,2189 ---- RETURN_FALSE; } ! oci8_make_pval(return_value,stmt->value.lval,outcol, "OCIResult",list,0); } /* }}} */ Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.23 php3/functions/php3_oci8.h:1.24 *** php3/functions/php3_oci8.h:1.23 Fri Feb 12 07:21:08 1999 --- php3/functions/php3_oci8.h Mon Feb 15 05:39:32 1999 *************** *** 67,73 **** HashTable *descriptors; int descriptors_count; int open; - int flags; } oci8_connection; typedef struct { --- 67,72 ---- -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#4098) next »