CVS update: php3/functions
| From: | thies | Date: | Thu, 18 Feb 1999 19:12:50 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-4151@lists.php.net to get a copy of this message | ||
Date: Thursday February 18, 1999 @ 14:12
Author: thies
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv1860/functions
Modified Files:
oci8.c
Log Message:
added OCIRowCount function
defining seems to work now (with ROWIDs, LOBs etc) -
some of the bind & define stuff is risky, as we can directly "bind" to a pval - and we
do not have reference counting yet...
Index: php3/functions/oci8.c
diff -c php3/functions/oci8.c:1.54 php3/functions/oci8.c:1.55
*** php3/functions/oci8.c:1.54 Thu Feb 18 10:04:56 1999
--- php3/functions/oci8.c Thu Feb 18 14:12:49 1999
***************
*** 32,38 ****
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.54 1999/02/18 15:04:56 thies Exp $ */
#include "php.h"
#include "internal_functions.h"
--- 32,38 ----
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.55 1999/02/18 19:12:49 thies Exp $ */
#include "php.h"
#include "internal_functions.h"
***************
*** 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 */
--- 65,73 ----
* - persistend connections
* - NULLS (retcode/indicator) needs some more work for describing & binding
* - remove all XXXs
! * - defining of Descriptors
* - clean up and documentation
+ * - OCINewContext function.
*/
/* {{{ thread safety stuff */
***************
*** 150,156 ****
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 *);
! static ub4 oci8_loadlob(oci8_connection *, oci8_descriptor *, char **);
/* bind callback functions */
static sb4 oci8_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **);
--- 151,157 ----
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 *);
! static ub4 oci8_loaddesc(oci8_connection *, oci8_descriptor *, char **);
/* bind callback functions */
static sb4 oci8_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **);
***************
*** 173,181 ****
void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_error(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);
void php3_oci8_rollback(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_newdescriptor(INTERNAL_FUNCTION_PARAMETERS);
--- 174,182 ----
void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_error(INTERNAL_FUNCTION_PARAMETERS);
! void php3_oci8_freedesc(INTERNAL_FUNCTION_PARAMETERS);
! void php3_oci8_savedesc(INTERNAL_FUNCTION_PARAMETERS);
! void php3_oci8_loaddesc(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_commit(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_rollback(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_newdescriptor(INTERNAL_FUNCTION_PARAMETERS);
***************
*** 184,189 ****
--- 185,191 ----
void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_serverversion(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_statementtype(INTERNAL_FUNCTION_PARAMETERS);
+ void php3_oci8_rowcount(INTERNAL_FUNCTION_PARAMETERS);
/* }}} */
/* {{{ extension definition structures */
***************
*** 214,225 ****
{"ociresult", php3_oci8_result, NULL},
{"ociserverversion", php3_oci8_serverversion, NULL},
{"ocistatementtype", php3_oci8_statementtype, NULL},
{"ocilogoff", php3_oci8_logoff, NULL},
{"ocilogon", php3_oci8_logon, NULL},
{"ocierror", php3_oci8_error, NULL},
! {"ocifreelob", php3_oci8_freelob, NULL},
! {"ocisavelob", php3_oci8_savelob, NULL},
! {"ociloadlob", php3_oci8_loadlob, NULL},
{"ocicommit", php3_oci8_commit, NULL},
{"ocirollback", php3_oci8_rollback, NULL},
{"ocinewdescriptor", php3_oci8_newdescriptor, NULL},
--- 216,228 ----
{"ociresult", php3_oci8_result, NULL},
{"ociserverversion", php3_oci8_serverversion, NULL},
{"ocistatementtype", php3_oci8_statementtype, NULL},
+ {"ocirowcount", php3_oci8_rowcount, NULL},
{"ocilogoff", php3_oci8_logoff, NULL},
{"ocilogon", php3_oci8_logon, NULL},
{"ocierror", php3_oci8_error, NULL},
! {"ocifreedesc", php3_oci8_freedesc, NULL},
! {"ocisavedesc", php3_oci8_savedesc, NULL},
! {"ociloaddesc", php3_oci8_loaddesc, NULL},
{"ocicommit", php3_oci8_commit, NULL},
{"ocirollback", php3_oci8_rollback, NULL},
{"ocinewdescriptor", php3_oci8_newdescriptor, NULL},
***************
*** 706,712 ****
return -1;
}
! loblen = oci8_loadlob(statement->conn,descr,&buffer);
if (loblen > 0) {
value->type = IS_STRING;
--- 709,715 ----
return -1;
}
! loblen = oci8_loaddesc(statement->conn,descr,&buffer);
if (loblen > 0) {
value->type = IS_STRING;
***************
*** 720,729 ****
add_property_long(value, "connection", statement->conn->id);
add_property_long(value, "descriptor", (long) column->data);
! if (column->type != SQLT_RDD) {
! add_method(value, "save", php3_oci8_savelob);
! add_method(value, "load", php3_oci8_loadlob);
}
}
} else {
switch (column->indicator) {
--- 723,736 ----
add_property_long(value, "connection", statement->conn->id);
add_property_long(value, "descriptor", (long) column->data);
!
! if (column->type != SQLT_RDD) { /* ROWIDs don't have any user-callable methods */
! if ((column->type != SQLT_BFILEE) && (column->type != SQLT_CFILEE)) {
! add_method(value, "save", php3_oci8_savedesc); /* oracle does not support writing
of files as of now */
! }
! add_method(value, "load", php3_oci8_loaddesc);
}
+ /* there is NO free call here, 'cause the memory gets deallocated together with the
statement! */
}
} else {
switch (column->indicator) {
***************
*** 789,794 ****
--- 796,802 ----
oci8_execute(oci8_statement *statement, char *func,ub4 mode)
{
oci8_out_column *outcol;
+ pval *tmp;
oci8_out_column column;
OCIParam *param;
oci8_descriptor descr;
***************
*** 836,841 ****
--- 844,850 ----
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++;
***************
*** 920,928 ****
*/
outcol->size = outcol->storage_size;
switch (outcol->type) {
case SQLT_RSET: /* ref. cursor XXX NYI */
- def_error = -1;
break;
case SQLT_RDD: /* ROWID */
--- 929,943 ----
*/
outcol->size = outcol->storage_size;
+ /* find a user-setted define */
+ define = 0;
+ if (statement->defines) {
+ _php3_hash_find(statement->defines,outcol->name,outcol->name_len,(void **)
&define);
+ }
+
+ def_error = -1;
switch (outcol->type) {
case SQLT_RSET: /* ref. cursor XXX NYI */
break;
case SQLT_RDD: /* ROWID */
***************
*** 931,954 ****
case SQLT_BFILE: /* binary file LOB */
outcol->is_descr = 1;
! 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(statement->conn->pEnv,(dvoid *)&(descr.ocidescr), descr.type,
(size_t) 0, (dvoid **) 0);
!
! _php3_hash_index_update(statement->conn->descriptors,
! statement->conn->descriptors_count,&descr,sizeof(oci8_descriptor),(void
**)&pdescr);
! outcol->data = (void *)(void *) statement->conn->descriptors_count++;
! oci8_debug("OCIExecute: new descriptor for %d ->
%x",outcol->data,descr.ocidescr);
define_type = outcol->type;
def_error = OCIDefineByPos(statement->pStmt,
(OCIDefine **)&outcol->pDefine,
statement->pError,
--- 946,982 ----
case SQLT_BFILE: /* binary file LOB */
outcol->is_descr = 1;
! if (define) {
! if (_php3_hash_find(define->pval->value.ht, "descriptor",
sizeof("descriptor"), (void **)&tmp) == FAILURE) {
! php3_error(E_WARNING, "unable to find my descriptor property");
! break;
! }
!
! if (_php3_hash_index_find(statement->conn->descriptors, tmp->value.lval, (void
**)&pdescr) == FAILURE) {
! php3_error(E_WARNING, "unable to find my descriptor");
! break;
! }
} else {
! 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(statement->conn->pEnv,(dvoid *)&(descr.ocidescr), descr.type,
(size_t) 0, (dvoid **) 0);
! _php3_hash_index_update(statement->conn->descriptors,
! statement->conn->descriptors_count,&descr,sizeof(oci8_descriptor),(void
**)&pdescr);
! outcol->data = (void *)(void *) statement->conn->descriptors_count++;
+ oci8_debug("OCIExecute: new descriptor for %d ->
%x",outcol->data,descr.ocidescr);
+ }
+
define_type = outcol->type;
+
def_error = OCIDefineByPos(statement->pStmt,
(OCIDefine **)&outcol->pDefine,
statement->pError,
***************
*** 972,979 ****
}
/* 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);
if (define->pval->value.str.val &&
(define->pval->value.str.val!=undefined_variable_string) &&
--- 1000,1006 ----
}
/* check for user supplied define variables! */
! if (define) {
convert_to_string(define->pval);
if (define->pval->value.str.val &&
(define->pval->value.str.val!=undefined_variable_string) &&
***************
*** 1044,1049 ****
--- 1071,1077 ----
}
if (error == OCI_SUCCESS_WITH_INFO || error == OCI_SUCCESS) {
+ /* do the stuff needed for OCIDefineByName */
for (i = 0; i < statement->ncolumns; i++) {
column = oci8_get_col(statement, i + 1, 0, "OCIFetch");
if (column == NULL) { /* should not happen... */
***************
*** 1067,1075 ****
}
/* }}} */
! /* {{{ oci8_loadlob() */
static ub4
! oci8_loadlob(oci8_connection *connection, oci8_descriptor *mydescr, char **buffer)
{
sword ociresult;
ub4 loblen;
--- 1095,1103 ----
}
/* }}} */
! /* {{{ oci8_loaddesc() */
static ub4
! oci8_loaddesc(oci8_connection *connection, oci8_descriptor *mydescr, char **buffer)
{
sword ociresult;
ub4 loblen;
***************
*** 1095,1101 ****
mydescr->ocidescr,
OCI_FILE_READONLY);
if (ociresult) {
! oci8_error(connection->pError, "OCILobRead: OCILobFileOpen", ociresult);
efree(buffer);
return 0;
}
--- 1123,1129 ----
mydescr->ocidescr,
OCI_FILE_READONLY);
if (ociresult) {
! oci8_error(connection->pError, "OCILobFileOpen", ociresult);
efree(buffer);
return 0;
}
***************
*** 1124,1130 ****
connection->pError,
mydescr->ocidescr);
if (ociresult) {
! oci8_error(connection->pError, "OCILobRead: OCILobFileClose", ociresult);
efree(buffer);
return 0;
}
--- 1152,1158 ----
connection->pError,
mydescr->ocidescr);
if (ociresult) {
! oci8_error(connection->pError, "OCILobFileClose", ociresult);
efree(buffer);
return 0;
}
***************
*** 1132,1138 ****
(*buffer)[ loblen ] = 0;
! oci8_debug("OCILoadLob: size=%d",loblen);
return loblen;
}
--- 1160,1166 ----
(*buffer)[ loblen ] = 0;
! oci8_debug("OCIloaddesc: size=%d",loblen);
return loblen;
}
***************
*** 1153,1167 ****
oci8_bind *phpbind;
pval *val;
- /* oci8_debug("oci8_bind_in_callback: ictxp=%08x", ictxp); */
-
phpbind = (oci8_bind *)ictxp;
- /* oci8_debug("oci8_bind_in_callback: phpbind=%08x", phpbind);
- if (phpbind) {
- oci8_debug("oci8_bind_in_callback: phpbind->val=%08x", phpbind->value);
- }
- */
if (!phpbind || !(val = phpbind->value)) {
php3_error(E_WARNING, "!phpbind || !phpbind->val");
return OCI_ERROR;
--- 1181,1188 ----
***************
*** 1170,1188 ****
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;
--- 1191,1200 ----
***************
*** 1211,1221 ****
oci8_bind *phpbind;
pval *val;
- /*
- oci8_debug("oci8_bind_out_callback: iter=%d index=%d alen=%d piece=%d",
- iter, index, **alenpp, *piecep);
- */
-
phpbind = (oci8_bind *)ctxp;
if (!phpbind) {
oci8_debug("oci8_bind_out_callback: phpbind = NULL");
--- 1223,1228 ----
***************
*** 1255,1262 ****
/* }}} */
- /* }}} */
-
/************************* EXTENSION FUNCTIONS *************************/
/* {{{ proto int OCIDefineByName(int stmt, string name, mixed &var [,int type])
--- 1262,1267 ----
***************
*** 1443,1452 ****
}
/* }}} */
! /* {{{ proto string ocifreelob(object lob)
*/
! void php3_oci8_freelob(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *conn, *desc;
oci8_connection *connection;
--- 1448,1457 ----
}
/* }}} */
! /* {{{ proto string ocifreedesc(object lob)
*/
! void php3_oci8_freedesc(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *conn, *desc;
oci8_connection *connection;
***************
*** 1459,1465 ****
RETURN_FALSE;
}
! connection = oci8_get_conn(conn->value.lval, "OCIFreeLob", list, plist);
if (connection == NULL) {
RETURN_FALSE;
}
--- 1464,1470 ----
RETURN_FALSE;
}
! connection = oci8_get_conn(conn->value.lval, "OCIfreedesc", list, plist);
if (connection == NULL) {
RETURN_FALSE;
}
***************
*** 1469,1475 ****
RETURN_FALSE;
}
! oci8_debug("OCOFreeLob: descr=%d",desc->value.lval);
_php3_hash_index_del(connection->descriptors,desc->value.lval);
--- 1474,1480 ----
RETURN_FALSE;
}
! oci8_debug("OCOfreedesc: descr=%d",desc->value.lval);
_php3_hash_index_del(connection->descriptors,desc->value.lval);
***************
*** 1479,1488 ****
RETURN_FALSE;
}
! /* {{{ proto string ocisavelob(object lob)
*/
! void php3_oci8_savelob(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *tmp, *conn, *arg;
OCILobLocator *mylob;
--- 1484,1493 ----
RETURN_FALSE;
}
! /* {{{ proto string ocisavedesc(object lob)
*/
! void php3_oci8_savedesc(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *tmp, *conn, *arg;
OCILobLocator *mylob;
***************
*** 1499,1505 ****
RETURN_FALSE;
}
! connection = oci8_get_conn(conn->value.lval, "OCISaveLob", list, plist);
if (connection == NULL) {
RETURN_FALSE;
}
--- 1504,1510 ----
RETURN_FALSE;
}
! connection = oci8_get_conn(conn->value.lval, "OCIsavedesc", list, plist);
if (connection == NULL) {
RETURN_FALSE;
}
***************
*** 1544,1550 ****
(ub2) 0,
(ub1) SQLCS_IMPLICIT );
! oci8_debug("OCISaveLob: size=%d",loblen);
if (ociresult) {
oci8_error(connection->pError, "OCILobWrite", ociresult);
--- 1549,1555 ----
(ub2) 0,
(ub1) SQLCS_IMPLICIT );
! oci8_debug("OCIsavedesc: size=%d",loblen);
if (ociresult) {
oci8_error(connection->pError, "OCILobWrite", ociresult);
***************
*** 1558,1567 ****
}
/* }}} */
! /* {{{ proto string ociloadlob(object lob)
*/
! void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *tmp, *conn;
oci8_connection *connection;
--- 1563,1572 ----
}
/* }}} */
! /* {{{ proto string ociloaddesc(object lob)
*/
! void php3_oci8_loaddesc(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *tmp, *conn;
oci8_connection *connection;
***************
*** 1577,1583 ****
RETURN_FALSE;
}
! connection = oci8_get_conn(conn->value.lval, "OCISaveLob", list, plist);
if (connection == NULL) {
RETURN_FALSE;
}
--- 1582,1588 ----
RETURN_FALSE;
}
! connection = oci8_get_conn(conn->value.lval, "OCIsavedesc", list, plist);
if (connection == NULL) {
RETURN_FALSE;
}
***************
*** 1592,1598 ****
RETURN_FALSE;
}
! loblen = oci8_loadlob(connection,descr,&buffer);
if (loblen > 0) {
RETURN_STRINGL(buffer,loblen,0);
--- 1597,1603 ----
RETURN_FALSE;
}
! loblen = oci8_loaddesc(connection,descr,&buffer);
if (loblen > 0) {
RETURN_STRINGL(buffer,loblen,0);
***************
*** 1648,1656 ****
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);
}
/* {{{ proto string OCIRollback(int conn)
--- 1653,1671 ----
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_freedesc);
!
! switch (descr.type) {
! case OCI_DTYPE_LOB :
! add_method(return_value, "save", php3_oci8_savedesc);
! /* breaktruh */
! case OCI_DTYPE_FILE :
! add_method(return_value, "load", php3_oci8_loaddesc);
! break;
!
! }
!
! add_method(return_value, "free", php3_oci8_freedesc);
}
/* {{{ proto string OCIRollback(int conn)
***************
*** 2419,2424 ****
--- 2434,2468 ----
default:
RETVAL_STRING("UNKNOWN",1);
}
+ }
+
+ void php3_oci8_rowcount(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *stmt;
+ oci8_statement *statement;
+ ub4 rowcount;
+ sword error;
+ OCI8_TLS_VARS;
+
+ if (getParameters(ht, 1, &stmt) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(stmt);
+ statement = oci8_get_stmt(stmt->value.lval, "OCIStatementType", list);
+ if (statement == NULL) {
+ RETURN_FALSE;
+ }
+
+ error = OCIAttrGet((dvoid *)statement->pStmt, OCI_HTYPE_STMT,
+ (ub2 *)&rowcount, (ub4 *)0, OCI_ATTR_ROW_COUNT,
+ statement->pError);
+
+ if (error != OCI_SUCCESS) {
+ oci8_error(statement->pError, "OCIRowCount", error);
+ RETURN_FALSE;
+ }
+
+ RETURN_LONG(rowcount);
}
/* }}} */
--
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