Index: ext/odbc/php_odbc.c =================================================================== RCS file: /repository/php-src/ext/odbc/php_odbc.c,v retrieving revision 1.189.2.4.2.7.2.3 diff -u -r1.189.2.4.2.7.2.3 php_odbc.c --- ext/odbc/php_odbc.c 31 Dec 2007 07:17:11 -0000 1.189.2.4.2.7.2.3 +++ ext/odbc/php_odbc.c 7 Jan 2008 14:12:20 -0000 @@ -64,7 +64,7 @@ static int le_result, le_conn, le_pconn; -#define SAFE_SQL_NTS(n) ((SWORD) ((n)?(SQL_NTS):0)) +#define SAFE_SQL_NTS(n) ((SQLSMALLINT) ((n)?(SQL_NTS):0)) /* {{{ odbc_functions[] */ @@ -180,7 +180,7 @@ if (res->stmt) { #if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) || defined(HAVE_SOLID_35) SQLTransact(res->conn_ptr->henv, res->conn_ptr->hdbc, - (UWORD)SQL_COMMIT); + (SQLUSMALLINT) SQL_COMMIT); #endif rc = SQLFreeStmt(res->stmt,SQL_DROP); /* We don't want the connection to be closed after the last statment has been closed @@ -380,6 +380,50 @@ } /* }}} */ + +/* {{{ PHP_INI_DISP(display_cursortype) + */ +static PHP_INI_DISP(display_cursortype) +{ + char *value; + TSRMLS_FETCH(); + + if (type == PHP_INI_DISPLAY_ORIG && ini_entry->modified) { + value = ini_entry->orig_value; + } else if (ini_entry->value) { + value = ini_entry->value; + } else { + value = NULL; + } + + if (value) { + switch (atoi (value)) + { + case SQL_CURSOR_FORWARD_ONLY: + PUTS ("Forward Only cursor"); + break; + + case SQL_CURSOR_STATIC: + PUTS ("Static cursor"); + break; + + case SQL_CURSOR_KEYSET_DRIVEN: + PUTS ("Keyset driven cursor"); + break; + + case SQL_CURSOR_DYNAMIC: + PUTS ("Dynamic cursor"); + break; + + default: + php_printf("Unknown cursor model %s", value); + break; + } + } +} + +/* }}} */ + /* {{{ PHP_INI_BEGIN */ PHP_INI_BEGIN() @@ -401,6 +445,8 @@ defaultbinmode, zend_odbc_globals, odbc_globals, display_binmode) STD_PHP_INI_BOOLEAN("odbc.check_persistent", "1", PHP_INI_SYSTEM, OnUpdateLong, check_persistent, zend_odbc_globals, odbc_globals) + STD_PHP_INI_ENTRY_EX("odbc.default_cursortype", "3", PHP_INI_ALL, OnUpdateLong, + default_cursortype, zend_odbc_globals, odbc_globals, display_cursortype) PHP_INI_END() /* }}} */ @@ -565,9 +611,9 @@ void odbc_sql_error(ODBC_SQL_ERROR_PARAMS) { char state[6]; - SDWORD error; /* Not used */ + SQLINTEGER error; /* Not used */ char errormsg[SQL_MAX_MESSAGE_LENGTH]; - SWORD errormsgsize; /* Not used */ + SQLSMALLINT errormsgsize; /* Not used */ RETCODE rc; ODBC_SQL_ENV_T henv; ODBC_SQL_CONN_T conn; @@ -641,8 +687,8 @@ { RETCODE rc; int i; - SWORD colnamelen; /* Not used */ - SDWORD displaysize; + SQLSMALLINT colnamelen; /* Not used */ + SQLLEN displaysize; result->values = (odbc_result_value *) safe_emalloc(sizeof(odbc_result_value), result->numcols, 0); @@ -650,9 +696,9 @@ result->binmode = ODBCG(defaultbinmode); for(i = 0; i < result->numcols; i++) { - rc = SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_NAME, + rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_NAME, result->values[i].name, sizeof(result->values[i].name), &colnamelen, 0); - rc = SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_TYPE, + rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_TYPE, NULL, 0, NULL, &result->values[i].coltype); /* Don't bind LONG / BINARY columns, so that fetch behaviour can @@ -670,17 +716,17 @@ #ifdef HAVE_ADABAS case SQL_TIMESTAMP: result->values[i].value = (char *)emalloc(27); - SQLBindCol(result->stmt, (UWORD)(i+1), SQL_C_CHAR, result->values[i].value, + SQLBindCol(result->stmt, (SQLUSMALLINT)(i+1), SQL_C_CHAR, result->values[i].value, 27, &result->values[i].vallen); break; #endif /* HAVE_ADABAS */ default: - rc = SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_DISPLAY_SIZE, + rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE, NULL, 0, NULL, &displaysize); displaysize = displaysize <= result->longreadlen ? displaysize : result->longreadlen; result->values[i].value = (char *)emalloc(displaysize + 1); - rc = SQLBindCol(result->stmt, (UWORD)(i+1), SQL_C_CHAR, result->values[i].value, + rc = SQLBindCol(result->stmt, (SQLUSMALLINT)(i+1), SQL_C_CHAR, result->values[i].value, displaysize + 1, &result->values[i].vallen); break; } @@ -702,7 +748,7 @@ ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); - rc = SQLTransact(conn->henv, conn->hdbc, (UWORD)((type)?SQL_COMMIT:SQL_ROLLBACK)); + rc = SQLTransact(conn->henv, conn->hdbc, (SQLUSMALLINT)((type)?SQL_COMMIT:SQL_ROLLBACK)); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLTransact"); RETURN_FALSE; @@ -727,7 +773,7 @@ void odbc_column_lengths(INTERNAL_FUNCTION_PARAMETERS, int type) { odbc_result *result; -#if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) || defined(HAVE_OPENLINK) +#if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) /* this seems to be necessary for Solid2.3 ( tested by * tammy@synchronis.com) and Solid 3.0 (tested by eric@terra.telemediair.nl) * Solid does not seem to declare a SQLINTEGER, but it does declare a @@ -736,7 +782,7 @@ */ SDWORD len; #else - SQLINTEGER len; + SQLLEN len; #endif zval **pv_res, **pv_num; @@ -763,7 +809,7 @@ RETURN_FALSE; } - SQLColAttributes(result->stmt, (UWORD)Z_LVAL_PP(pv_num), + SQLColAttributes(result->stmt, (SQLUSMALLINT)Z_LVAL_PP(pv_num), (SQLUSMALLINT) (type?SQL_COLUMN_SCALE:SQL_COLUMN_PRECISION), NULL, 0, NULL, &len); @@ -841,7 +887,7 @@ odbc_connection *conn; RETCODE rc; #ifdef HAVE_SQL_EXTENDED_FETCH - UDWORD scrollopts; + SQLUINTEGER scrollopts; #endif if (zend_get_parameters_ex(2, &pv_conn, &pv_query) == FAILURE) { @@ -879,7 +925,8 @@ /* Try to set CURSOR_TYPE to dynamic. Driver will replace this with other type if not possible. */ - if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, SQL_CURSOR_DYNAMIC) + int cursortype = ODBCG(default_cursortype); + if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, cursortype) == SQL_ERROR) { odbc_sql_error(conn, result->stmt, " SQLSetStmtOption"); SQLFreeStmt(result->stmt, SQL_DROP); @@ -932,15 +979,15 @@ { zval **pv_res, **pv_param_arr, **tmp; typedef struct params_t { - SDWORD vallen; + SQLLEN vallen; int fp; } params_t; params_t *params = NULL; char *filename; unsigned char otype; - SWORD sqltype, ctype, scale; - SWORD nullable; - UDWORD precision; + SQLSMALLINT sqltype, ctype, scale; + SQLSMALLINT nullable; + SQLULEN precision; odbc_result *result; int numArgs, i, ne; RETCODE rc; @@ -997,7 +1044,7 @@ RETURN_FALSE; } - SQLDescribeParam(result->stmt, (UWORD)i, &sqltype, &precision, + SQLDescribeParam(result->stmt, (SQLUSMALLINT)i, &sqltype, &precision, &scale, &nullable); params[i-1].vallen = Z_STRLEN_PP(tmp); params[i-1].fp = -1; @@ -1044,7 +1091,7 @@ params[i-1].vallen = SQL_LEN_DATA_AT_EXEC(0); - rc = SQLBindParameter(result->stmt, (UWORD)i, SQL_PARAM_INPUT, + rc = SQLBindParameter(result->stmt, (SQLUSMALLINT)i, SQL_PARAM_INPUT, ctype, sqltype, precision, scale, (void *)params[i-1].fp, 0, ¶ms[i-1].vallen); @@ -1056,7 +1103,7 @@ params[i-1].vallen = SQL_NULL_DATA; } - rc = SQLBindParameter(result->stmt, (UWORD)i, SQL_PARAM_INPUT, + rc = SQLBindParameter(result->stmt, (SQLUSMALLINT)i, SQL_PARAM_INPUT, ctype, sqltype, precision, scale, Z_STRVAL_PP(tmp), 0, ¶ms[i-1].vallen); @@ -1131,7 +1178,8 @@ PHP_FUNCTION(odbc_cursor) { zval **pv_res; - SWORD len, max_len; + SQLUSMALLINT max_len; + SQLSMALLINT len; char *cursorname; odbc_result *result; RETCODE rc; @@ -1150,12 +1198,12 @@ if (max_len > 0) { cursorname = emalloc(max_len + 1); - rc = SQLGetCursorName(result->stmt,cursorname,(SWORD)max_len,&len); + rc = SQLGetCursorName(result->stmt,cursorname,(SQLSMALLINT)max_len,&len); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { char state[6]; /* Not used */ - SDWORD error; /* Not used */ - char errormsg[255]; - SWORD errormsgsize; /* Not used */ + SQLINTEGER error; /* Not used */ + char errormsg[SQL_MAX_MESSAGE_LENGTH]; + SQLSMALLINT errormsgsize; /* Not used */ SQLError( result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, state, &error, errormsg, @@ -1257,7 +1305,7 @@ odbc_connection *conn; RETCODE rc; #ifdef HAVE_SQL_EXTENDED_FETCH - UDWORD scrollopts; + SQLUINTEGER scrollopts; #endif numArgs = ZEND_NUM_ARGS(); @@ -1299,7 +1347,8 @@ /* Try to set CURSOR_TYPE to dynamic. Driver will replace this with other type if not possible. */ - if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, SQL_CURSOR_DYNAMIC) + int cursortype = ODBCG(default_cursortype); + if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, cursortype) == SQL_ERROR) { odbc_sql_error(conn, result->stmt, " SQLSetStmtOption"); SQLFreeStmt(result->stmt, SQL_DROP); @@ -1351,12 +1400,12 @@ int i; odbc_result *result; RETCODE rc; - SWORD sql_c_type; + SQLSMALLINT sql_c_type; char *buf = NULL; #ifdef HAVE_SQL_EXTENDED_FETCH - UDWORD crow; - UWORD RowStatus[1]; - SDWORD rownum = -1; + SQLULEN crow; + SQLUSMALLINT RowStatus[1]; + SQLLEN rownum = -1; zval **pv_res, **pv_row, *tmp; switch(ZEND_NUM_ARGS()) { @@ -1435,7 +1484,7 @@ break; } if (buf == NULL) buf = emalloc(result->longreadlen + 1); - rc = SQLGetData(result->stmt, (UWORD)(i + 1), sql_c_type, + rc = SQLGetData(result->stmt, (SQLUSMALLINT)(i + 1), sql_c_type, buf, result->longreadlen + 1, &result->values[i].vallen); if (rc == SQL_ERROR) { @@ -1509,14 +1558,14 @@ int numArgs, i; odbc_result *result; RETCODE rc; - SWORD sql_c_type; + SQLSMALLINT sql_c_type; char *buf = NULL; zval **pv_res, **pv_res_arr, *tmp; #ifdef HAVE_SQL_EXTENDED_FETCH zval **pv_row; - UDWORD crow; - UWORD RowStatus[1]; - SDWORD rownum = -1; + SQLULEN crow; + SQLUSMALLINT RowStatus[1]; + SQLLEN rownum = -1; #endif /* HAVE_SQL_EXTENDED_FETCH */ numArgs = ZEND_NUM_ARGS(); @@ -1594,7 +1643,7 @@ } if (buf == NULL) buf = emalloc(result->longreadlen + 1); - rc = SQLGetData(result->stmt, (UWORD)(i + 1),sql_c_type, + rc = SQLGetData(result->stmt, (SQLUSMALLINT)(i + 1),sql_c_type, buf, result->longreadlen + 1, &result->values[i].vallen); if (rc == SQL_ERROR) { @@ -1665,13 +1714,13 @@ PHP_FUNCTION(odbc_fetch_row) { int numArgs; - SDWORD rownum = 1; + SQLLEN rownum = 1; odbc_result *result; RETCODE rc; zval **pv_res, **pv_row; #ifdef HAVE_SQL_EXTENDED_FETCH - UDWORD crow; - UWORD RowStatus[1]; + SQLULEN crow; + SQLUSMALLINT RowStatus[1]; #endif numArgs = ZEND_NUM_ARGS(); @@ -1727,15 +1776,15 @@ { char *field; int field_ind; - SWORD sql_c_type = SQL_C_CHAR; + SQLSMALLINT sql_c_type = SQL_C_CHAR; odbc_result *result; int i = 0; RETCODE rc; - SDWORD fieldsize; + SQLLEN fieldsize; zval **pv_res, **pv_field; #ifdef HAVE_SQL_EXTENDED_FETCH - UDWORD crow; - UWORD RowStatus[1]; + SQLULEN crow; + SQLUSMALLINT RowStatus[1]; #endif field_ind = -1; @@ -1813,8 +1862,8 @@ else fieldsize = result->longreadlen; } else { - SQLColAttributes(result->stmt, (UWORD)(field_ind + 1), - (UWORD)((sql_c_type == SQL_C_BINARY) ? SQL_COLUMN_LENGTH : + SQLColAttributes(result->stmt, (SQLUSMALLINT)(field_ind + 1), + (SQLUSMALLINT)((sql_c_type == SQL_C_BINARY) ? SQL_COLUMN_LENGTH : SQL_COLUMN_DISPLAY_SIZE), NULL, 0, NULL, &fieldsize); } @@ -1825,7 +1874,7 @@ /* SQLGetData will truncate CHAR data to fieldsize - 1 bytes and append \0. * For binary data it is truncated to fieldsize bytes. */ - rc = SQLGetData(result->stmt, (UWORD)(field_ind + 1), sql_c_type, + rc = SQLGetData(result->stmt, (SQLUSMALLINT)(field_ind + 1), sql_c_type, field, fieldsize, &result->values[field_ind].vallen); if (rc == SQL_ERROR) { @@ -1868,7 +1917,7 @@ /* Call SQLGetData() until SQL_SUCCESS is returned */ while(1) { - rc = SQLGetData(result->stmt, (UWORD)(field_ind + 1),sql_c_type, + rc = SQLGetData(result->stmt, (SQLUSMALLINT)(field_ind + 1),sql_c_type, field, fieldsize, &result->values[field_ind].vallen); if (rc == SQL_ERROR) { @@ -1903,10 +1952,10 @@ odbc_result *result; RETCODE rc; zval **pv_res, **pv_format; - SWORD sql_c_type; + SQLSMALLINT sql_c_type; #ifdef HAVE_SQL_EXTENDED_FETCH - UDWORD crow; - UWORD RowStatus[1]; + SQLULEN crow; + SQLUSMALLINT RowStatus[1]; #endif numArgs = ZEND_NUM_ARGS(); @@ -1972,7 +2021,7 @@ if (buf == NULL) buf = emalloc(result->longreadlen); - rc = SQLGetData(result->stmt, (UWORD)(i + 1),sql_c_type, + rc = SQLGetData(result->stmt, (SQLUSMALLINT)(i + 1),sql_c_type, buf, result->longreadlen, &result->values[i].vallen); php_printf("