CVS update: php3/functions

From: Date: Mon, 08 Feb 1999 13:35:52 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-3976@lists.php.net to get a copy of this message
Date: Monday February 8, 1999 @ 8:35 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv19369 Modified Files: oci8.c php3_oci8.h Log Message: inserting of lobs works now!!!! STILL work in progress Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.25 php3/functions/oci8.c:1.26 *** php3/functions/oci8.c:1.25 Mon Feb 8 06:30:22 1999 --- php3/functions/oci8.c Mon Feb 8 08:35:51 1999 *************** *** 31,37 **** +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.25 1999/02/08 11:30:22 thies Exp $ */ #include "php.h" #include "internal_functions.h" --- 31,37 ---- +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.26 1999/02/08 13:35:51 thies Exp $ */ #include "php.h" #include "internal_functions.h" *************** *** 51,57 **** /* 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() --- 51,56 ---- *************** *** 128,137 **** void php3_info_oci8(void); static ub4 oci8_error(OCIError *err_p, char *what, sword status); ! static int oci8_ping(oci8_connection *conn); static void oci8_debug(const char *format,...); static void oci8_close_conn(oci8_connection *connection); ! static void oci8_free_lobs(oci8_connection *connection); static void oci8_free_stmt(oci8_statement *statement); static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); --- 127,136 ---- void php3_info_oci8(void); static ub4 oci8_error(OCIError *err_p, char *what, sword status); ! /* static int oci8_ping(oci8_connection *conn); XXX NYI */ static void oci8_debug(const char *format,...); static void oci8_close_conn(oci8_connection *connection); ! static void oci8_free_descr(oci8_connection *connection); static void oci8_free_stmt(oci8_statement *statement); static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); *************** *** 165,171 **** void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_commit(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_rollback(INTERNAL_FUNCTION_PARAMETERS); ! void php3_oci8_newlob(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS); --- 164,170 ---- void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_commit(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_rollback(INTERNAL_FUNCTION_PARAMETERS); ! void php3_oci8_newdescriptor(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS); *************** *** 199,205 **** {"ociloadlob", php3_oci8_loadlob, NULL}, {"ocicommit", php3_oci8_commit, NULL}, {"ocirollback", php3_oci8_rollback, NULL}, ! {"ocinewlob", php3_oci8_newlob, NULL}, {NULL, NULL, NULL} }; --- 198,204 ---- {"ociloadlob", php3_oci8_loadlob, NULL}, {"ocicommit", php3_oci8_commit, NULL}, {"ocirollback", php3_oci8_rollback, NULL}, ! {"ocinewdescriptor", php3_oci8_newdescriptor, NULL}, {NULL, NULL, NULL} }; *************** *** 258,265 **** OCI8_GLOBAL(php3_oci8_module).num_persistent = 0; ! OCI8_GLOBAL(php3_oci8_module).le_lob = ! register_list_destructors(oci8_free_lobs, NULL); OCI8_GLOBAL(php3_oci8_module).le_conn = register_list_destructors(oci8_close_conn, NULL); --- 257,264 ---- 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); *************** *** 279,288 **** REGISTER_LONG_CONSTANT("OCI_COMMIT_ON_SUCCESS",OCI_COMMIT_ON_SUCCESS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_EXACT_FETCH",OCI_EXACT_FETCH, CONST_CS | CONST_PERSISTENT); ! /* types for OCIBindByName */ ! REGISTER_LONG_CONSTANT("SQLT_STR",SQLT_STR, CONST_CS | CONST_PERSISTENT); ! REGISTER_LONG_CONSTANT("SQLT_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT); ! REGISTER_LONG_CONSTANT("SQLT_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT); return SUCCESS; } --- 278,285 ---- REGISTER_LONG_CONSTANT("OCI_COMMIT_ON_SUCCESS",OCI_COMMIT_ON_SUCCESS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_EXACT_FETCH",OCI_EXACT_FETCH, CONST_CS | CONST_PERSISTENT); ! REGISTER_LONG_CONSTANT("OCI_DTYPE_LOB",OCI_DTYPE_LOB, CONST_CS | CONST_PERSISTENT); ! REGISTER_LONG_CONSTANT("OCI_DTYPE_FILE",OCI_DTYPE_FILE, CONST_CS | CONST_PERSISTENT); return SUCCESS; } *************** *** 395,401 **** oci8_free_column(oci8_out_column *column) { if (column->data) { ! if (column->is_lob) { /* XXX free lob here */ } else { efree(column->data); --- 392,398 ---- oci8_free_column(oci8_out_column *column) { if (column->data) { ! if (column->is_descr) { /* XXX free lob here */ } else { efree(column->data); *************** *** 449,458 **** } /* }}} */ ! /* {{{ oci8_free_lobs() */ static void ! oci8_free_lobs(oci8_connection *connection) { OCI8_TLS_VARS; /* XXX needs implementation */ --- 446,455 ---- } /* }}} */ ! /* {{{ oci8_free_descr() */ static void ! oci8_free_descr(oci8_connection *connection) { OCI8_TLS_VARS; /* XXX needs implementation */ *************** *** 516,521 **** --- 513,519 ---- return errcode; } + #if 0 /* XXX NYI */ /* }}} */ /* {{{ oci8_ping() */ *************** *** 527,532 **** --- 525,532 ---- } /* }}} */ + #endif + /* {{{ oci8_debug() */ static void oci8_debug(const char *format,...) *************** *** 610,621 **** oci8_statement *statement; pval *value = ecalloc(1,sizeof(pval)); ! if (column->is_lob) { 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_lob); ! add_property_long(value, "locator", locator); add_property_long(value, "connection", statement->conn->id); add_method(value, "save", php3_oci8_savelob); add_method(value, "load", php3_oci8_loadlob); --- 610,621 ---- oci8_statement *statement; pval *value = ecalloc(1,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); *************** *** 790,796 **** case SQLT_BLOB: /* binary LOB */ case SQLT_CLOB: /* character LOB */ case SQLT_BFILE: /* binary file LOB */ ! outcol->is_lob = 1; OCIDescriptorAlloc(statement->conn->pEnv,&(outcol->data), OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); define_type = outcol->type; def_error = OCIDefineByPos(statement->pStmt, --- 790,796 ---- case SQLT_BLOB: /* binary LOB */ case SQLT_CLOB: /* character LOB */ case SQLT_BFILE: /* binary file LOB */ ! outcol->is_descr = 1; OCIDescriptorAlloc(statement->conn->pEnv,&(outcol->data), OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); define_type = outcol->type; def_error = OCIDefineByPos(statement->pStmt, *************** *** 928,940 **** } #endif ! convert_to_string(val); /* XXX FIXME that's not always our datatype */ ! oci8_debug("oci8_bind_in_callback: buffer=\"%s\" maxlen=%d",val->value.str.val,phpbind->maxsize); ! *bufpp = val->value.str.val; ! *alenp = phpbind->maxsize; ! *indpp = (dvoid *)&phpbind->indicator; *piecep = OCI_ONE_PIECE; /* pass all data in one go */ --- 928,948 ---- } #endif ! if (phpbind->descr == 0) { /* "normal string bind */ ! convert_to_string(val); ! oci8_debug("oci8_bind_in_callback: buffer=\"%s\" maxlen=%d",val->value.str.val,phpbind->maxsize); ! *bufpp = val->value.str.val; ! *alenp = phpbind->maxsize; ! *indpp = (dvoid *)&phpbind->indicator; ! } else { /* descriptor bind */ ! oci8_debug("oci8_bind_in_callback: descriptor"); ! ! *bufpp = phpbind->descr; ! *alenp = -1; /* seems to be allright */ ! *indpp = (dvoid *)&phpbind->indicator; ! } *piecep = OCI_ONE_PIECE; /* pass all data in one go */ *************** *** 981,987 **** */ if (val->type == IS_OBJECT) { ! return OCI_ERROR; } else if (val->type == IS_STRING) { if (val->value.str.val && (val->value.str.val!=undefined_variable_string) && (val->value.str.val!=empty_string)) { efree(val->value.str.val); /* free the "old" value */ --- 989,995 ---- */ if (val->type == IS_OBJECT) { ! } else if (val->type == IS_STRING) { if (val->value.str.val && (val->value.str.val!=undefined_variable_string) && (val->value.str.val!=empty_string)) { efree(val->value.str.val); /* free the "old" value */ *************** *** 1007,1046 **** /************************* EXTENSION FUNCTIONS *************************/ ! /* {{{ proto int OCIBindByName(int stmt, string name, mixed &var, int maxlength [, int type]) Bind a PHP variable to an Oracle placeholder by name. */ void php3_oci8_bindbyname(INTERNAL_FUNCTION_PARAMETERS) { ! pval *stmt, *name, *var, *maxlen, *type; oci8_statement *statement; oci8_bind *bind, *tmp_bind; sword error; ub2 ocitype; sb4 ocimaxlen; ocitype = SQLT_STR; ! if (getParameters(ht, 5, &stmt, &name, &var, &maxlen, &type) == SUCCESS) { ! convert_to_long(maxlen); ! convert_to_long(type); ! ocimaxlen = maxlen->value.lval; ! ocitype = type->value.lval; ! } else if (getParameters(ht, 4, &stmt, &name, &var, &maxlen) == SUCCESS) { convert_to_long(maxlen); ocimaxlen = maxlen->value.lval; } else { WRONG_PARAM_COUNT; } ! switch (ocitype) { ! case SQLT_BLOB : ! case SQLT_CLOB : ! if (var->type != IS_OBJECT) { ! php3_error(E_WARNING, "OCIBindByName LOBs must be initializes using OCINewLob!"); RETURN_FALSE; } break; default: --- 1015,1070 ---- /************************* EXTENSION FUNCTIONS *************************/ ! /* {{{ proto int OCIBindByName(int stmt, string name, mixed &var, int maxlength) 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!!! */ void php3_oci8_bindbyname(INTERNAL_FUNCTION_PARAMETERS) { ! pval *stmt, *name, *var, *maxlen, *tmp; oci8_statement *statement; oci8_bind *bind, *tmp_bind; sword error; ub2 ocitype; sb4 ocimaxlen; + dvoid *mydescr = 0; + int descr_type; ocitype = SQLT_STR; ! if (getParameters(ht, 4, &stmt, &name, &var, &maxlen) == SUCCESS) { convert_to_long(maxlen); ocimaxlen = maxlen->value.lval; } else { WRONG_PARAM_COUNT; } ! switch (var->type) { ! case IS_OBJECT : ! /* find out what the hell the type of the object is and bind it!!! */ ! if (_php3_hash_find(var->value.ht, "type", sizeof("type"), (void **)&tmp) == FAILURE) { ! php3_error(E_WARNING, "unable to find my locator property"); RETURN_FALSE; } + + switch (tmp->value.lval) { /* XXX i think we have to supply the type as a parameter!!!! */ + case OCI_DTYPE_LOB : + ocitype = SQLT_CLOB; + break; + } + + if (_php3_hash_find(var->value.ht, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { + php3_error(E_WARNING, "unable to find my locator property"); + 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: *************** *** 1050,1056 **** } break; } ! ocimaxlen++; convert_to_long(stmt); convert_to_string(name); --- 1074,1081 ---- } break; } ! ! ocimaxlen++; /* SQLT_STR needs a trailing 0 - maybe we need to resize the var buffers????? */ convert_to_long(stmt); convert_to_string(name); *************** *** 1079,1084 **** --- 1104,1110 ---- } bind->value = var; + bind->descr = mydescr; bind->maxsize = ocimaxlen; error = OCIBindByName(statement->pStmt, /* statement handle */ *************** *** 1105,1110 **** --- 1131,1141 ---- /* cbf_no_data*/ oci8_bind_in_callback, (dvoid *)bind, oci8_bind_out_callback); + if (error != OCI_SUCCESS) { + oci8_error(statement->pError, "OCIBindDynamic", error); + RETURN_FALSE; + } + RETVAL_TRUE; } *************** *** 1135,1141 **** RETURN_FALSE; } ! if (_php3_hash_find(id->value.ht, "locator", sizeof("locator"), (void **)&tmp) == FAILURE) { php3_error(E_WARNING, "unable to find my locator property"); RETURN_FALSE; } --- 1166,1172 ---- RETURN_FALSE; } ! 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; } *************** *** 1143,1149 **** 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_lob) { php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find); RETURN_FALSE; } --- 1174,1180 ---- 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; } *************** *** 1206,1212 **** RETURN_FALSE; } ! if (_php3_hash_find(id->value.ht, "locator", sizeof("locator"), (void **)&tmp) == FAILURE) { php3_error(E_WARNING, "unable to find my locator property"); RETURN_FALSE; } --- 1237,1243 ---- RETURN_FALSE; } ! 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; } *************** *** 1214,1220 **** 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_lob) { php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find); RETURN_FALSE; } --- 1245,1251 ---- 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; } *************** *** 1256,1272 **** } /* }}} */ ! /* {{{ proto string OCINewLob(int connection) ! initialize a new empty lob */ ! void php3_oci8_newlob(INTERNAL_FUNCTION_PARAMETERS) { pval *conn; sword ociresult; oci8_connection *connection; OCILobLocator *mylob; int locator; OCI8_TLS_VARS; if (getParameters(ht, 1, &conn) == FAILURE) { --- 1287,1304 ---- } /* }}} */ ! /* {{{ proto string OCINewDescriptor(int connection [,int type ]) ! initialize a new empty descriptor (currently only LOB is supported). */ ! void php3_oci8_newdescriptor(INTERNAL_FUNCTION_PARAMETERS) { pval *conn; sword ociresult; oci8_connection *connection; OCILobLocator *mylob; int locator; + ub4 type = OCI_DTYPE_LOB; OCI8_TLS_VARS; if (getParameters(ht, 1, &conn) == FAILURE) { *************** *** 1274,1295 **** } convert_to_long(conn); ! connection = oci8_get_conn(conn->value.lval, "OCINewLob", list, plist); if (connection == NULL) { RETURN_FALSE; } ! ociresult = OCIDescriptorAlloc(connection->pEnv,(dvoid*)&(mylob), OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); if (ociresult) { ! oci8_error(connection->pError,"OCIDescriptorAlloc OCI_DTYPE_LOB",ociresult); RETURN_FALSE; } object_init(return_value); ! locator = php3_list_insert(mylob, OCI8_GLOBAL(php3_oci8_module).le_lob); ! add_property_long(return_value, "locator", 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); } --- 1306,1328 ---- } convert_to_long(conn); ! connection = oci8_get_conn(conn->value.lval, "OCINewDescriptor", list, plist); if (connection == NULL) { RETURN_FALSE; } ! ociresult = OCIDescriptorAlloc(connection->pEnv,(dvoid*)&(mylob), type, (size_t) 0, (dvoid **) 0); if (ociresult) { ! 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_property_long(return_value, "type", type); add_method(return_value, "save", php3_oci8_savelob); add_method(return_value, "load", php3_oci8_loadlob); } *************** *** 1528,1534 **** /* }}} */ ! /* {{{ proto int OCIExecute(int stmt) Execute a parsed statement. */ --- 1561,1567 ---- /* }}} */ ! /* {{{ proto int OCIExecute(int stmt [,int mode]) Execute a parsed statement. */ Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.16 php3/functions/php3_oci8.h:1.17 *** php3/functions/php3_oci8.h:1.16 Mon Feb 8 06:30:22 1999 --- php3/functions/php3_oci8.h Mon Feb 8 08:35:52 1999 *************** *** 81,86 **** --- 81,87 ---- typedef struct { OCIBind *pBind; pval *value; + dvoid *descr; /* used for binding of LOBS etc */ ub4 maxsize; sb2 indicator; ub2 rcode; *************** *** 96,102 **** void *data; sb2 indicator; ub2 retcode; ! ub2 is_lob; pval *value; } oci8_out_column; --- 97,103 ---- void *data; sb2 indicator; ub2 retcode; ! ub2 is_descr; pval *value; } oci8_out_column; *************** *** 111,117 **** long num_persistent; long num_links; int le_conn; ! int le_lob; /* int le_pconn;*/ int le_stmt; /* sb4 max_bind_data_size; */ --- 112,118 ---- long num_persistent; long num_links; int le_conn; ! int le_descr; /* int le_pconn;*/ int le_stmt; /* sb4 max_bind_data_size; */ -- 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 (#3976) next »