CVS update: php3/functions
| From: | ssb | Date: | Thu, 10 Sep 1998 16:32:08 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-905@lists.php.net to get a copy of this message | ||
Date: Thursday September 10, 1998 @ 12:32
Author: ssb
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv25933
Modified Files:
oci8.c
Log Message:
Made internal utility functions for finding connections, statements and
columns. Also made the parsing, execution and fetching into utility
functions so they can be combined in more ways from PHP functions.
Index: php3/functions/oci8.c
diff -c php3/functions/oci8.c:1.7 php3/functions/oci8.c:1.8
*** php3/functions/oci8.c:1.7 Thu Sep 10 10:51:15 1998
--- php3/functions/oci8.c Thu Sep 10 12:32:06 1998
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.7 1998/09/10 14:51:15 ssb Exp $ */
#include "php.h"
#include "internal_functions.h"
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.8 1998/09/10 16:32:06 ssb Exp $ */
#include "php.h"
#include "internal_functions.h"
***************
*** 115,121 ****
# endif /* COMPILE_DL */
/* }}} */
! /* {{{ startup and shutdown function prototypes */
int php3_minit_oci8(INIT_FUNC_ARGS);
int php3_rinit_oci8(INIT_FUNC_ARGS);
--- 115,121 ----
# endif /* COMPILE_DL */
/* }}} */
! /* {{{ startup/shutdown/info/internal function prototypes */
int php3_minit_oci8(INIT_FUNC_ARGS);
int php3_rinit_oci8(INIT_FUNC_ARGS);
***************
*** 130,135 ****
--- 130,141 ----
static void oci8_free_stmt(oci8_statement *statement);
/*static void oci8_close_pconn(oci8_connection *connection);*/
+ 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, char *);
+ static int oci8_parse(oci8_connection *, text *, ub4, HashTable *);
+ static int oci8_execute(oci8_statement *, char *);
+ static int oci8_fetch(oci8_statement *, ub4, char *);
/* }}} */
/* {{{ extension function prototypes */
***************
*** 145,150 ****
--- 151,157 ----
void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_fetch(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS);
+ void php3_oci8_fetchinto(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_serverversion(INTERNAL_FUNCTION_PARAMETERS);
/* }}} */
***************
*** 163,168 ****
--- 170,176 ----
{"ocinumcols", php3_oci8_numcols, NULL},
{"ocifetch", php3_oci8_fetch, NULL},
{"ociresult", php3_oci8_result, NULL},
+ {"ocifetchinto", php3_oci8_fetchinto, second_arg_force_ref},
{"ociserverversion", php3_oci8_serverversion, NULL},
{NULL, NULL, NULL}
};
***************
*** 409,414 ****
--- 417,644 ----
}
#endif
+
+ static oci8_connection *
+ oci8_get_conn(int conn_ind, const char *func, HashTable *list, HashTable *plist)
+ {
+ int type;
+ oci8_connection *connection;
+ OCI8_TLS_VARS;
+
+ connection = (oci8_connection *)php3_list_find(conn_ind, &type);
+ if (!connection || !OCI8_CONN_TYPE(type)) {
+ php3_error(E_WARNING, "%s: invalid connection %d", func, conn_ind);
+ return (oci8_connection *)NULL;
+ }
+ return connection;
+ }
+
+
+ static oci8_statement *
+ oci8_get_stmt(int stmt_ind, const char *func, HashTable *list)
+ {
+ int type;
+ oci8_statement *statement;
+ OCI8_TLS_VARS;
+
+ statement = (oci8_statement *)php3_list_find(stmt_ind, &type);
+ if (!statement || !OCI8_STMT_TYPE(type)) {
+ php3_error(E_WARNING, "%s: invalid statement %d", func, stmt_ind);
+ return (oci8_statement *)NULL;
+ }
+ return statement;
+ }
+
+
+ static oci8_out_column *
+ oci8_get_col(oci8_statement *statement, int col, char *func)
+ {
+ oci8_out_column *outcol = NULL;
+ OCI8_TLS_VARS;
+
+ if (_php3_hash_index_find(statement->columns, col, (void **)&outcol) == FAILURE) {
+ php3_error(E_WARNING, "%s: invalid column %d", func, col);
+ return NULL;
+ }
+ return outcol;
+ }
+
+
+ static int
+ oci8_parse(oci8_connection *connection, text *query, ub4 len, HashTable *list)
+ {
+ oci8_statement *statement;
+ sword error;
+ OCI8_TLS_VARS;
+
+ statement = OCI8_CALLOC(1,sizeof(oci8_statement));
+ OCIHandleAlloc(connection->pEnv, (dvoid **)&statement->pStmt,
+ OCI_HTYPE_STMT, 0, NULL);
+ OCIHandleAlloc(connection->pEnv, (dvoid **)&statement->pError,
+ 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;
+ }
+
+ statement->last_query = OCI8_STRDUP(query);
+ statement->conn = connection;
+ return php3_list_insert(statement, OCI8_GLOBAL(php3_oci8_module).le_stmt);
+ }
+
+
+ static int
+ oci8_execute(oci8_statement *statement, char *func)
+ {
+ oci8_out_column *outcol;
+ OCIParam *param;
+ int counter;
+ sword error, def_error;
+ ub2 define_type;
+ OCI8_TLS_VARS;
+
+ error = OCIStmtExecute(statement->conn->pServiceContext,
+ statement->pStmt, statement->pError,
+ 0, 0, NULL, NULL, OCI_DEFAULT);
+ if (error) {
+ oci8_error(statement->pError, "OCIExecute", error);
+ return 0;
+ }
+
+ statement->columns = OCI8_MALLOC(sizeof(HashTable));
+ if (!statement->columns ||
+ _php3_hash_init(statement->columns, 13, NULL, NULL, 0) == FAILURE) {
+ /* out of memory */
+ return 0;
+ }
+
+ OCIHandleAlloc(statement->conn->pEnv, (dvoid **)¶m,
+ OCI_DTYPE_PARAM, 0, NULL);
+ counter = 1;
+ error = OCIParamGet(statement->pStmt, OCI_HTYPE_STMT, statement->pError,
+ (dvoid *)¶m, counter);
+ oci8_error(statement->pError, "OCIExecute", error);
+ while (error == OCI_SUCCESS) {
+ outcol = OCI8_CALLOC(1,sizeof(oci8_out_column));
+ if (_php3_hash_index_update(statement->columns, counter, outcol,
+ sizeof(oci8_out_column), NULL) == FAILURE) {
+ OCI8_FREE(outcol);
+ OCI8_FREE(statement->columns);
+ /* out of memory */
+ return 0;
+ } else {
+ oci8_debug("added info about column %d", counter);
+ }
+ OCI8_FREE(outcol);
+ if (_php3_hash_index_find(statement->columns, counter,
+ (void **)&outcol) == FAILURE ||
+ outcol == NULL) {
+ php3_error(E_WARNING, "%s: inserted column lost?!", func);
+ return 0;
+ }
+ outcol->name = NULL;
+
+ /* get data type */
+ /* XXX can get OCI_ATTR_TYPE_NAME instead */
+ oci8_error(statement->pError, func,
+ OCIAttrGet((dvoid *)param, OCI_DTYPE_PARAM,
+ (dvoid *)&outcol->type, (ub4 *)0,
+ OCI_ATTR_DATA_TYPE, statement->pError));
+ /* get data size */
+ oci8_error(statement->pError, func,
+ 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, func,
+ OCIAttrGet((dvoid *)param, OCI_DTYPE_PARAM,
+ (dvoid **)&outcol->name,
+ (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_BIN:
+ case SQLT_LBI:
+ case SQLT_BLOB:
+ case SQLT_CLOB:
+ case SQLT_BFILE:
+ define_type = outcol->type;
+ break;
+ default:
+ define_type = SQLT_STR;
+ outcol->storage_size++; /* add one for string terminator */
+ break;
+ }
+ outcol->data = (text *)OCI8_MALLOC(outcol->storage_size);
+ if (outcol->data == NULL) {
+ OCI8_FREE(outcol);
+ OCI8_FREE(statement->columns);
+ /* out of memory */
+ return 0;
+ }
+
+ def_error = OCIDefineByPos(statement->pStmt,
+ (OCIDefine **)&outcol->pDefine,
+ statement->pError, counter,
+ (dvoid *)outcol->data,
+ outcol->storage_size, define_type,
+ (dvoid *)0, (ub2 *)0, (ub2 *)0,
+ OCI_DEFAULT);
+
+ if (def_error) {
+ oci8_error(statement->pError, func, def_error);
+ OCI8_FREE(outcol->data);
+ OCI8_FREE(outcol);
+ OCI8_FREE(statement->columns);
+ return 0;
+ }
+ statement->ncolumns = counter;
+ counter++;
+ error = OCIParamGet(statement->pStmt, OCI_HTYPE_STMT,
+ statement->pError, (dvoid *)¶m, counter);
+ }
+ return 1;
+ }
+
+
+ static int
+ oci8_fetch(oci8_statement *statement, ub4 nrows, char *func)
+ {
+ sword error;
+ OCI8_TLS_VARS;
+
+ error = OCIStmtFetch(statement->pStmt, statement->pError, nrows,
+ OCI_FETCH_NEXT, OCI_DEFAULT);
+ oci8_debug("OCIStmtFetch returned %d", error);
+ if (error == OCI_NO_DATA) {
+ return 0;
+ }
+ if (error == OCI_SUCCESS_WITH_INFO) {
+ /* "Data was truncated or EOF was reached.",
+ * the manual says.
+ */
+ return 0;
+ }
+ if (error != OCI_SUCCESS) {
+ oci8_error(statement->pError, func, error);
+ return 0;
+ }
+ return 1;
+ }
+
+
/* }}} */
/************************* EXTENSION FUNCTIONS *************************/
***************
*** 471,477 ****
if (OCI8_GLOBAL(php3_oci8_module).max_links != -1 &&
OCI8_GLOBAL(php3_oci8_module).num_links >=
OCI8_GLOBAL(php3_oci8_module).max_links) {
! php3_error(E_WARNING, "OCI8: Too many open links (%d)",
OCI8_GLOBAL(php3_oci8_module).num_links);
RETURN_FALSE;
}
--- 701,707 ----
if (OCI8_GLOBAL(php3_oci8_module).max_links != -1 &&
OCI8_GLOBAL(php3_oci8_module).num_links >=
OCI8_GLOBAL(php3_oci8_module).max_links) {
! php3_error(E_WARNING, "OCILogon: Too many open links (%d)",
OCI8_GLOBAL(php3_oci8_module).num_links);
RETURN_FALSE;
}
***************
*** 547,596 ****
void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg1, *arg2;
oci8_connection *connection;
- oci8_statement *statement;
- char *query;
- int query_len, conn, type;
- sword error;
OCI8_TLS_VARS;
! if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
-
- convert_to_long(arg1);
- convert_to_string(arg2);
! conn = arg1->value.lval;
! connection = (oci8_connection *)php3_list_find(conn, &type);
! if (!connection || !OCI8_CONN_TYPE(type)) {
! php3_error(E_WARNING, "Invalid connection handle (%d).", conn);
! RETURN_FALSE;
! }
! query = arg2->value.str.val;
! query_len = arg2->value.str.len;
!
! statement = OCI8_CALLOC(1,sizeof(oci8_statement));
! OCIHandleAlloc(connection->pEnv, (dvoid **)&statement->pStmt,
! OCI_HTYPE_STMT, 0, NULL);
! OCIHandleAlloc(connection->pEnv, (dvoid **)&statement->pError,
! OCI_HTYPE_ERROR, 0, NULL);
! error = oci8_error(statement->pError, "OCIStmtPrepare",
! OCIStmtPrepare(statement->pStmt,
! connection->pError,
! query, query_len,
! OCI_NTV_SYNTAX, OCI_DEFAULT));
! if (error) {
RETURN_FALSE;
}
! query[query_len] = '\0';
! statement->last_query = OCI8_STRDUP(query);
! statement->conn = connection;
! RETVAL_LONG(php3_list_insert(statement,
! OCI8_GLOBAL(php3_oci8_module).le_stmt));
}
/* }}} */
--- 777,802 ----
void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *conn, *query;
oci8_connection *connection;
OCI8_TLS_VARS;
! if (getParameters(ht, 2, &conn, &query) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(conn);
! convert_to_string(query);
! connection = oci8_get_conn(conn->value.lval, "OCIParse", list, plist);
! if (connection == NULL) {
RETURN_FALSE;
}
! RETVAL_LONG(oci8_parse(connection,
! query->value.str.val,
! query->value.str.len,
! list));
}
/* }}} */
***************
*** 598,732 ****
void php3_oci8_execute(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg;
oci8_statement *statement;
- oci8_out_column *outcol;
- OCIParam *param;
- int stmt, type, counter;
- sword error, def_error;
- ub2 define_type;
OCI8_TLS_VARS;
! if (getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(arg);
! stmt = arg->value.lval;
!
! statement = (oci8_statement *)php3_list_find(stmt, &type);
! if (!statement || !OCI8_STMT_TYPE(type)) {
! php3_error(E_WARNING, "Invalid statement handle (%d).", stmt);
! RETURN_FALSE;
! }
!
! error = OCIStmtExecute(statement->conn->pServiceContext,
! statement->pStmt, statement->pError,
! 0, 0, NULL, NULL, OCI_DEFAULT);
! if (error) {
! oci8_error(statement->pError, statement->last_query, error);
RETURN_FALSE;
}
!
! statement->columns = OCI8_MALLOC(sizeof(HashTable));
! if (!statement->columns ||
! _php3_hash_init(statement->columns, 13, NULL, NULL, 0) == FAILURE) {
! RETURN_OUT_OF_MEMORY;
}
-
- OCIHandleAlloc(statement->conn->pEnv, (dvoid **)¶m,
- OCI_DTYPE_PARAM, 0, NULL);
- counter = 1;
- error = OCIParamGet(statement->pStmt, OCI_HTYPE_STMT, statement->pError,
- (dvoid *)¶m, counter);
- oci8_error(statement->pError, "OCIParamGet", error);
- while (error == OCI_SUCCESS) {
- outcol = OCI8_CALLOC(1,sizeof(oci8_out_column));
- if (_php3_hash_index_update(statement->columns, counter, outcol,
- sizeof(oci8_out_column), NULL) == FAILURE) {
- OCI8_FREE(outcol);
- OCI8_FREE(statement->columns);
- RETURN_OUT_OF_MEMORY;
- } else {
- oci8_debug("added info about column %d", counter);
- }
- OCI8_FREE(outcol);
- if (_php3_hash_index_find(statement->columns, counter,
- (void **)&outcol) == FAILURE ||
- outcol == NULL) {
- php3_error(E_WARNING, "Inserted column lost?!");
- RETURN_FALSE;
- }
- outcol->name = NULL;
-
- /* get data type */
- /* XXX can get OCI_ATTR_TYPE_NAME instead */
- oci8_error(statement->pError, "OCIAttrGet(Parameter,DataType)",
- 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(Parameter,DataSize)",
- 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(Parameter,ColumnName)",
- OCIAttrGet((dvoid *)param, OCI_DTYPE_PARAM,
- (dvoid **)&outcol->name,
- (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_BIN:
- case SQLT_LBI:
- case SQLT_BLOB:
- case SQLT_CLOB:
- case SQLT_BFILE:
- define_type = outcol->type;
- break;
- default:
- define_type = SQLT_STR;
- outcol->storage_size++; /* add one for string terminator */
- break;
- }
- outcol->data = (text *)OCI8_MALLOC(outcol->storage_size);
- if (outcol->data == NULL) {
- OCI8_FREE(outcol);
- OCI8_FREE(statement->columns);
- RETURN_OUT_OF_MEMORY;
- }
-
- def_error = OCIDefineByPos(statement->pStmt,
- (OCIDefine **)&outcol->pDefine,
- statement->pError, counter,
- (dvoid *)outcol->data,
- outcol->storage_size, define_type,
- (dvoid *)0, (ub2 *)0, (ub2 *)0,
- OCI_DEFAULT);
-
- if (def_error) {
- oci8_error(statement->pError, "OCIDefineByPos", def_error);
- OCI8_FREE(outcol->data);
- OCI8_FREE(outcol);
- OCI8_FREE(statement->columns);
- RETURN_FALSE;
- }
- statement->ncolumns = counter;
- counter++;
- error = OCIParamGet(statement->pStmt, OCI_HTYPE_STMT,
- statement->pError, (dvoid *)¶m, counter);
- }
-
- RETURN_TRUE;
}
/* }}} */
--- 804,827 ----
void php3_oci8_execute(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *stmt;
oci8_statement *statement;
OCI8_TLS_VARS;
! if (getParameters(ht, 1, &stmt) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(stmt);
! statement = oci8_get_stmt(stmt->value.lval, "OCIExecute", list);
! if (statement == NULL) {
RETURN_FALSE;
}
!
! if (oci8_execute(statement, "OCIExecute")) {
! RETVAL_TRUE;
! } else {
! RETVAL_FALSE;
}
}
/* }}} */
***************
*** 734,763 ****
void php3_oci8_columnname(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg1, *arg2;
oci8_statement *statement;
oci8_out_column *outcol;
- int stmt, type, col;
OCI8_TLS_VARS;
! if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(arg1);
! convert_to_long(arg2);
! stmt = arg1->value.lval;
! col = arg2->value.lval;
! statement = (oci8_statement *)php3_list_find(stmt, &type);
! if (!statement || !OCI8_STMT_TYPE(type)) {
! php3_error(E_WARNING, "Invalid statement handle (%d).", stmt);
RETURN_FALSE;
}
! if (_php3_hash_index_find(statement->columns, col, (void **)&outcol) ==
! FAILURE) {
! php3_error(E_WARNING, "No such column (%d).", col);
RETURN_FALSE;
}
-
RETVAL_STRINGL(outcol->name, outcol->name_len, 1);
}
--- 829,852 ----
void php3_oci8_columnname(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *stmt, *col;
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, "OCIColumnName", list);
! if (statement == NULL) {
RETURN_FALSE;
}
! outcol = oci8_get_col(statement, col->value.lval, "OCIColumnName");
! if (outcol == NULL) {
RETURN_FALSE;
}
RETVAL_STRINGL(outcol->name, outcol->name_len, 1);
}
***************
*** 766,795 ****
void php3_oci8_columnsize(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg1, *arg2;
oci8_statement *statement;
oci8_out_column *outcol;
- int stmt, type, col;
OCI8_TLS_VARS;
! if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(arg1);
! convert_to_long(arg2);
! stmt = arg1->value.lval;
! col = arg2->value.lval;
! statement = (oci8_statement *)php3_list_find(stmt, &type);
! if (!statement || !OCI8_STMT_TYPE(type)) {
! php3_error(E_WARNING, "Invalid statement handle (%d).", stmt);
RETURN_FALSE;
}
! if (_php3_hash_index_find(statement->columns, col, (void **)&outcol) ==
! FAILURE) {
! php3_error(E_WARNING, "No such column (%d).", col);
RETURN_FALSE;
}
-
RETVAL_LONG(outcol->size);
}
--- 855,878 ----
void php3_oci8_columnsize(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *stmt, *col;
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, "OCIColumnSize", list);
! if (statement == NULL) {
RETURN_FALSE;
}
! outcol = oci8_get_col(statement, col->value.lval, "OCIColumnSize");
! if (outcol == NULL) {
RETURN_FALSE;
}
RETVAL_LONG(outcol->size);
}
***************
*** 798,827 ****
void php3_oci8_columntype(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg1, *arg2;
oci8_statement *statement;
oci8_out_column *outcol;
- int stmt, type, col;
OCI8_TLS_VARS;
! if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(arg1);
! convert_to_long(arg2);
! stmt = arg1->value.lval;
! col = arg2->value.lval;
! statement = (oci8_statement *)php3_list_find(stmt, &type);
! if (!statement || !OCI8_STMT_TYPE(type)) {
! php3_error(E_WARNING, "Invalid statement handle (%d).", stmt);
RETURN_FALSE;
}
! if (_php3_hash_index_find(statement->columns, col, (void **)&outcol) ==
! FAILURE) {
! php3_error(E_WARNING, "No such column (%d).", col);
RETURN_FALSE;
}
-
switch (outcol->type) {
case SQLT_DAT:
RETVAL_STRING("DATE",1);
--- 881,904 ----
void php3_oci8_columntype(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *stmt, *col;
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, "OCIColumnType", list);
! if (statement == NULL) {
RETURN_FALSE;
}
! outcol = oci8_get_col(statement, col->value.lval, "OCIColumnType");
! if (outcol == NULL) {
RETURN_FALSE;
}
switch (outcol->type) {
case SQLT_DAT:
RETVAL_STRING("DATE",1);
***************
*** 863,928 ****
void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg;
oci8_statement *statement;
- int stmt, type;
OCI8_TLS_VARS;
! if (getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(arg);
! stmt = arg->value.lval;
!
! statement = (oci8_statement *)php3_list_find(stmt, &type);
! if (!statement || !OCI8_STMT_TYPE(type)) {
! php3_error(E_WARNING, "Invalid statement handle (%d).", stmt);
RETURN_FALSE;
}
RETVAL_LONG(statement->ncolumns);
}
/* }}} */
! /* {{{ int OCIFetch(int stmt) */
void php3_oci8_fetch(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg1;
oci8_statement *statement;
! int stmt, type;
! sword error;
! ub4 nrows = 1;
OCI8_TLS_VARS;
! if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(arg1);
! stmt = arg1->value.lval;
! statement = (oci8_statement *)php3_list_find(stmt, &type);
! if (!statement || !OCI8_STMT_TYPE(type)) {
! php3_error(E_WARNING, "Invalid statement handle (%d).", stmt);
! RETURN_FALSE;
! }
!
! error = OCIStmtFetch(statement->pStmt, statement->pError, nrows,
! OCI_FETCH_NEXT, OCI_DEFAULT);
! oci8_debug("OCIStmtFetch returned %d", error);
! if (error == OCI_NO_DATA) {
RETURN_FALSE;
}
! if (error == OCI_SUCCESS_WITH_INFO) {
! /* "Data was truncated or EOF was reached.", the documentation
! * says.
! */
! RETURN_FALSE;
! }
! if (error != OCI_SUCCESS) {
! oci8_error(statement->pError, "OCIStmtFetch", error);
! RETURN_FALSE;
}
- RETVAL_TRUE;
}
/* }}} */
--- 940,984 ----
void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *stmt;
oci8_statement *statement;
OCI8_TLS_VARS;
! if (getParameters(ht, 1, &stmt) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(stmt);
! statement = oci8_get_stmt(stmt->value.lval, "OCINumCols", list);
! if (statement == NULL) {
RETURN_FALSE;
}
RETVAL_LONG(statement->ncolumns);
}
/* }}} */
! /* {{{ int OCIFetch(int stmt) */
void php3_oci8_fetch(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *stmt;
oci8_statement *statement;
! ub4 nrows = 1; /* only one row at a time is supported for now */
OCI8_TLS_VARS;
! if (getParameters(ht, 1, &stmt) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(stmt);
! statement = oci8_get_stmt(stmt->value.lval, "OCIFetch", list);
! if (statement == NULL) {
RETURN_FALSE;
}
! if (oci8_fetch(statement, nrows, "OCIFetch")) {
! RETVAL_TRUE;
! } else {
! RETVAL_FALSE;
}
}
/* }}} */
***************
*** 930,959 ****
void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *arg1, *arg2;
oci8_statement *statement;
! oci8_out_column *outcol = NULL;
! int stmt, type, col;
OCI8_TLS_VARS;
! if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
! convert_to_long(arg1);
! convert_to_long(arg2);
! stmt = arg1->value.lval;
! col = arg2->value.lval;
! statement = (oci8_statement *)php3_list_find(stmt, &type);
! if (!statement || !OCI8_STMT_TYPE(type)) {
! php3_error(E_WARNING, "Invalid statement handle (%d).", stmt);
RETURN_FALSE;
}
! if (_php3_hash_index_find(statement->columns, col, (void **)&outcol) ==
! FAILURE) {
! php3_error(E_WARNING, "No such column (%d).", col);
RETURN_FALSE;
}
! RETVAL_STRING(outcol->data,1);
}
/* }}} */
--- 986,1010 ----
void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *stmt, *col;
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;
}
! RETVAL_STRING(outcol->data, 1);
}
/* }}} */
***************
*** 988,993 ****
--- 1039,1088 ----
}
/* }}} */
+
+ void php3_oci8_fetchinto(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *stmt, *array, element;
+ oci8_statement *statement;
+ oci8_out_column *column;
+ ub4 nrows = 1;
+ int i;
+ OCI8_TLS_VARS;
+
+ if (getParameters(ht, 2, &stmt, &array) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(stmt);
+ convert_to_long(array);
+ statement = oci8_get_stmt(stmt->value.lval, "OCIFetchInto", list);
+ if (statement == NULL) {
+ RETURN_FALSE;
+ }
+ if (array->type != IS_ARRAY) {
+ if (array_init(array) == FAILURE) {
+ php3_error(E_WARNING,
+ "OCIFetchInto: unable to convert arg 2 to array");
+ RETURN_FALSE;
+ }
+ }
+ if (!oci8_fetch(statement, nrows, "OCIFetchInto")) {
+ RETURN_FALSE;
+ }
+
+ for (i = 0; i < statement->ncolumns; i++) {
+ column = oci8_get_col(statement, i + 1, "OCIFetchInto");
+ if (column == NULL) {
+ continue;
+ }
+ element.type = IS_STRING;
+ element.value.str.len = column->size;
+ element.value.str.val = OCI8_MALLOC(column->storage_size);
+ memcpy(element.value.str.val, column->data, column->storage_size);
+ _php3_hash_index_update(array->value.ht, i, (void *)&element,
+ sizeof(pval), NULL);
+ }
+
+ }
#endif
--
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