CVS update: php3/functions

From: Date: Fri, 11 Sep 1998 14:14:40 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-975@lists.php.net to get a copy of this message
Date: Friday September 11, 1998 @ 10:14 Author: ssb Update of /repository/php3/functions In directory asf:/u2/tmp/cvs-serv10384 Modified Files: oci8.c php3_oci8.h Log Message: Implemented OCIBindByName() in the Oracle 8 module. This bind function uses variable references and lets you do bind, exec, change variable, exec, change variable, exec... Currently only input binding is supported. LONG data is currently limited to two megabytes. Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.10 php3/functions/oci8.c:1.11 *** php3/functions/oci8.c:1.10 Thu Sep 10 14:29:15 1998 --- php3/functions/oci8.c Fri Sep 11 10:14:39 1998 *************** *** 27,33 **** +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.10 1998/09/10 18:29:15 ssb Exp $ */ #include "php.h" #include "internal_functions.h" --- 27,33 ---- +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.11 1998/09/11 14:14:39 ssb Exp $ */ #include "php.h" #include "internal_functions.h" *************** *** 47,57 **** /* TODO list: * * - Error mode (print or shut up?) - * - Dynamic Binding * - LOB writing, reading and manipulation * - ability to refer to columns by name as well as number * - OCIPasswordChange() - * - OCIServerVersion() * - Prefetching control * */ --- 47,56 ---- /* TODO list: * * - Error mode (print or shut up?) * - LOB writing, reading and manipulation + * - returning refcursors as statement handles * - ability to refer to columns by name as well as number * - OCIPasswordChange() * - Prefetching control * */ *************** *** 138,143 **** --- 137,146 ---- static int oci8_execute(oci8_statement *, char *); 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 **); + static sb4 oci8_bind_out_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 **, ub1 *, dvoid **, ub2 **); + /* }}} */ /* {{{ extension function prototypes */ *************** *** 155,164 **** --- 158,172 ---- void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_fetchinto(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_serverversion(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_bindbyname(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_test(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_test2(INTERNAL_FUNCTION_PARAMETERS); /* }}} */ /* {{{ extension definition structures */ + static unsigned char refs_aaf[] = {3, BYREF_ALLOW, BYREF_ALLOW, BYREF_FORCE}; + function_entry oci8_functions[] = { {"ocilogon", php3_oci8_logon, NULL}, /* {"ociplogon", php3_oci8_plogon, NULL},*/ *************** *** 175,180 **** --- 183,191 ---- {"ociresult", php3_oci8_result, NULL}, {"ocifetchinto", php3_oci8_fetchinto, second_arg_force_ref}, {"ociserverversion", php3_oci8_serverversion, NULL}, + {"ocibindbyname", php3_oci8_bindbyname, refs_aaf}, + {"ocitest", php3_oci8_test, first_arg_force_ref}, + {"ocitest2", php3_oci8_test2, NULL}, {NULL, NULL, NULL} }; *************** *** 607,620 **** * handled specially. */ switch (outcol->type) { ! case SQLT_BIN: ! case SQLT_LBI: ! case SQLT_BLOB: ! case SQLT_CLOB: ! case SQLT_BFILE: define_type = outcol->type; break; default: define_type = SQLT_STR; outcol->storage_size++; /* add one for string terminator */ break; --- 618,634 ---- * handled specially. */ switch (outcol->type) { ! case SQLT_BIN: /* RAW */ ! case SQLT_LBI: /* LONG RAW */ ! case SQLT_BLOB: /* binary LOB */ ! case SQLT_CLOB: /* character LOB */ ! case SQLT_BFILE: /* binary file LOB */ ! case SQLT_RSET: /* ref. cursor */ ! outcol->is_opaque = 1; define_type = outcol->type; break; default: + outcol->is_opaque = 0; define_type = SQLT_STR; outcol->storage_size++; /* add one for string terminator */ break; *************** *** 671,676 **** --- 685,747 ---- } + static sb4 + oci8_bind_in_callback(dvoid *ictxp, /* context pointer */ + OCIBind *bindp, /* bind handle */ + ub4 iter, /* 0-based execute iteration value */ + ub4 index, /* index of current array for PL/SQL or + row index for SQL */ + dvoid **bufpp, /* pointer to data */ + ub4 *alenp, /* size after value/piece has been read */ + ub1 *piecep, /* which piece */ + dvoid **indpp) /* indicator value */ + { + oci8_bind *phpbind; + pval *val; + + oci8_debug("oci8_bind_in_callback: ictxp=%08x", ictxp); + phpbind = (oci8_bind *)ictxp; + oci8_debug("oci8_bind_in_callback: phpbind=%08x", phpbind); + if (phpbind) { + oci8_debug("oci8_bind_in_callback: phpbind->val=%08x", phpbind->val); + } + if (!phpbind || !(val = phpbind->val)) { + php3_error(E_WARNING, "!phpbind || !phpbind->val"); + return OCI_ERROR; + } + if (val->type == IS_STRING && val->value.str.val == undefined_variable_string) { + /* NULL value */ + phpbind->indicator = -1; + phpbind->size = 0; + phpbind->buf = NULL; + } else { + if (phpbind->is_opaque) { + /* XXX get list entry and return pointer to data */ + /* give NULL value for now */ + phpbind->indicator = -1; + phpbind->size = 0; + phpbind->buf = NULL; + } else { + convert_to_string(val); + phpbind->indicator = 0; + phpbind->size = val->value.str.len + 1; + phpbind->buf = val->value.str.val; + } + } + + (void)iter; /* ignoring iter */ + (void)index; /* ignoring index */ + *bufpp = phpbind->buf; + *alenp = phpbind->size; + *indpp = (dvoid *)&phpbind->indicator; + + *piecep = OCI_ONE_PIECE; /* pass all data in one go */ + + return OCI_CONTINUE; + } + + /* static sb4 oci8_bind_out_callback */ + /* }}} */ /************************* EXTENSION FUNCTIONS *************************/ *************** *** 1106,1112 **** } /* }}} */ ! /* {{{ int OCIFetchInto(int stmt, array &array) */ void php3_oci8_fetchinto(INTERNAL_FUNCTION_PARAMETERS) { --- 1177,1183 ---- } /* }}} */ ! /* {{{ int OCIFetchInto(int stmt, array &output) */ void php3_oci8_fetchinto(INTERNAL_FUNCTION_PARAMETERS) { *************** *** 1147,1152 **** --- 1218,1315 ---- sizeof(pval), NULL); } RETVAL_LONG(statement->ncolumns); + } + + /* }}} */ + /* {{{ int OCITest() */ + + void php3_oci8_test(INTERNAL_FUNCTION_PARAMETERS) + { + pval *var; + OCI8_TLS_VARS; + + if (getParameters(ht, 1, &var) == FAILURE) { + WRONG_PARAM_COUNT; + } + RETURN_LONG((long)var); + } + + /* }}} */ + /* {{{ string OCITest2(int ptr) */ + + void php3_oci8_test2(INTERNAL_FUNCTION_PARAMETERS) + { + pval *var; + char buf[200]; + OCI8_TLS_VARS; + + if (getParameters(ht, 1, &var) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(var); + var = (pval *)var->value.lval; + snprintf(buf, sizeof(buf), "var=%08x var->value=%08x str=%s", + var, var->value, var->value.str.val); + buf[sizeof(buf)-1] = '\0'; + RETVAL_STRING(buf,1); + } + + /* }}} */ + /* {{{ int OCIBindByName(int stmt, string name, mixed &var) */ + + void php3_oci8_bindbyname(INTERNAL_FUNCTION_PARAMETERS) + { + pval *stmt, *name, *var; + oci8_statement *statement; + oci8_bind *bind; + sword error; + + if (getParameters(ht, 3, &stmt, &name, &var) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(stmt); + convert_to_string(name); + convert_to_string(var); + statement = oci8_get_stmt(stmt->value.lval, "OCIBindByName", list); + if (statement == NULL) { + RETURN_FALSE; + } + bind = OCI8_CALLOC(1,sizeof(oci8_bind)); + if (!bind) { + RETURN_FALSE; /* out of memory */ + } + bind->val = var; + error = OCIBindByName(statement->pStmt, /* statement handle */ + (OCIBind **)&bind->pBind, /* bind hdl (will alloc) */ + statement->pError, /* error handle */ + name->value.str.val, /* placeholder name */ + name->value.str.len, /* placeholder length */ + (dvoid *)0, /* in/out data */ + (sb4)OCI8_MAX_DATA_SIZE, /* max size ever used */ + (ub2)SQLT_STR, /* in/out data type */ + (dvoid *)0, /* indicator (ignored) */ + (ub2 *)0, /* size array (ignored) */ + (ub2 *)0, /* return code (ignored) */ + (ub4)0, /* maxarr_len (PL/SQL only?) */ + (ub4 *)0, /* actual array size (PL/SQL only?) */ + OCI_DATA_AT_EXEC /* mode */); + if (error != OCI_SUCCESS) { + oci8_error(statement->pError, "OCIBindByName", error); + RETURN_FALSE; + } + error = OCIBindDynamic(bind->pBind, + statement->pError, + (dvoid *)bind, + oci8_bind_in_callback, + #if 0 + (dvoid *)bind, + oci8_bind_out_callback + #else + (dvoid *)NULL, + (OCICallbackOutBind)NULL + #endif + ); + RETVAL_TRUE; } /* }}} */ Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.7 php3/functions/php3_oci8.h:1.8 *** php3/functions/php3_oci8.h:1.7 Thu Sep 10 13:58:01 1998 --- php3/functions/php3_oci8.h Fri Sep 11 10:14:39 1998 *************** *** 73,78 **** --- 73,87 ---- } oci8_statement; typedef struct { + OCIBind *pBind; + pval *val; + ub4 size; + dvoid *buf; + sb2 indicator; + ub2 is_opaque; + } oci8_bind; + + typedef struct { OCIDefine *pDefine; text *name; ub4 name_len; *************** *** 82,87 **** --- 91,97 ---- text *data; sb2 indicator; ub2 retcode; + ub2 is_opaque; } oci8_out_column; typedef struct { *************** *** 119,124 **** --- 129,135 ---- # endif # define OCI8_MAX_NAME_LEN 64 + # define OCI8_MAX_DATA_SIZE 2097152 /* two megs */ /* this one has to be changed to include persistent connections as well */ # define OCI8_CONN_TYPE(x) ((x)==OCI8_GLOBAL(php3_oci8_module).le_conn) -- 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 (#975) next »