CVS update: php3/functions

From: Date: Thu, 06 May 1999 10:14:29 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-5382@lists.php.net to get a copy of this message
Date: Thursday May 6, 1999 @ 6:14 Author: thies Update of /repository/php3/functions In directory php:/tmp/cvs-serv22771/functions Modified Files: oci8.c php3_oci8.h Log Message: added REFCURSORS (i could use some help with the documentation;-) Index: php3/functions/oci8.c diff -u php3/functions/oci8.c:1.89 php3/functions/oci8.c:1.90 --- php3/functions/oci8.c:1.89 Wed May 5 02:35:20 1999 +++ php3/functions/oci8.c Thu May 6 06:14:29 1999 @@ -33,7 +33,7 @@ #define OCI8_USE_EMALLOC 0 /* set this to 1 if you want to use the php memory manager! */ -/* $Id: oci8.c,v 1.89 1999/05/05 06:35:20 thies Exp $ */ +/* $Id: oci8.c,v 1.90 1999/05/06 10:14:29 thies Exp $ */ /* TODO list: * @@ -178,7 +178,7 @@ static oci8_out_column *oci8_get_col(oci8_statement *, int, pval *, char *); static int oci8_make_pval(pval *,oci8_statement *,oci8_out_column *, char *,HashTable *, int mode); -static int oci8_parse(oci8_connection *, text *, ub4, HashTable *); +static int oci8_parse(oci8_connection *, char *, int, HashTable *); static int oci8_execute(oci8_statement *, char *,ub4 mode); static int oci8_fetch(oci8_statement *, ub4, char *); static ub4 oci8_loaddesc(oci8_connection *, oci8_descriptor *, char **); @@ -231,6 +231,7 @@ void php3_oci8_newdescriptor(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS); +void php3_oci8_newcursor(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_serverversion(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_statementtype(INTERNAL_FUNCTION_PARAMETERS); @@ -261,9 +262,11 @@ {"ocifetchinto", php3_oci8_fetchinto, a2_arg_force_ref}, {"ocifetchstatement",php3_oci8_fetchstatement,a2_arg_force_ref}, {"ocifreestatement", php3_oci8_freestatement, NULL}, + {"ocifreecursor", php3_oci8_freestatement, NULL}, {"ociinternaldebug", php3_oci8_internaldebug, NULL}, {"ocinumcols", php3_oci8_numcols, NULL}, {"ociparse", php3_oci8_parse, NULL}, + {"ocinewcursor", php3_oci8_newcursor, NULL}, {"ociresult", php3_oci8_result, NULL}, {"ociserverversion", php3_oci8_serverversion, NULL}, {"ocistatementtype", php3_oci8_statementtype, NULL}, @@ -401,6 +404,7 @@ REGISTER_LONG_CONSTANT("OCI_B_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_ROWID",SQLT_RDD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("OCI_B_CURSOR",SQLT_RSET, CONST_CS | CONST_PERSISTENT); /* for OCIFetchInto & OCIResult */ REGISTER_LONG_CONSTANT("OCI_ASSOC",OCI_ASSOC, CONST_CS | CONST_PERSISTENT); @@ -956,10 +960,10 @@ /* {{{ oci8_parse() */ static int -oci8_parse(oci8_connection *connection, text *query, ub4 len, HashTable *list) +oci8_parse(oci8_connection *connection, char *query, int len, HashTable *list) { oci8_statement *statement; - sword error; + sword error = 0; OCI8_TLS_VARS; statement = ecalloc(1,sizeof(oci8_statement)); @@ -973,12 +977,15 @@ OCI_HTYPE_ERROR, 0, NULL); - error = oci8_error(statement->pError, "OCIParse", - OCIStmtPrepare(statement->pStmt, connection->pError, - query, len, - OCI_NTV_SYNTAX, OCI_DEFAULT)); - if (error) { - return 0; + + if (len > 0) { + error = oci8_error(statement->pError, "OCIParse", + OCIStmtPrepare(statement->pStmt, connection->pError, + query, len, + OCI_NTV_SYNTAX, OCI_DEFAULT)); + if (error) { + return 0; + } } #if 0 /* testing */ @@ -989,7 +996,9 @@ } #endif - statement->last_query = estrdup(query); + if (query) { + statement->last_query = estrdup(query); + } statement->conn = connection; statement->id = php3_list_insert(statement, OCI8_GLOBAL(php3_oci8_module).le_stmt); @@ -1041,29 +1050,31 @@ iters = 1; } - error = oci8_error( - statement->pError, - "OCIStmtExecute", - OCIStmtExecute( - statement->conn->pServiceContext, - statement->pStmt, - statement->pError, - iters, - 0, - NULL, - NULL, - mode)); - - switch (error) { - case 0: - break; - - case 3113: /* ORA-03113: end-of-file on communication channel */ - statement->conn->open = 0; - statement->conn->session->open = 0; - statement->conn->session->server->open = 0; - return 0; - break; + if (statement->last_query) { /* if we execute refcursors we don't have a query and we don't want to execute!!! */ + error = oci8_error( + statement->pError, + "OCIStmtExecute", + OCIStmtExecute( + statement->conn->pServiceContext, + statement->pStmt, + statement->pError, + iters, + 0, + NULL, + NULL, + mode)); + + switch (error) { + case 0: + break; + + case 3113: /* ORA-03113: end-of-file on communication channel */ + statement->conn->open = 0; + statement->conn->session->open = 0; + statement->conn->session->server->open = 0; + return 0; + break; + } } if (stmttype == OCI_STMT_SELECT && (statement->executed == 0)) { @@ -1187,9 +1198,6 @@ switch (outcol->type) { case SQLT_RSET: /* ref. cursor XXX NYI */ - define_type = -1; - break; - case SQLT_RDD: /* ROWID */ case SQLT_BLOB: /* binary LOB */ case SQLT_CLOB: /* character LOB */ @@ -1483,40 +1491,46 @@ if (outcol->is_descr) { - if (define && (! outcol->pdescr)) { /* column has been user-defined */ - if (_php3_hash_find(define->pval->value.ht, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { - php3_error(E_WARNING, "unable to find my descriptor property"); - return OCI_ERROR; - } else if (_php3_hash_index_find(outcol->statement->conn->descriptors, tmp->value.lval, (void **)&pdescr) == FAILURE) { - php3_error(E_WARNING, "unable to find my descriptor"); - return OCI_ERROR; - } - outcol->pdescr = pdescr; - } else if (! outcol->pdescr) { /* we got no define value and teh descriptor hasn't been allocated yet */ - if (outcol->type == SQLT_BFILE) { - descr.type = OCI_DTYPE_FILE; - } else if (outcol->type == SQLT_RDD ) { - descr.type = OCI_DTYPE_ROWID; - } else { - descr.type = OCI_DTYPE_LOB; - } - - OCIDescriptorAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv,(dvoid *)&(descr.ocidescr), descr.type, (size_t) 0, (dvoid **) 0); - - _php3_hash_index_update(outcol->statement->conn->descriptors, - outcol->statement->conn->descriptors_count,&descr,sizeof(oci8_descriptor),(void **)&pdescr); - - outcol->data = (void *) outcol->statement->conn->descriptors_count++; - outcol->pdescr = pdescr; - - oci8_debug("OCIExecute: new descriptor for %d -> %x",outcol->data,descr.ocidescr); - } - + if (define && (! outcol->pdescr)) { /* column has been user-defined */ + if (_php3_hash_find(define->pval->value.ht, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { + php3_error(E_WARNING, "unable to find my descriptor property"); + return OCI_ERROR; + } else if (_php3_hash_index_find(outcol->statement->conn->descriptors, tmp->value.lval, (void **)&pdescr) == FAILURE) { + php3_error(E_WARNING, "unable to find my descriptor"); + return OCI_ERROR; + } + outcol->pdescr = pdescr; + } else if (! outcol->pdescr) { /* we got no define value and the descriptor hasn't been allocated yet */ + if (outcol->type == SQLT_BFILE) { + descr.type = OCI_DTYPE_FILE; + } else if (outcol->type == SQLT_RDD ) { + descr.type = OCI_DTYPE_ROWID; + } else { + descr.type = OCI_DTYPE_LOB; + } + + OCIDescriptorAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid *)&(descr.ocidescr), + descr.type, + (size_t) 0, + (dvoid **) 0); + + _php3_hash_index_update(outcol->statement->conn->descriptors, + outcol->statement->conn->descriptors_count, + &descr,sizeof(oci8_descriptor), + (void **)&pdescr); + + outcol->data = (void *) outcol->statement->conn->descriptors_count++; + outcol->pdescr = pdescr; + + oci8_debug("OCIExecute: new descriptor for %d -> %x",outcol->data,descr.ocidescr); + } + if (! outcol->pdescr) { php3_error(E_WARNING, "unable to find my descriptor"); return OCI_ERROR; } - + outcol->rlen = -1; *bufpp = outcol->pdescr->ocidescr; } else { /* "normal variable" */ @@ -1543,7 +1557,7 @@ } else if (! outcol->data) { outcol->data = (text *) emalloc(outcol->storage_size4); } - + if (! outcol->data) { php3_error(E_WARNING, "OCIFetch: cannot allocate %d bytes!",outcol->storage_size4); return OCI_ERROR; @@ -1593,13 +1607,17 @@ return OCI_ERROR; } - if (phpbind->descr == 0) { /* "normal string bind */ + if ((phpbind->descr == 0) && (phpbind->pStmt == 0)) { /* "normal string bind */ convert_to_string(val); *bufpp = val->value.str.val; *alenp = phpbind->maxsize; + *indpp = (dvoid *)&phpbind->indicator; + } else if (phpbind->pStmt != 0) { + *bufpp = phpbind->pStmt; + *alenp = -1; /* seems to be allright */ *indpp = (dvoid *)&phpbind->indicator; - } else { /* descriptor bind */ + } else { /* descriptor bind */ *bufpp = phpbind->descr; *alenp = -1; /* seems to be allright */ *indpp = (dvoid *)&phpbind->indicator; @@ -2311,11 +2329,13 @@ { pval *stmt, *name, *var, *maxlen, *tmp,*type; oci8_statement *statement; + oci8_statement *bindstmt; oci8_bind *bind, *tmp_bind; oci8_descriptor *descr; sword error; ub2 ocitype; sb4 ocimaxlen; + OCIStmt *mystmt; dvoid *mydescr = 0; ocitype = SQLT_STR; /* zero terminated string */ @@ -2357,12 +2377,24 @@ break; default: - convert_to_string(var); - if (ocimaxlen == -1) { - if (var->value.str.len == 0) { - php3_error(E_WARNING, "OCIBindByName bindlength is 0"); + if (ocitype == SQLT_RSET) { /* refcursor binding */ + convert_to_long(var); + + bindstmt = oci8_get_stmt(var->value.lval, "OCIBindByName", list); + if (! bindstmt) { + RETURN_FALSE; } - ocimaxlen = var->value.str.len + 1; /* SQLT_STR needs a trailing 0 - maybe we need to resize the var buffers????? */ + ocimaxlen = 0; + mystmt = bindstmt->pStmt; + } else { /* everything else is now handled as a string */ + convert_to_string(var); + if (ocimaxlen == -1) { + if (var->value.str.len == 0) { + php3_error(E_WARNING, "OCIBindByName bindlength is 0"); + } + ocimaxlen = var->value.str.len + 1; + /* SQLT_STR needs a trailing 0 - maybe we need to resize the var buffers????? */ + } } break; } @@ -2391,6 +2423,7 @@ bind->value = var; bind->descr = mydescr; + bind->pStmt = mystmt; bind->maxsize = ocimaxlen; error = OCIBindByName(statement->pStmt, /* statement handle */ @@ -3322,6 +3355,35 @@ RETURN_LONG(oci8_parse(connection, query->value.str.val, query->value.str.len, + list)); +} + +/* }}} */ +/* {{{ proto int OCINewCursor(int conn) + return a new cursor (Statement-Handle) - use this to bind ref-cursors! + + */ + +void php3_oci8_newcursor(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *conn; + oci8_connection *connection; + OCI8_TLS_VARS; + + if (getParameters(ht, 1, &conn) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(conn); + + connection = oci8_get_conn(conn->value.lval, "OCINewCursor", list); + if (connection == NULL) { + RETURN_FALSE; + } + + RETURN_LONG(oci8_parse(connection, + 0, + 0, list)); } Index: php3/functions/php3_oci8.h diff -u php3/functions/php3_oci8.h:1.44 php3/functions/php3_oci8.h:1.45 --- php3/functions/php3_oci8.h:1.44 Wed May 5 02:35:20 1999 +++ php3/functions/php3_oci8.h Thu May 6 06:14:29 1999 @@ -83,12 +83,6 @@ } oci8_connection; typedef struct { - int id; - oci8_session *session; - OCITrans *pTrans; -} oci8_xa; - -typedef struct { dvoid *ocidescr; ub4 type; } oci8_descriptor; @@ -106,7 +100,7 @@ oci8_connection *conn; OCIError *pError; OCIStmt *pStmt; - text *last_query; + char *last_query; HashTable *columns; int ncolumns; HashTable *binds; @@ -118,6 +112,7 @@ OCIBind *pBind; pval *value; dvoid *descr; /* used for binding of LOBS etc */ + OCIStmt *pStmt; /* used for binding REFCURSORs */ ub4 maxsize; sb2 indicator; ub2 retcode; -- 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 (#5382) next »