CVS update: php3/functions

From: Date: Tue, 16 Feb 1999 14:55:22 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4123@lists.php.net to get a copy of this message
Date: Tuesday February 16, 1999 @ 9:55 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv7777/functions Modified Files: oci8.c php3_oci8.h Log Message: small fixes- initial "non working" version of ocidefinebyname Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.50 php3/functions/oci8.c:1.51 *** php3/functions/oci8.c:1.50 Tue Feb 16 08:15:19 1999 --- php3/functions/oci8.c Tue Feb 16 09:55:21 1999 *************** *** 32,38 **** +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.50 1999/02/16 13:15:19 thies Exp $ */ #include "php.h" #include "internal_functions.h" --- 32,38 ---- +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.51 1999/02/16 14:55:21 thies Exp $ */ #include "php.h" #include "internal_functions.h" *************** *** 158,163 **** --- 158,164 ---- /* {{{ extension function prototypes */ void php3_oci8_bindbyname(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_definebyname(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_columnisnull(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_columnname(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_columnsize(INTERNAL_FUNCTION_PARAMETERS); *************** *** 195,200 **** --- 196,202 ---- static unsigned char third_arg_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; function_entry oci8_functions[] = { + {"ocidefinebyname", php3_oci8_definebyname, third_arg_force_ref}, {"ocibindbyname", php3_oci8_bindbyname, third_arg_force_ref}, {"ocicolumnisnull", php3_oci8_columnisnull, NULL}, {"ocicolumnname", php3_oci8_columnname, NULL}, *************** *** 398,403 **** --- 400,420 ---- #endif /* }}} */ + /* {{{ oci8_free_define() */ + + static int + oci8_free_define(oci8_define *define) + { + oci8_debug("oci8_free_define:"); + + if (define->name) { + efree(define->name); + define->name = 0; + } + return 0; + } + + /* }}} */ /* {{{ oci8_free_column() */ static int *************** *** 449,454 **** --- 466,476 ---- efree(statement->binds); } + if (statement->defines) { + _php3_hash_destroy(statement->defines); + efree(statement->defines); + } + efree(statement); } *************** *** 791,796 **** --- 813,819 ---- OCIParam *param; oci8_descriptor descr; oci8_descriptor *pdescr; + oci8_define *define; int counter; sword error, def_error; ub2 define_type; *************** *** 928,934 **** outcol->storage_size++; /* add one for string terminator */ } ! outcol->data = (text *)emalloc(outcol->storage_size); if (outcol->data == NULL) { efree(outcol); --- 951,967 ---- outcol->storage_size++; /* add one for string terminator */ } ! if (_php3_hash_find(statement->defines,outcol->name,outcol->name_len,(void **) &define) == SUCCESS) { ! convert_to_string(define->pval); ! if (define->pval->value.str.val) { ! /* XXX Free here */ ! } ! define->pval->value.str.val = emalloc(outcol->storage_size); ! define->pval->value.str.len = outcol->storage_size; ! outcol->data = define->pval->value.str.val; ! } else { ! outcol->data = (text *)emalloc(outcol->storage_size); ! } if (outcol->data == NULL) { efree(outcol); *************** *** 977,984 **** oci8_fetch(oci8_statement *statement, ub4 nrows, char *func) { sword error; - text errbuf[512]; - ub4 errcode = 0; OCI8_TLS_VARS; error = OCIStmtFetch(statement->pStmt, statement->pError, nrows, --- 1010,1015 ---- *************** *** 1204,1209 **** --- 1235,1303 ---- /************************* EXTENSION FUNCTIONS *************************/ + /* {{{ proto int OCIDefineByName(int stmt, string name, mixed &var [,int type]) + Define a PHP variable to an Oracle column by name. + if you want to define a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE defining!!! + */ + + void php3_oci8_definebyname(INTERNAL_FUNCTION_PARAMETERS) + { + pval *stmt, *name, *var, *type; + oci8_statement *statement; + oci8_define *define, *tmp_define; + ub2 ocitype; + + ocitype = SQLT_STR; /* zero terminated string */ + + if (getParameters(ht, 4, &stmt, &name, &var, &type) == SUCCESS) { + convert_to_long(type); + ocitype = type->value.lval; + } else if (getParameters(ht, 3, &stmt, &name, &var) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(stmt); + statement = oci8_get_stmt(stmt->value.lval, "OCIBindByName", list); + if (statement == NULL) { + RETURN_FALSE; + } + + convert_to_string(name); + + define = ecalloc(1,sizeof(oci8_define)); + if (!define) { + /* out of memory */ + RETURN_FALSE; + } + if (statement->defines == NULL) { + statement->defines = emalloc(sizeof(HashTable)); + if (statement->defines == NULL || + _php3_hash_init(statement->defines, 13, NULL, (void (*)(void *))oci8_free_define, 0) == FAILURE) { + /* out of memory */ + RETURN_FALSE; + } + } + if (_php3_hash_add(statement->defines, + name->value.str.val, + name->value.str.len, + define, + sizeof(oci8_define), + (void **)&tmp_define) == SUCCESS) { + efree(define); + define = tmp_define; + } else { + RETURN_FALSE; + } + + define->name = estrndup(name->value.str.val,name->value.str.len); + define->name_len = name->value.str.len; + define->type = ocitype; + define->pval = var; + + RETVAL_TRUE; + } + + /* }}} */ /* {{{ proto int OCIBindByName(int stmt, string name, mixed &var, int maxlength [,int type]) Bind a PHP variable to an Oracle placeholder by name. if you want to bind a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE binding!!! *************** *** 1233,1238 **** --- 1327,1333 ---- WRONG_PARAM_COUNT; } + convert_to_long(stmt); statement = oci8_get_stmt(stmt->value.lval, "OCIBindByName", list); if (statement == NULL) { RETURN_FALSE; *************** *** 1265,1271 **** break; } - convert_to_long(stmt); convert_to_string(name); bind = ecalloc(1,sizeof(oci8_bind)); --- 1360,1365 ---- *************** *** 1446,1455 **** void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS) { pval *id, *tmp, *conn; - OCILobLocator *mylob; oci8_connection *connection; oci8_descriptor *descr; - sword ociresult; char *buffer; ub4 loblen; --- 1540,1547 ---- Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.26 php3/functions/php3_oci8.h:1.27 *** php3/functions/php3_oci8.h:1.26 Tue Feb 16 06:57:52 1999 --- php3/functions/php3_oci8.h Tue Feb 16 09:55:22 1999 *************** *** 75,80 **** --- 75,88 ---- } oci8_descriptor; typedef struct { + pval *pval; + text *name; + ub4 name_len; + ub4 type; + } oci8_define; + + + typedef struct { int id; oci8_connection *conn; OCIError *pError; *************** *** 83,88 **** --- 91,97 ---- HashTable *columns; int ncolumns; HashTable *binds; + HashTable *defines; int executed; } oci8_statement; -- 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 (#4123) next »