CVS update: php3/functions

From: Date: Wed, 10 Feb 1999 11:32:09 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4023@lists.php.net to get a copy of this message
Date: Wednesday February 10, 1999 @ 6:32 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv21131 Modified Files: oci8.c php3_oci8.h Log Message: ociresult now accepts a column name or a column index (starting with 1) we still can't deallocate descriptors Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.32 php3/functions/oci8.c:1.33 *** php3/functions/oci8.c:1.32 Tue Feb 9 08:36:20 1999 --- php3/functions/oci8.c Wed Feb 10 06:32:09 1999 *************** *** 32,38 **** +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.32 1999/02/09 13:36:20 thies Exp $ */ #include "php.h" #include "internal_functions.h" --- 32,38 ---- +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.33 1999/02/10 11:32:09 thies Exp $ */ #include "php.h" #include "internal_functions.h" *************** *** 160,165 **** --- 160,166 ---- void php3_oci8_internaldebug(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_freelob(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_savelob(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_commit(INTERNAL_FUNCTION_PARAMETERS); *************** *** 198,203 **** --- 199,205 ---- {"ocistatementtype", php3_oci8_statementtype, NULL}, {"ocilogoff", php3_oci8_logoff, NULL}, {"ocilogon", php3_oci8_logon, NULL}, + {"ocifreelob", php3_oci8_freelob, NULL}, {"ocisavelob", php3_oci8_savelob, NULL}, {"ociloadlob", php3_oci8_loadlob, NULL}, {"ocicommit", php3_oci8_commit, NULL}, *************** *** 261,268 **** --- 263,272 ---- OCI8_GLOBAL(php3_oci8_module).num_persistent = 0; + /* OCI8_GLOBAL(php3_oci8_module).le_descr = register_list_destructors(oci8_free_descr, NULL); + */ OCI8_GLOBAL(php3_oci8_module).le_conn = register_list_destructors(oci8_close_conn, NULL); *************** *** 384,390 **** oci8_debug("oci8_free_column:"); if (column->data) { ! if (column->is_descr) { OCIDescriptorFree(column->data, OCI_DTYPE_LOB); } else { efree(column->data); --- 388,395 ---- oci8_debug("oci8_free_column:"); if (column->data) { ! if (column->is_descr && column->data) { ! oci8_debug("oci8_free_column: freeing descriptor %x",column->data); OCIDescriptorFree(column->data, OCI_DTYPE_LOB); } else { efree(column->data); *************** *** 440,446 **** oci8_debug("oci8_free_descr: %x",descr); ! /* XXX OCIDescriptorFree(column->data, OCI_DTYPE_LOB); */ } /* }}} */ --- 445,451 ---- oci8_debug("oci8_free_descr: %x",descr); ! // OCIDescriptorFree(&descr, OCI_DTYPE_LOB); } /* }}} */ *************** *** 454,459 **** --- 459,469 ---- oci8_debug("oci8_close_conn:"); + if (connection->descriptors) { + _php3_hash_destroy(connection->descriptors); + efree(connection->descriptors); + } + connection->open = 0; oci8_error(connection->pError, "OCILogoff", OCILogoff(connection->pServiceContext, *************** *** 596,604 **** oci8_make_pval(pval *val,int stmt_ind,oci8_out_column *column, char *func,HashTable *list) { size_t size; - int locator; - oci8_statement *statement; pval *value; if (val) { value = val; --- 606,613 ---- oci8_make_pval(pval *val,int stmt_ind,oci8_out_column *column, char *func,HashTable *list) { size_t size; pval *value; + oci8_statement *statement; if (val) { value = val; *************** *** 609,623 **** memset(value,0,sizeof(pval)); if (column->is_descr) { ! statement = oci8_get_stmt(stmt_ind, "oci8_make_pval", list); ! object_init(value); - locator = php3_list_insert(column->data, OCI8_GLOBAL(php3_oci8_module).le_descr); - add_property_long(value, "descriptor", locator); add_property_long(value, "connection", statement->conn->id); add_method(value, "save", php3_oci8_savelob); add_method(value, "load", php3_oci8_loadlob); - oci8_debug("oci8_make_pval: new descriptor for %x",column->data); } else { switch (column->indicator) { case -1: /* NULL value, return an empty string */ --- 618,629 ---- memset(value,0,sizeof(pval)); if (column->is_descr) { ! statement = oci8_get_stmt(stmt_ind, "oci8_make_pval", list); 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 -1: /* NULL value, return an empty string */ *************** *** 640,648 **** value->value.str.val = emalloc(size); memcpy(value->value.str.val, column->data, size); } ! /* ! column->value = value; ! */ return value; } --- 646,652 ---- value->value.str.val = emalloc(size); memcpy(value->value.str.val, column->data, size); } ! return value; } *************** *** 713,727 **** return 0; } - statement->columns = emalloc(sizeof(HashTable)); - if (!statement->columns || - _php3_hash_init(statement->columns, 13, NULL, - (void (*)(void *))oci8_free_column, 0) == FAILURE) { - /* out of memory */ - return 0; - } - if (stmttype == OCI_STMT_SELECT) { OCIHandleAlloc(statement->conn->pEnv, (dvoid **)&param, OCI_DTYPE_PARAM, 0, NULL); counter = 1; --- 717,731 ---- return 0; } if (stmttype == OCI_STMT_SELECT) { + + statement->columns = emalloc(sizeof(HashTable)); + if (!statement->columns || + _php3_hash_init(statement->columns, 13, NULL,(void (*)(void *))oci8_free_column, 0) == FAILURE) { + /* out of memory */ + return 0; + } + OCIHandleAlloc(statement->conn->pEnv, (dvoid **)&param, OCI_DTYPE_PARAM, 0, NULL); counter = 1; *************** *** 864,870 **** return 1; } oci8_error(statement->pError, func, error); ! return 1; } /* }}} */ --- 868,874 ---- return 1; } oci8_error(statement->pError, func, error); ! return 0; } /* }}} */ *************** *** 1016,1022 **** ub2 ocitype; sb4 ocimaxlen; dvoid *mydescr = 0; - int descr_type; ocitype = SQLT_STR; --- 1020,1025 ---- *************** *** 1040,1052 **** RETURN_FALSE; } mydescr = (dvoid *) php3_list_find(tmp->value.lval, &descr_type); if (!mydescr || descr_type != OCI8_GLOBAL(php3_oci8_module).le_descr) { php3_error(E_WARNING, "unable to find identifier (%d)", tmp->value.lval); RETURN_FALSE; } - break; default: --- 1043,1061 ---- RETURN_FALSE; } + /* mydescr = (dvoid *) php3_list_find(tmp->value.lval, &descr_type); if (!mydescr || descr_type != OCI8_GLOBAL(php3_oci8_module).le_descr) { php3_error(E_WARNING, "unable to find identifier (%d)", tmp->value.lval); RETURN_FALSE; + } + */ + mydescr = (dvoid *) tmp->value.lval; + + if (! mydescr) { + RETURN_FALSE; } break; default: *************** *** 1121,1134 **** } /* }}} */ /* {{{ proto string ocisavelob(object lob) */ void php3_oci8_savelob(INTERNAL_FUNCTION_PARAMETERS) { pval *id, *tmp, *conn, *arg; - int id_to_find; - int lob_type; OCILobLocator *mylob; oci8_connection *connection; sword ociresult; --- 1130,1164 ---- } /* }}} */ + /* {{{ proto string ocifreelob(object lob) + */ + + void php3_oci8_freelob(INTERNAL_FUNCTION_PARAMETERS) + { + pval *id, *tmp; + + OCI8_TLS_VARS; + + if (getThis(&id) == SUCCESS) { + 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; + } + + php3_list_delete(tmp->value.lval); + + RETURN_TRUE; + } + + RETURN_FALSE; + } + /* {{{ proto string ocisavelob(object lob) */ void php3_oci8_savelob(INTERNAL_FUNCTION_PARAMETERS) { pval *id, *tmp, *conn, *arg; OCILobLocator *mylob; oci8_connection *connection; sword ociresult; *************** *** 1152,1164 **** --- 1182,1202 ---- RETURN_FALSE; } + /* id_to_find = tmp->value.lval; + mylob = (OCILobLocator *) php3_list_find(id_to_find, &lob_type); if (!mylob || lob_type != OCI8_GLOBAL(php3_oci8_module).le_descr) { php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find); RETURN_FALSE; } + */ + mylob = (OCILobLocator *) tmp->value.lval; + + if (! mylob) { + RETURN_FALSE; + } if (getParameters(ht, 1, &arg) == FAILURE) { WRONG_PARAM_COUNT; *************** *** 1204,1211 **** void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS) { pval *id, *tmp, *conn; - int id_to_find; - int lob_type; OCILobLocator *mylob; oci8_connection *connection; sword ociresult; --- 1242,1247 ---- *************** *** 1230,1235 **** --- 1266,1272 ---- RETURN_FALSE; } + /* id_to_find = tmp->value.lval; mylob = (OCILobLocator *) php3_list_find(id_to_find, &lob_type); *************** *** 1237,1242 **** --- 1274,1285 ---- php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find); RETURN_FALSE; } + */ + mylob = (OCILobLocator *) tmp->value.lval; + + if (! mylob) { + RETURN_FALSE; + } ociresult = OCILobGetLength(connection->pServiceContext, connection->pError, mylob, &loblen); *************** *** 1287,1293 **** sword ociresult; oci8_connection *connection; OCILobLocator *mylob; - int locator; ub4 type = OCI_DTYPE_LOB; OCI8_TLS_VARS; --- 1330,1335 ---- *************** *** 1307,1317 **** oci8_error(connection->pError,"OCIDescriptorAlloc %d",ociresult),type; RETURN_FALSE; } object_init(return_value); ! locator = php3_list_insert(mylob, OCI8_GLOBAL(php3_oci8_module).le_descr); ! add_property_long(return_value, "descriptor", locator); add_property_long(return_value, "connection", conn->value.lval); add_method(return_value, "save", php3_oci8_savelob); add_method(return_value, "load", php3_oci8_loadlob); oci8_debug("OCINewDescriptor: new descriptor for %x",mylob); --- 1349,1361 ---- oci8_error(connection->pError,"OCIDescriptorAlloc %d",ociresult),type; RETURN_FALSE; } + + // _php3_hash_next_index_insert(connection->descriptors, &mylob, sizeof(void *),(void **) &mylob); object_init(return_value); ! add_property_long(return_value, "descriptor", (long) mylob); add_property_long(return_value, "connection", conn->value.lval); + add_method(return_value, "free", php3_oci8_freelob); add_method(return_value, "save", php3_oci8_savelob); add_method(return_value, "load", php3_oci8_loadlob); oci8_debug("OCINewDescriptor: new descriptor for %x",mylob); *************** *** 1835,1840 **** --- 1879,1892 ---- /* non persistent, simply add to list */ connection->id = php3_list_insert(connection, OCI8_GLOBAL(php3_oci8_module).le_conn); + connection->descriptors = emalloc(sizeof(HashTable)); + if (!connection->descriptors || + _php3_hash_init(connection->descriptors, 13, NULL, + (void (*)(void *))oci8_free_descr, 0) == FAILURE) { + /* out of memory */ + RETURN_FALSE; + } + RETVAL_LONG(connection->id); OCI8_GLOBAL(php3_oci8_module).num_links++; *************** *** 1898,1927 **** void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS) { ! pval *stmt, *col, *ret; oci8_statement *statement; ! oci8_out_column *outcol; OCI8_TLS_VARS; if (getParameters(ht, 2, &stmt, &col) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(stmt); ! convert_to_long(col); statement = oci8_get_stmt(stmt->value.lval, "OCIResult", list); if (statement == NULL) { RETURN_FALSE; } ! outcol = oci8_get_col(statement, col->value.lval, "OCIResult"); if (outcol == NULL) { ! RETURN_FALSE; } ! ret = oci8_make_pval(0,stmt->value.lval,outcol, "OCIResult",list); ! if (ret == NULL) { ! RETVAL_FALSE; ! } else { ! memcpy(return_value, ret, sizeof(pval)); } } /* }}} */ --- 1950,1995 ---- void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS) { ! pval *stmt, *col; oci8_statement *statement; ! oci8_out_column *outcol = NULL; ! int i; OCI8_TLS_VARS; if (getParameters(ht, 2, &stmt, &col) == FAILURE) { WRONG_PARAM_COUNT; } + convert_to_long(stmt); ! statement = oci8_get_stmt(stmt->value.lval, "OCIResult", list); + if (statement == NULL) { RETURN_FALSE; } ! ! if (col->type == IS_STRING) { ! for (i = 0; i < statement->ncolumns; i++) { ! outcol = oci8_get_col(statement, i + 1, "OCIResult"); ! if (outcol == NULL || outcol->indicator == -1) { ! continue; ! } else if ((outcol->name_len == col->value.str.len) ! && (! strncmp(outcol->name,col->value.str.val,col->value.str.len))) { ! break; /* got you! */ ! } ! } ! } ! if (outcol == NULL) { ! convert_to_long(col); ! outcol = oci8_get_col(statement,col->value.lval, "OCIResult"); } ! ! if (outcol == NULL) { ! RETURN_FALSE; } + + oci8_make_pval(return_value,stmt->value.lval,outcol, "OCIResult",list); } /* }}} */ Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.19 php3/functions/php3_oci8.h:1.20 *** php3/functions/php3_oci8.h:1.19 Tue Feb 9 08:36:20 1999 --- php3/functions/php3_oci8.h Wed Feb 10 06:32:09 1999 *************** *** 66,73 **** OCISession *pSession; /* HashTable *statements; - HashTable *descriptors; */ int open; } oci8_connection; --- 66,73 ---- OCISession *pSession; /* HashTable *statements; */ + HashTable *descriptors; int open; } oci8_connection; *************** *** 115,121 **** long num_persistent; long num_links; int le_conn; - int le_descr; int le_stmt; } oci8_module; --- 115,120 ---- *************** *** 128,133 **** --- 127,133 ---- /* 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) # define OCI8_STMT_TYPE(x) ((x)==OCI8_GLOBAL(php3_oci8_module).le_stmt) + # define OCI8_DESCR_TYPE(x) ((x)==OCI8_GLOBAL(php3_oci8_module).le_descr) # define RETURN_OUT_OF_MEMORY \ php3_error(E_WARNING, "Out of memory");\ -- 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 (#4023) next »