CVS update: php3/functions

From: Date: Thu, 18 Feb 1999 15:04:56 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4143@lists.php.net to get a copy of this message
Date: Thursday February 18, 1999 @ 10:04 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv29856/functions Modified Files: oci8.c Log Message: small fixes, starting to "clean-up" Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.53 php3/functions/oci8.c:1.54 *** php3/functions/oci8.c:1.53 Thu Feb 18 08:06:03 1999 --- php3/functions/oci8.c Thu Feb 18 10:04:56 1999 *************** *** 32,38 **** +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.53 1999/02/18 13:06:03 thies Exp $ */ #include "php.h" #include "internal_functions.h" --- 32,38 ---- +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.54 1999/02/18 15:04:56 thies Exp $ */ #include "php.h" #include "internal_functions.h" *************** *** 65,70 **** --- 65,72 ---- * - persistend connections * - NULLS (retcode/indicator) needs some more work for describing & binding * - remove all XXXs + * - defining is not yet complete + * - clean up and documentation */ /* {{{ thread safety stuff */ *************** *** 144,150 **** 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 *); --- 146,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 int 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 *); *************** *** 678,699 **** /* }}} */ /* {{{ 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; - } else { - value = emalloc(sizeof(pval)); - } - memset(value,0,sizeof(pval)); statement = oci8_get_stmt(stmt_ind, "oci8_make_pval", list); --- 680,694 ---- /* }}} */ /* {{{ oci8_make_pval() */ ! static int ! oci8_make_pval(pval *value,int stmt_ind,oci8_out_column *column, char *func,HashTable *list, int mode) { size_t size; oci8_statement *statement; oci8_descriptor *descr; ub4 loblen; char *buffer; memset(value,0,sizeof(pval)); statement = oci8_get_stmt(stmt_ind, "oci8_make_pval", list); *************** *** 702,720 **** if ((column->type != SQLT_RDD) && (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); --- 697,709 ---- if ((column->type != SQLT_RDD) && (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) { ! var_reset(value); ! return 0; } 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 -1; } loblen = oci8_loadlob(statement->conn,descr,&buffer); *************** *** 723,732 **** value->type = IS_STRING; value->value.str.len = loblen; value->value.str.val = buffer; - } else if (mode & OCI_RETURN_NULLS) { - value->type = IS_STRING; - value->value.str.len = 0; - value->value.str.val = empty_string; } else { var_reset(value); } --- 712,717 ---- *************** *** 747,767 **** size = column->size; break; - case 0: /* intact value */ size = strlen(column->data); /* everything is now a NULL terminated string */ break; 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; ! } else { ! var_reset(value); ! } ! return value; } value->type = IS_STRING; --- 732,745 ---- size = column->size; break; case 0: /* intact value */ size = strlen(column->data); /* everything is now a NULL terminated string */ break; 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! */ ! var_reset(value); ! return 0; } value->type = IS_STRING; *************** *** 770,776 **** memcpy(value->value.str.val, column->data, size); } ! return value; } /* }}} */ --- 748,754 ---- memcpy(value->value.str.val, column->data, size); } ! return 0; } /* }}} */ *************** *** 821,852 **** ub2 define_type; ub2 stmttype = 0; ub4 iters; OCI8_TLS_VARS; ! OCIAttrGet((dvoid *)statement->pStmt, OCI_HTYPE_STMT, ! (ub2 *)&stmttype, (ub4 *)0, OCI_ATTR_STMT_TYPE, ! statement->pError); if (stmttype == OCI_STMT_SELECT) { iters = 0; } else { iters = 1; } - /* oci8_debug("oci8_execute: stmttype=%d mode=%d", stmttype, mode); */ ! error = OCIStmtExecute(statement->conn->pServiceContext, ! statement->pStmt, statement->pError, ! iters, 0, NULL, NULL, mode); if (error) { - oci8_debug("oci8_execute error 1"); - oci8_error(statement->pError, func, error); return 0; } if (stmttype == OCI_STMT_SELECT && (statement->executed == 0)) { - /* we only need to do the define step is this very statement is executed the first time! */ - statement->executed++; statement->columns = emalloc(sizeof(HashTable)); --- 799,843 ---- ub2 define_type; ub2 stmttype = 0; ub4 iters; + ub4 colcount; OCI8_TLS_VARS; ! error = oci8_error(statement->pError, ! "OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_STMT_TYPE", ! OCIAttrGet((dvoid *)statement->pStmt, ! OCI_HTYPE_STMT, ! (ub2 *)&stmttype, ! (ub4 *)0, ! OCI_ATTR_STMT_TYPE, ! statement->pError)); + if (error) { + return 0; + } + if (stmttype == OCI_STMT_SELECT) { iters = 0; } else { iters = 1; } ! ! error = oci8_error(statement->pError, ! "OCIStmtExecute", ! OCIStmtExecute(statement->conn->pServiceContext, ! statement->pStmt, ! statement->pError, ! iters, ! 0, ! NULL, ! NULL, ! mode)); if (error) { return 0; } if (stmttype == OCI_STMT_SELECT && (statement->executed == 0)) { /* we only need to do the define step is this very statement is executed the first time! */ statement->executed++; statement->columns = emalloc(sizeof(HashTable)); *************** *** 856,906 **** return 0; } ! OCIHandleAlloc(statement->conn->pEnv, (dvoid **)&param, ! OCI_DTYPE_PARAM, 0, NULL); counter = 1; - error = OCIParamGet(statement->pStmt, OCI_HTYPE_STMT, - statement->pError, (dvoid *)&param, counter); - oci8_error(statement->pError, "oci8_execute2", error); ! while (error == OCI_SUCCESS) { memset(&column,0,sizeof(oci8_out_column)); if (_php3_hash_index_update(statement->columns, counter, &column, sizeof(oci8_out_column), (void**) &outcol) == FAILURE) { efree(statement->columns); /* out of memory */ return 0; } outcol->statement = statement; ! /* get data type */ ! /* XXX can get OCI_ATTR_TYPE_NAME instead */ ! oci8_error(statement->pError, "OCIAttrGet(param,type)", ! OCIAttrGet((dvoid *)param, OCI_DTYPE_PARAM, ! (dvoid *)&outcol->type, (ub4 *)0, ! OCI_ATTR_DATA_TYPE, statement->pError)); ! /* get data size */ ! oci8_error(statement->pError, "OCIAttrGet(param,size)", ! OCIAttrGet((dvoid *)param, OCI_DTYPE_PARAM, ! (dvoid *)&outcol->storage_size, (dvoid *)0, ! OCI_ATTR_DATA_SIZE, statement->pError)); ! /* get column name */ ! oci8_error(statement->pError, "OCIAttrGet(param,name)", ! OCIAttrGet((dvoid *)param, OCI_DTYPE_PARAM, (dvoid **)&outcol->name, /* XXX this string is NOT zero terminated!!!! */ (ub4 *)&outcol->name_len, ! (ub4)OCI_ATTR_NAME, statement->pError)); /* Remember the size Oracle told us, we have to increase the * storage size for some types. */ outcol->size = outcol->storage_size; - /* "Scalar" data types are stored directly in strings, - * while others, like LOBs and RAW data need to be - * handled specially. - */ switch (outcol->type) { case SQLT_RDD: /* ROWID */ case SQLT_BLOB: /* binary LOB */ case SQLT_CLOB: /* character LOB */ --- 847,930 ---- return 0; } ! OCIHandleAlloc(statement->conn->pEnv, ! (dvoid **)&param, ! OCI_DTYPE_PARAM, ! 0, ! NULL); counter = 1; ! error = oci8_error(statement->pError, ! "OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_PARAM_COUNT", ! OCIAttrGet((dvoid *)statement->pStmt, ! OCI_HTYPE_STMT, ! (dvoid *)&colcount, ! (ub4 *)0, ! OCI_ATTR_PARAM_COUNT, ! statement->pError)); ! if (error) { ! return 0; ! } ! ! statement->ncolumns = colcount; ! ! for (counter = 1; counter <= colcount; counter++) { memset(&column,0,sizeof(oci8_out_column)); + if (_php3_hash_index_update(statement->columns, counter, &column, sizeof(oci8_out_column), (void**) &outcol) == FAILURE) { efree(statement->columns); /* out of memory */ return 0; } + outcol->statement = statement; ! oci8_error(statement->pError, ! "OCIParamGet OCI_HTYPE_STMT", ! OCIParamGet((dvoid *)statement->pStmt, ! OCI_HTYPE_STMT, ! statement->pError, ! (dvoid*)&param, ! counter)); ! ! oci8_error(statement->pError, ! "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_TYPE", ! OCIAttrGet((dvoid *)param, ! OCI_DTYPE_PARAM, ! (dvoid *)&outcol->type, ! (ub4 *)0, ! OCI_ATTR_DATA_TYPE, ! statement->pError)); ! ! oci8_error(statement->pError, ! "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_SIZE", ! OCIAttrGet((dvoid *)param, ! OCI_DTYPE_PARAM, ! (dvoid *)&outcol->storage_size, ! (dvoid *)0, ! OCI_ATTR_DATA_SIZE, ! statement->pError)); ! ! oci8_error(statement->pError, ! "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_NAME", ! OCIAttrGet((dvoid *)param, ! OCI_DTYPE_PARAM, (dvoid **)&outcol->name, /* XXX this string is NOT zero terminated!!!! */ (ub4 *)&outcol->name_len, ! (ub4)OCI_ATTR_NAME, ! statement->pError)); /* Remember the size Oracle told us, we have to increase the * storage size for some types. */ outcol->size = outcol->storage_size; switch (outcol->type) { + case SQLT_RSET: /* ref. cursor XXX NYI */ + def_error = -1; + break; + case SQLT_RDD: /* ROWID */ case SQLT_BLOB: /* binary LOB */ case SQLT_CLOB: /* character LOB */ *************** *** 938,949 **** OCI_DEFAULT); break; - case SQLT_RSET: /* ref. cursor */ - /* XXX NYI */ - define_type = outcol->type; - def_error = -1; - break; - default: define_type = SQLT_STR; --- 962,967 ---- *************** *** 953,958 **** --- 971,977 ---- outcol->storage_size++; /* add one for string terminator */ } + /* check for user supplied define variables! */ if (statement->defines && (_php3_hash_find(statement->defines,outcol->name,outcol->name_len,(void **) &define) == SUCCESS)) { convert_to_string(define->pval); *************** *** 992,998 **** } if (def_error) { ! oci8_debug("oci8_execute error 2"); oci8_error(statement->pError, func, def_error); efree(outcol->data); efree(outcol); --- 1011,1017 ---- } if (def_error) { ! oci8_debug("OCIDefineByPos"); oci8_error(statement->pError, func, def_error); efree(outcol->data); efree(outcol); *************** *** 1000,1009 **** return 0; } - statement->ncolumns = counter; - counter++; - error = OCIParamGet(statement->pStmt, OCI_HTYPE_STMT, - statement->pError, (dvoid *)&param, counter); } } return 1; --- 1019,1024 ---- -- 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 (#4143) next »