CVS update: php3/functions
| From: | thies | Date: | Wed, 03 Feb 1999 15:08:09 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-3857@lists.php.net to get a copy of this message | ||
Date: Wednesday February 3, 1999 @ 10:08
Author: thies
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv1603/functions
Modified Files:
oci8.c php3_oci8.h
Log Message:
added BLOB read support (there's much more to come so i'm not updating the ChangeLog
now...)
Index: php3/functions/oci8.c
diff -c php3/functions/oci8.c:1.22 php3/functions/oci8.c:1.23
*** php3/functions/oci8.c:1.22 Fri Jan 1 12:59:14 1999
--- php3/functions/oci8.c Wed Feb 3 10:08:08 1999
***************
*** 30,36 ****
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.22 1999/01/01 17:59:14 zeev Exp $ */
#include "php.h"
#include "internal_functions.h"
--- 30,36 ----
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.23 1999/02/03 15:08:08 thies Exp $ */
#include "php.h"
#include "internal_functions.h"
***************
*** 129,140 ****
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_stmt(oci8_statement *statement);
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 pval *oci8_make_pval(oci8_out_column *, 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 *);
--- 129,141 ----
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_blobs(oci8_connection *connection);
static void oci8_free_stmt(oci8_statement *statement);
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 pval *oci8_make_pval(int,oci8_out_column *, char *,HashTable *);
static int oci8_parse(oci8_connection *, text *, ub4, HashTable *);
static int oci8_execute(oci8_statement *, char *);
static int oci8_fetch(oci8_statement *, ub4, char *);
***************
*** 158,163 ****
--- 159,165 ----
void php3_oci8_internaldebug(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS);
+ void php3_oci8_getblob(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS);
***************
*** 187,192 ****
--- 189,195 ----
{"ocistatementtype", php3_oci8_statementtype, NULL},
{"ocilogoff", php3_oci8_logoff, NULL},
{"ocilogon", php3_oci8_logon, NULL},
+ {"ocigetblob", php3_oci8_getblob, NULL},
/* {"ociplogon", php3_oci8_plogon, NULL},*/
{NULL, NULL, NULL}
};
***************
*** 246,251 ****
--- 249,257 ----
OCI8_GLOBAL(php3_oci8_module).num_persistent = 0;
+ OCI8_GLOBAL(php3_oci8_module).le_blob =
+ register_list_destructors(oci8_free_blobs, NULL);
+
OCI8_GLOBAL(php3_oci8_module).le_conn =
register_list_destructors(oci8_close_conn, NULL);
***************
*** 354,360 ****
oci8_free_column(oci8_out_column *column)
{
if (column->data) {
! efree(column->data);
}
if (column->value) {
efree(column->value);
--- 360,370 ----
oci8_free_column(oci8_out_column *column)
{
if (column->data) {
! if (column->is_blob) {
! /* XXX free blob here */
! } else {
! efree(column->data);
! }
}
if (column->value) {
efree(column->value);
***************
*** 375,393 ****
--- 385,417 ----
OCIHandleFree(statement->pError, OCI_HTYPE_ERROR);
if (statement->last_query) {
efree(statement->last_query);
+ statement->last_query = 0;
}
if (statement->columns) {
_php3_hash_destroy(statement->columns);
efree(statement->columns);
+ statement->columns = 0;
}
if (statement->binds) {
_php3_hash_destroy(statement->binds);
efree(statement->binds);
+ statement->binds = 0;
}
efree(statement);
}
/* }}} */
+ /* {{{ oci8_free_blobs() */
+
+ static void
+ oci8_free_blobs(oci8_connection *connection)
+ {
+ OCI8_TLS_VARS;
+ /* XXX needs implementation */
+ }
+
+ /* }}} */
+ /* }}} */
/* {{{ oci8_close_conn() */
static void
***************
*** 531,561 ****
/* {{{ oci8_make_pval() */
static pval *
! oci8_make_pval(oci8_out_column *column, char *func)
! {
! pval *value = ecalloc(1,sizeof(pval));
size_t size;
! switch (column->indicator) {
! case -1: /* NULL value, return an empty string */
! var_reset(value);
! return value;
! case -2: /* truncated value */
! oci8_debug("%s: truncated column", func);
! size = column->size;
! break;
! case 0: /* intact value */
! size = column->storage_size;
! break;
! default:
! var_reset(value);
! return value;
}
- value->type = IS_STRING;
- value->value.str.len = size;
- value->value.str.val = emalloc(size);
- memcpy(value->value.str.val, column->data, size);
- column->value = value;
return value;
}
--- 555,595 ----
/* {{{ oci8_make_pval() */
static pval *
! oci8_make_pval(int stmt_ind,oci8_out_column *column, char *func,HashTable *list)
! {
size_t size;
+ int locator;
+ pval *value = ecalloc(1,sizeof(pval));
! if (column->is_blob) {
! object_init(value);
! locator = php3_list_insert(column->data, OCI8_GLOBAL(php3_oci8_module).le_blob);
! add_property_long(value, "locator", locator);
! add_property_long(value, "statement", stmt_ind);
! add_method(value, "get", php3_oci8_getblob);
! } else {
! switch (column->indicator) {
! case -1: /* NULL value, return an empty string */
! var_reset(value);
! return value;
! case -2: /* truncated value */
! oci8_debug("%s: truncated column", func);
! size = column->size;
! break;
! case 0: /* intact value */
! size = column->storage_size;
! break;
! default:
! var_reset(value);
! return value;
! }
!
! value->type = IS_STRING;
! value->value.str.len = size;
! value->value.str.val = emalloc(size);
! memcpy(value->value.str.val, column->data, size);
! column->value = value;
}
return value;
}
***************
*** 685,720 ****
* handled specially.
*/
switch (outcol->type) {
- case SQLT_BIN: /* RAW */
- case SQLT_LBI: /* LONG RAW */
case SQLT_BLOB: /* binary LOB */
case SQLT_CLOB: /* character LOB */
case SQLT_BFILE: /* binary file LOB */
case SQLT_RSET: /* ref. cursor */
! outcol->is_opaque = 1;
define_type = outcol->type;
break;
default:
outcol->is_opaque = 0;
define_type = SQLT_STR;
outcol->storage_size++; /* add one for string terminator */
break;
}
- outcol->data = (text *)emalloc(outcol->storage_size);
- if (outcol->data == NULL) {
- efree(outcol);
- efree(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 *)&outcol->indicator, (ub2 *)0,
- (ub2 *)&outcol->retcode, OCI_DEFAULT);
if (def_error) {
oci8_debug("oci8_execute error 2");
--- 719,770 ----
* handled specially.
*/
switch (outcol->type) {
case SQLT_BLOB: /* binary LOB */
case SQLT_CLOB: /* character LOB */
+ outcol->is_blob = 1;
+ OCIDescriptorAlloc(statement->conn->pEnv,&(outcol->data), OCI_DTYPE_LOB,
(size_t) 0, (dvoid **) 0);
+ define_type = outcol->type;
+ def_error = OCIDefineByPos(statement->pStmt,
+ (OCIDefine **)&outcol->pDefine,
+ statement->pError,
+ counter,
+ (dvoid *)&(outcol->data),
+ (sb4)-1,
+ define_type,
+ (dvoid *)0,
+ (ub2 *)0,
+ (ub2 *)0,
+ OCI_DEFAULT);
+ break;
+ case SQLT_BIN: /* RAW */
+ case SQLT_LBI: /* LONG RAW */
case SQLT_BFILE: /* binary file LOB */
case SQLT_RSET: /* ref. cursor */
! outcol->is_opaque = 1;
define_type = outcol->type;
break;
default:
outcol->is_opaque = 0;
define_type = SQLT_STR;
outcol->storage_size++; /* add one for string terminator */
+ outcol->data = (text *)emalloc(outcol->storage_size);
+
+ if (outcol->data == NULL) {
+ efree(outcol);
+ efree(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 *)&outcol->indicator, (ub2 *)0,
+ (ub2 *)&outcol->retcode, OCI_DEFAULT);
break;
}
if (def_error) {
oci8_debug("oci8_execute error 2");
***************
*** 724,729 ****
--- 774,780 ----
efree(statement->columns);
return 0;
}
+
statement->ncolumns = counter;
counter++;
error = OCIParamGet(statement->pStmt, OCI_HTYPE_STMT,
***************
*** 947,952 ****
--- 998,1083 ----
}
/* }}} */
+ /* {{{ proto string ocigetblob(object blob)
+ */
+
+ void php3_oci8_getblob(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *id, *tmp, *stmt, *col;
+ int id_to_find;
+ int lob_type;
+ OCILobLocator *mylob;
+ oci8_statement *statement;
+ sword ociresult;
+ char *buffer;
+ ub4 loblen;
+ ub4 amtp;
+
+ OCI8_TLS_VARS;
+
+ if (getThis(&id) == SUCCESS) {
+ if (_php3_hash_find(id->value.ht, "statement", sizeof("statement"),
(void **)&stmt) == FAILURE) {
+ php3_error(E_WARNING, "unable to find my statement property");
+ RETURN_FALSE;
+ }
+
+ statement = oci8_get_stmt(stmt->value.lval, "OCIGetBlob", list);
+ if (statement == NULL) {
+ 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;
+ }
+
+ 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_blob) {
+ php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find);
+ RETURN_FALSE;
+ }
+
+ ociresult = OCILobGetLength(statement->conn->pServiceContext,
statement->conn->pError, mylob, &loblen);
+
+ if (ociresult) {
+ oci8_error(statement->conn->pError, "OCILobGetLength", ociresult);
+ RETURN_FALSE;
+ }
+
+ buffer = emalloc(loblen);
+
+ if (! buffer) {
+ php3_error(E_ERROR,"OCIGetBlob: unable to convert allocate %ld bytes.",loblen);
+ RETURN_FALSE;
+ }
+
+ ociresult = OCILobRead(statement->conn->pServiceContext,
+ statement->conn->pError,
+ mylob,
+ &loblen, /* IN/OUT bytes toread/read */
+ 1, /* offset (starts with 1) */
+ (dvoid *) buffer,
+ loblen, /* size of buffer */
+ (dvoid *)0,
+ (OCICallbackLobRead) 0, /* callback... */
+ (ub2) 0, /* The character set ID of the buffer data. */
+ (ub1) SQLCS_IMPLICIT); /* The character set form of the buffer data. */
+
+ if (ociresult) {
+ oci8_error(statement->conn->pError, "OCILobRead", ociresult);
+ efree(buffer);
+ RETURN_FALSE;
+ }
+
+ RETURN_STRINGL(buffer,loblen,0);
+ }
+
+ RETURN_FALSE;
+ }
+
+ /* }}} */
/* {{{ proto string OCIColumnName(int stmt, int col)
Tell the name of a column.
*/
***************
*** 1209,1215 ****
if (column == NULL || column->indicator == -1) {
continue;
}
! element = oci8_make_pval(column, "OCIFetchInto");
_php3_hash_index_update(array->value.ht, i, (void *)element,
sizeof(pval), NULL);
}
--- 1340,1346 ----
if (column == NULL || column->indicator == -1) {
continue;
}
! element = oci8_make_pval(stmt->value.lval,column, "OCIFetchInto",list);
_php3_hash_index_update(array->value.ht, i, (void *)element,
sizeof(pval), NULL);
}
***************
*** 1430,1436 ****
if (outcol == NULL) {
RETURN_FALSE;
}
! ret = oci8_make_pval(outcol, "OCIResult");
if (ret == NULL) {
RETVAL_FALSE;
} else {
--- 1561,1567 ----
if (outcol == NULL) {
RETURN_FALSE;
}
! ret = oci8_make_pval(stmt->value.lval,outcol, "OCIResult",list);
if (ret == NULL) {
RETVAL_FALSE;
} else {
Index: php3/functions/php3_oci8.h
diff -c php3/functions/php3_oci8.h:1.13 php3/functions/php3_oci8.h:1.14
*** php3/functions/php3_oci8.h:1.13 Fri Jan 1 12:59:16 1999
--- php3/functions/php3_oci8.h Wed Feb 3 10:08:08 1999
***************
*** 91,100 ****
ub2 type;
ub2 size;
ub2 storage_size;
! text *data;
sb2 indicator;
ub2 retcode;
ub2 is_opaque;
pval *value;
} oci8_out_column;
--- 91,101 ----
ub2 type;
ub2 size;
ub2 storage_size;
! void *data;
sb2 indicator;
ub2 retcode;
ub2 is_opaque;
+ ub2 is_blob;
pval *value;
} oci8_out_column;
***************
*** 109,114 ****
--- 110,116 ----
long num_persistent;
long num_links;
int le_conn;
+ int le_blob;
/* 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