cvs: /php3/functions unified_odbc.c
| From: | Andreas Karajannis | Date: | Tue, 03 Aug 1999 07:48:19 +0000 |
| Subject: | cvs: /php3/functions unified_odbc.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-9471@lists.php.net to get a copy of this message | ||
kara Tue Aug 3 03:48:19 1999 EDT
Modified files:
/php3/functions unified_odbc.c
Log:
Small fix for host variable type in odbc_execute
Index: php3/functions/unified_odbc.c
diff -u php3/functions/unified_odbc.c:1.108 php3/functions/unified_odbc.c:1.109
--- php3/functions/unified_odbc.c:1.108 Thu Jul 15 11:55:40 1999
+++ php3/functions/unified_odbc.c Tue Aug 3 03:48:18 1999
@@ -29,7 +29,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: unified_odbc.c,v 1.108 1999/07/15 15:55:40 rasmus Exp $ */
+/* $Id: unified_odbc.c,v 1.109 1999/08/03 07:48:18 kara Exp $ */
/* This file is based on the Adabas D extension.
* Adabas D will no longer be supported as separate module.
@@ -140,16 +140,6 @@
#if HAVE_SOLID
{"solid_fetch_prev",php3_solid_fetch_prev, NULL},
#endif
-#if 0 && HAVE_IODBC /* this won't work with the new system */
-/* for backwards compatibility with the older odbc module*/
- {"sqlconnect", php3_uodbc_connect, NULL},
- {"sqldisconnect", php3_uodbc_close, NULL},
- {"sqlfetch", php3_uodbc_fetch_row, NULL},
- {"sqlexecdirect", php3_uodbc_do, NULL},
- {"sqlgetdata", php3_uodbc_result, NULL},
- {"sqlfree", php3_uodbc_free_result, NULL},
- {"sqlrowcount", php3_uodbc_num_rows, NULL},
-#endif
{ NULL, NULL, NULL }
};
@@ -158,7 +148,7 @@
UODBC_FUNCTIONS,
PHP3_MINIT_UODBC,
PHP3_MSHUTDOWN_UODBC,
- PHP3_RINIT_UODBC,
+ PHP3_RINIT_UODBC,
NULL,
PHP3_INFO_UODBC,
STANDARD_MODULE_PROPERTIES
@@ -174,6 +164,7 @@
static void _free_result(UODBC_RESULT *res)
{
int i;
+ UODBC_TLS_VARS;
if (res){
if (res->values) {
@@ -185,14 +176,19 @@
res->values = NULL;
}
if (res->stmt){
+ UODBC_CONNECTION *db_conn;
+
+ if(_php3_hash_find(UODBC_GLOBAL(PHP3_UODBC_MODULE).conns,
+ (void*)&(res->conn_ptr), sizeof(void*), (void **)&db_conn) == SUCCESS){
#if HAVE_SOLID
- SQLTransact(UODBC_GLOBAL(PHP3_UODBC_MODULE).henv, res->conn_ptr->hdbc,
- (UWORD)SQL_COMMIT);
+ SQLTransact(UODBC_GLOBAL(PHP3_UODBC_MODULE).henv, res->conn_ptr->hdbc,
+ (UWORD)SQL_COMMIT);
#endif
- SQLFreeStmt(res->stmt,SQL_DROP);
+ SQLFreeStmt(res->stmt,SQL_DROP);
#if !HAVE_IBMDB2
- res->stmt = NULL;
+ res->stmt = NULL;
#endif
+ }
}
efree(res);
}
@@ -223,12 +219,20 @@
UODBC_TLS_VARS;
conn->open = 0;
- _php3_hash_apply(UODBC_GLOBAL(PHP3_UODBC_MODULE).resource_list,
+/* _php3_hash_apply(UODBC_GLOBAL(PHP3_UODBC_MODULE).resource_list,
(int (*)(void *))_results_cleanup);
+*/
+
+#if HAVE_SOLID
+ SQLTransact(UODBC_GLOBAL(PHP3_UODBC_MODULE).henv, conn->hdbc,
+ (UWORD)SQL_COMMIT);
+#endif
+
SQLDisconnect(conn->hdbc);
SQLFreeConnect(conn->hdbc);
efree(conn);
UODBC_GLOBAL(PHP3_UODBC_MODULE).num_links--;
+ _php3_hash_del(UODBC_GLOBAL(PHP3_UODBC_MODULE).conns, (void*)&conn, sizeof(void*));
}
@@ -238,13 +242,14 @@
conn->open = 0;
+/*
_php3_hash_apply(UODBC_GLOBAL(PHP3_UODBC_MODULE).resource_plist,
(int (*)(void *))_results_cleanup);
-
+*/
SQLDisconnect(conn->hdbc);
SQLFreeConnect(conn->hdbc);
free(conn);
-
+ _php3_hash_del(UODBC_GLOBAL(PHP3_UODBC_MODULE).conns, (void*)&conn, sizeof(void*));
UODBC_GLOBAL(PHP3_UODBC_MODULE).num_links--;
UODBC_GLOBAL(PHP3_UODBC_MODULE).num_persistent--;
}
@@ -316,6 +321,9 @@
UODBC_GLOBAL(PHP3_UODBC_MODULE).le_pconn =
register_list_destructors(NULL, _close_pconnection);
+ UODBC_GLOBAL(PHP3_UODBC_MODULE).conns = malloc(sizeof(HashTable));
+ _php3_hash_init(UODBC_GLOBAL(PHP3_UODBC_MODULE).conns, 13, NULL, NULL, 1);
+
#ifdef SQLANY_BUG
/* Make a dumb connection to avoid crash on SQLFreeEnv(),
* then release it immediately.
@@ -735,7 +743,7 @@
}
SQLNumParams(result->stmt, &(result->numparams));
- SQLNumResultCols(result->stmt, &(result->numcols));
+ SQLNumResultCols(result->stmt, &(result->numcols));
if (result->numcols > 0){
if (!UODBC_BINDCOLS(result)){
@@ -758,16 +766,16 @@
Execute a prepared statement */
extern UODBC_FUNCTION(execute)
{
- pval *arg1, *arg2, arr, *tmp;
- typedef struct params_t {
+ pval *arg1, *arg2, arr, *tmp;
+ typedef struct params_t {
SDWORD vallen;
int fp;
} params_t;
params_t *params = NULL;
char *filename;
- SWORD sqltype, scale, nullable;
+ SWORD sqltype, scale, nullable, ctype;
UDWORD precision;
- UODBC_RESULT *result=NULL;
+ UODBC_RESULT *result=NULL;
int res_ind, numArgs, i, ne;
RETCODE rc;
@@ -779,12 +787,12 @@
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE)
WRONG_PARAM_COUNT;
- arr = *arg2;
- if (arr.type != IS_ARRAY) {
- php3_error(E_WARNING, "No array passed to odbc_execute()");
- return;
- }
- }
+ arr = *arg2;
+ if (arr.type != IS_ARRAY) {
+ php3_error(E_WARNING, "No array passed to odbc_execute()");
+ return;
+ }
+ }
convert_to_long(arg1);
res_ind = arg1->value.lval;
@@ -799,25 +807,26 @@
RETURN_FALSE;
}
- if (result->numparams > 0){
+ if (result->numparams > 0){
if ((ne = _php3_hash_num_elements(arr.value.ht)) < result->numparams){
php3_error(E_WARNING,"Not enough parameters (%d should be %d) given",
ne, result->numparams);
RETURN_FALSE;
}
- pval_copy_constructor(arg2);
- _php3_hash_internal_pointer_reset(arr.value.ht);
- params = (params_t *)emalloc(sizeof(params_t) * result->numparams);
+ pval_copy_constructor(arg2);
+ _php3_hash_internal_pointer_reset(arr.value.ht);
+ params = (params_t *)emalloc(sizeof(params_t) * result->numparams);
for (i = 1; i <= result->numparams; i++) {
- if (_php3_hash_get_current_data(arr.value.ht, (void **) &tmp) == FAILURE) {
- php3_error(E_WARNING,"Error getting parameter");
- SQLFreeStmt(result->stmt,SQL_RESET_PARAMS);
+ if (_php3_hash_get_current_data(arr.value.ht, (void **) &tmp)
+ == FAILURE) {
+ php3_error(E_WARNING,"Error getting parameter");
+ SQLFreeStmt(result->stmt,SQL_RESET_PARAMS);
efree(params);
- RETURN_FALSE;
- }
- convert_to_string(tmp);
+ RETURN_FALSE;
+ }
+ convert_to_string(tmp);
if (tmp->type != IS_STRING) {
php3_error(E_WARNING,"Error converting parameter");
SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
@@ -827,17 +836,21 @@
RETURN_FALSE;
}
- SQLDescribeParam(result->stmt, (UWORD)i, &sqltype, &precision,
+ SQLDescribeParam(result->stmt, (UWORD)i, &sqltype, &precision,
&scale, &nullable);
params[i-1].vallen = tmp->value.str.len;
params[i-1].fp = -1;
+ if(IS_SQL_BINARY(sqltype))
+ ctype = SQL_C_BINARY;
+ else
+ ctype = SQL_C_CHAR;
if (tmp->value.str.val[0] == '\'') {
filename = &tmp->value.str.val[1];
filename[tmp->value.str.len - 2] = '\0';
- if ((params[i-1].fp = open(filename,O_RDONLY)) == -1) {
+ if ((params[i-1].fp = open(filename,O_RDONLY)) == -1) {
php3_error(E_WARNING,"Can't open file %s", filename);
SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
for (i = 0; i < result->numparams; i++) {
@@ -854,11 +867,12 @@
params[i-1].vallen = SQL_LEN_DATA_AT_EXEC(0);
rc = SQLBindParameter(result->stmt, (UWORD)i, SQL_PARAM_INPUT,
- SQL_C_BINARY, sqltype, precision, scale,
+ ctype, sqltype, precision, scale,
(void *)params[i-1].fp, 0,
¶ms[i-1].vallen);
} else {
- /*if (IS_SQL_BINARY(sqltype)){
+/*
+ if (IS_SQL_BINARY(sqltype)){
php3_error(E_WARNING,"No Filename for binary parameter");
SQLFreeStmt(result->stmt,SQL_RESET_PARAMS);
_php3_hash_destroy(arr.value.ht);
@@ -868,7 +882,7 @@
}
*/
rc = SQLBindParameter(result->stmt, (UWORD)i, SQL_PARAM_INPUT,
- SQL_C_CHAR, sqltype, precision, scale,
+ ctype, sqltype, precision, scale,
tmp->value.str.val, 0,
¶ms[i-1].vallen);
}
@@ -1994,6 +2008,14 @@
RETURN_FALSE;
}
}
+
+ _php3_hash_add(UODBC_GLOBAL(PHP3_UODBC_MODULE).conns,
+ (void*)&db_conn,
+ sizeof(void*),
+ (void*)&db_conn,
+ sizeof(void*),
+ NULL);
+
efree(hashed_details);
return_value->type = IS_LONG;
}