diff options
Diffstat (limited to 'ext/pdo_odbc')
-rw-r--r-- | ext/pdo_odbc/odbc_driver.c | 60 | ||||
-rw-r--r-- | ext/pdo_odbc/odbc_stmt.c | 204 | ||||
-rw-r--r-- | ext/pdo_odbc/pdo_odbc.c | 8 | ||||
-rw-r--r-- | ext/pdo_odbc/php_pdo_odbc.h | 18 | ||||
-rw-r--r-- | ext/pdo_odbc/php_pdo_odbc_int.h | 18 |
5 files changed, 162 insertions, 146 deletions
diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c index 08fafa6a34..378bf95c94 100644 --- a/ext/pdo_odbc/odbc_driver.c +++ b/ext/pdo_odbc/odbc_driver.c @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -31,32 +31,32 @@ #include "php_pdo_odbc_int.h" #include "zend_exceptions.h" -static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC) +static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; pdo_odbc_errinfo *einfo = &H->einfo; pdo_odbc_stmt *S = NULL; - char *message = NULL; + zend_string *message = NULL; if (stmt) { S = (pdo_odbc_stmt*)stmt->driver_data; einfo = &S->einfo; } - spprintf(&message, 0, "%s (%s[%ld] at %s:%d)", + message = strpprintf(0, "%s (%s[%ld] at %s:%d)", einfo->last_err_msg, einfo->what, einfo->last_error, einfo->file, einfo->line); add_next_index_long(info, einfo->last_error); - add_next_index_string(info, message, 0); - add_next_index_string(info, einfo->last_state, 1); + add_next_index_str(info, message); + add_next_index_string(info, einfo->last_state); return 1; } -void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line TSRMLS_DC) /* {{{ */ +void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line) /* {{{ */ { SQLRETURN rc; SQLSMALLINT errmsgsize = 0; @@ -104,7 +104,7 @@ void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, strcpy(*pdo_err, einfo->last_state); /* printf("@@ SQLSTATE[%s] %s\n", *pdo_err, einfo->last_err_msg); */ if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), einfo->last_error TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->last_error, "SQLSTATE[%s] %s: %d %s", *pdo_err, what, einfo->last_error, einfo->last_err_msg); } @@ -124,7 +124,7 @@ void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, } /* }}} */ -static int odbc_handle_closer(pdo_dbh_t *dbh TSRMLS_DC) +static int odbc_handle_closer(pdo_dbh_t *dbh) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle*)dbh->driver_data; @@ -142,7 +142,7 @@ static int odbc_handle_closer(pdo_dbh_t *dbh TSRMLS_DC) return 0; } -static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC) +static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len, pdo_stmt_t *stmt, zval *driver_options) { RETCODE rc; pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; @@ -158,8 +158,8 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, p /* before we prepare, we need to peek at the query; if it uses named parameters, * we want PDO to rewrite them for us */ stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL; - ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len TSRMLS_CC); - + ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len); + if (ret == 1) { /* query was re-written */ sql = nsql; @@ -169,7 +169,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, p efree(S); return 0; } - + rc = SQLAllocHandle(SQL_HANDLE_STMT, H->dbc, &S->stmt); if (rc == SQL_INVALID_HANDLE || rc == SQL_ERROR) { @@ -181,7 +181,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, p return 0; } - cursor_type = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY TSRMLS_CC); + cursor_type = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY); if (cursor_type != PDO_CURSOR_FWDONLY) { rc = SQLSetStmtAttr(S->stmt, SQL_ATTR_CURSOR_SCROLLABLE, (void*)SQL_SCROLLABLE, 0); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { @@ -193,7 +193,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, p return 0; } } - + rc = SQLPrepare(S->stmt, (char*)sql, SQL_NTS); if (nsql) { efree(nsql); @@ -220,13 +220,13 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, p return 1; } -static long odbc_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC) +static zend_long odbc_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; RETCODE rc; SQLLEN row_count = -1; PDO_ODBC_HSTMT stmt; - + rc = SQLAllocHandle(SQL_HANDLE_STMT, H->dbc, &stmt); if (rc != SQL_SUCCESS) { pdo_odbc_drv_error("SQLAllocHandle: STMT"); @@ -261,14 +261,14 @@ out: return row_count; } -static int odbc_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type param_type TSRMLS_DC) +static int odbc_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type param_type ) { /* pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; */ /* TODO: figure it out */ return 0; } -static int odbc_handle_begin(pdo_dbh_t *dbh TSRMLS_DC) +static int odbc_handle_begin(pdo_dbh_t *dbh) { if (dbh->auto_commit) { /* we need to disable auto-commit now, to be able to initiate a transaction */ @@ -284,7 +284,7 @@ static int odbc_handle_begin(pdo_dbh_t *dbh TSRMLS_DC) return 1; } -static int odbc_handle_commit(pdo_dbh_t *dbh TSRMLS_DC) +static int odbc_handle_commit(pdo_dbh_t *dbh) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; RETCODE rc; @@ -310,7 +310,7 @@ static int odbc_handle_commit(pdo_dbh_t *dbh TSRMLS_DC) return 1; } -static int odbc_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC) +static int odbc_handle_rollback(pdo_dbh_t *dbh) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; RETCODE rc; @@ -336,7 +336,7 @@ static int odbc_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC) return 1; } -static int odbc_handle_set_attr(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) +static int odbc_handle_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; switch (attr) { @@ -351,12 +351,12 @@ static int odbc_handle_set_attr(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) } } -static int odbc_handle_get_attr(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) +static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; switch (attr) { case PDO_ATTR_CLIENT_VERSION: - ZVAL_STRING(val, "ODBC-" PDO_ODBC_TYPE, 1); + ZVAL_STRING(val, "ODBC-" PDO_ODBC_TYPE); return 1; case PDO_ATTR_SERVER_VERSION: @@ -388,7 +388,7 @@ static struct pdo_dbh_methods odbc_methods = { NULL, /* check_liveness */ }; -static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC) /* {{{ */ +static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ */ { pdo_odbc_db_handle *H; RETCODE rc; @@ -398,7 +398,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_D H = pecalloc(1, sizeof(*H), dbh->is_persistent); dbh->driver_data = H; - + SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &H->env); rc = SQLSetEnvAttr(H->env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); @@ -416,7 +416,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_D } } #endif - + rc = SQLAllocHandle(SQL_HANDLE_DBC, H->env, &H->dbc); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { pdo_odbc_drv_error("SQLAllocHandle (DBC)"); @@ -431,7 +431,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_D } /* set up the cursor library, if needed, or if configured explicitly */ - cursor_lib = pdo_attr_lval(driver_options, PDO_ODBC_ATTR_USE_CURSOR_LIBRARY, SQL_CUR_USE_IF_NEEDED TSRMLS_CC); + cursor_lib = pdo_attr_lval(driver_options, PDO_ODBC_ATTR_USE_CURSOR_LIBRARY, SQL_CUR_USE_IF_NEEDED); rc = SQLSetConnectAttr(H->dbc, SQL_ODBC_CURSORS, (void*)cursor_lib, SQL_IS_INTEGER); if (rc != SQL_SUCCESS && cursor_lib != SQL_CUR_USE_IF_NEEDED) { pdo_odbc_drv_error("SQLSetConnectAttr SQL_ODBC_CURSORS"); @@ -469,7 +469,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_D dbh->methods = &odbc_methods; dbh->alloc_own_columns = 1; - + return 1; fail: diff --git a/ext/pdo_odbc/odbc_stmt.c b/ext/pdo_odbc/odbc_stmt.c index 2b88df81a0..729f818094 100644 --- a/ext/pdo_odbc/odbc_stmt.c +++ b/ext/pdo_odbc/odbc_stmt.c @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -57,8 +57,8 @@ static int pdo_odbc_sqltype_is_unicode(pdo_odbc_stmt *S, SWORD sqltype) } } -static int pdo_odbc_utf82ucs2(pdo_stmt_t *stmt, int is_unicode, const char *buf, - unsigned long buflen, unsigned long *outlen) +static int pdo_odbc_utf82ucs2(pdo_stmt_t *stmt, int is_unicode, const char *buf, + zend_ulong buflen, zend_ulong *outlen) { #ifdef PHP_WIN32 if (is_unicode && buflen) { @@ -77,7 +77,7 @@ static int pdo_odbc_utf82ucs2(pdo_stmt_t *stmt, int is_unicode, const char *buf, S->convbufsize = ret + sizeof(WCHAR); S->convbuf = erealloc(S->convbuf, S->convbufsize); } - + ret = MultiByteToWideChar(CP_UTF8, 0, buf, buflen, (LPWSTR)S->convbuf, S->convbufsize / sizeof(WCHAR)); if (ret == 0) { /*printf("%s:%d %d [%d] %.*s\n", __FILE__, __LINE__, GetLastError(), buflen, buflen, buf);*/ @@ -92,8 +92,8 @@ static int pdo_odbc_utf82ucs2(pdo_stmt_t *stmt, int is_unicode, const char *buf, return PDO_ODBC_CONV_NOT_REQUIRED; } -static int pdo_odbc_ucs22utf8(pdo_stmt_t *stmt, int is_unicode, const char *buf, - unsigned long buflen, unsigned long *outlen) +static int pdo_odbc_ucs22utf8(pdo_stmt_t *stmt, int is_unicode, const char *buf, + zend_ulong buflen, zend_ulong *outlen) { #ifdef PHP_WIN32 if (is_unicode && buflen) { @@ -109,7 +109,7 @@ static int pdo_odbc_ucs22utf8(pdo_stmt_t *stmt, int is_unicode, const char *buf, S->convbufsize = ret + 1; S->convbuf = erealloc(S->convbuf, S->convbufsize); } - + ret = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)buf, buflen/sizeof(WCHAR), S->convbuf, S->convbufsize, NULL, NULL); if (ret == 0) { return PDO_ODBC_CONV_FAIL; @@ -123,7 +123,7 @@ static int pdo_odbc_ucs22utf8(pdo_stmt_t *stmt, int is_unicode, const char *buf, return PDO_ODBC_CONV_NOT_REQUIRED; } -static void free_cols(pdo_stmt_t *stmt, pdo_odbc_stmt *S TSRMLS_DC) +static void free_cols(pdo_stmt_t *stmt, pdo_odbc_stmt *S) { if (S->cols) { int i; @@ -138,7 +138,7 @@ static void free_cols(pdo_stmt_t *stmt, pdo_odbc_stmt *S TSRMLS_DC) } } -static int odbc_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) +static int odbc_stmt_dtor(pdo_stmt_t *stmt) { pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; @@ -150,7 +150,7 @@ static int odbc_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) S->stmt = SQL_NULL_HANDLE; } - free_cols(stmt, S TSRMLS_CC); + free_cols(stmt, S); if (S->convbuf) { efree(S->convbuf); } @@ -159,7 +159,7 @@ static int odbc_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) return 1; } -static int odbc_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) +static int odbc_stmt_execute(pdo_stmt_t *stmt) { RETCODE rc; pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; @@ -169,8 +169,8 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) if (stmt->executed) { SQLCloseCursor(S->stmt); } - - rc = SQLExecute(S->stmt); + + rc = SQLExecute(S->stmt); while (rc == SQL_NEED_DATA) { struct pdo_bound_param_data *param; @@ -180,20 +180,26 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) php_stream *stm; int len; pdo_odbc_param *P; - + zval *parameter; + P = (pdo_odbc_param*)param->driver_data; - if (Z_TYPE_P(param->parameter) != IS_RESOURCE) { + if (Z_ISREF(param->parameter)) { + parameter = Z_REFVAL(param->parameter); + } else { + parameter = ¶m->parameter; + } + if (Z_TYPE_P(parameter) != IS_RESOURCE) { /* they passed in a string */ - unsigned long ulen; - convert_to_string(param->parameter); + zend_ulong ulen; + convert_to_string(parameter); - switch (pdo_odbc_utf82ucs2(stmt, P->is_unicode, - Z_STRVAL_P(param->parameter), - Z_STRLEN_P(param->parameter), + switch (pdo_odbc_utf82ucs2(stmt, P->is_unicode, + Z_STRVAL_P(parameter), + Z_STRLEN_P(parameter), &ulen)) { case PDO_ODBC_CONV_NOT_REQUIRED: - SQLPutData(S->stmt, Z_STRVAL_P(param->parameter), - Z_STRLEN_P(param->parameter)); + SQLPutData(S->stmt, Z_STRVAL_P(parameter), + Z_STRLEN_P(parameter)); break; case PDO_ODBC_CONV_OK: SQLPutData(S->stmt, S->convbuf, ulen); @@ -212,7 +218,7 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) /* we assume that LOBs are binary and don't need charset * conversion */ - php_stream_from_zval_no_verify(stm, ¶m->parameter); + php_stream_from_zval_no_verify(stm, parameter); if (!stm) { /* shouldn't happen either */ pdo_odbc_stmt_error("input LOB is no longer a stream"); @@ -274,14 +280,15 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) } static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, - enum pdo_param_event event_type TSRMLS_DC) + enum pdo_param_event event_type) { pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; RETCODE rc; SWORD sqltype = 0, ctype = 0, scale = 0, nullable = 0; SQLULEN precision = 0; pdo_odbc_param *P; - + zval *parameter; + /* we're only interested in parameters for prepared SQL right now */ if (param->is_param) { @@ -308,7 +315,7 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p case PDO_PARAM_STMT: return 0; - + default: break; } @@ -353,7 +360,7 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p } else { P->paramtype = SQL_PARAM_OUTPUT; } - + if (P->paramtype != SQL_PARAM_INPUT) { if (PDO_PARAM_TYPE(param->param_type) != PDO_PARAM_NULL) { /* need an explicit buffer to hold result */ @@ -364,7 +371,7 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p P->outbuf = emalloc(P->len + (P->is_unicode ? 2:1)); } } - + if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && P->paramtype != SQL_PARAM_INPUT) { pdo_odbc_stmt_error("Can't bind a lob for output"); return 0; @@ -372,13 +379,13 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p rc = SQLBindParameter(S->stmt, (SQLUSMALLINT) param->paramno+1, P->paramtype, ctype, sqltype, precision, scale, - P->paramtype == SQL_PARAM_INPUT ? + P->paramtype == SQL_PARAM_INPUT ? (SQLPOINTER)param : P->outbuf, P->len, &P->len ); - + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { return 1; } @@ -388,12 +395,18 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p case PDO_PARAM_EVT_EXEC_PRE: P = param->driver_data; + if (!Z_ISREF(param->parameter)) { + parameter = ¶m->parameter; + } else { + parameter = Z_REFVAL(param->parameter); + } + if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) { - if (Z_TYPE_P(param->parameter) == IS_RESOURCE) { + if (Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream *stm; php_stream_statbuf sb; - php_stream_from_zval_no_verify(stm, ¶m->parameter); + php_stream_from_zval_no_verify(stm, parameter); if (!stm) { return 0; @@ -432,28 +445,28 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p } } } else { - convert_to_string(param->parameter); + convert_to_string(parameter); if (P->outbuf) { - P->len = Z_STRLEN_P(param->parameter); - memcpy(P->outbuf, Z_STRVAL_P(param->parameter), P->len); + P->len = Z_STRLEN_P(parameter); + memcpy(P->outbuf, Z_STRVAL_P(parameter), P->len); } else { - P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(param->parameter)); + P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(parameter)); } } - } else if (Z_TYPE_P(param->parameter) == IS_NULL || PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL) { + } else if (Z_TYPE_P(parameter) == IS_NULL || PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL) { P->len = SQL_NULL_DATA; } else { - convert_to_string(param->parameter); + convert_to_string(parameter); if (P->outbuf) { - unsigned long ulen; + zend_ulong ulen; switch (pdo_odbc_utf82ucs2(stmt, P->is_unicode, - Z_STRVAL_P(param->parameter), - Z_STRLEN_P(param->parameter), + Z_STRVAL_P(parameter), + Z_STRLEN_P(parameter), &ulen)) { case PDO_ODBC_CONV_FAIL: case PDO_ODBC_CONV_NOT_REQUIRED: - P->len = Z_STRLEN_P(param->parameter); - memcpy(P->outbuf, Z_STRVAL_P(param->parameter), P->len); + P->len = Z_STRLEN_P(parameter); + memcpy(P->outbuf, Z_STRVAL_P(parameter), P->len); break; case PDO_ODBC_CONV_OK: P->len = ulen; @@ -461,44 +474,47 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p break; } } else { - P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(param->parameter)); + P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(parameter)); } } return 1; - + case PDO_PARAM_EVT_EXEC_POST: P = param->driver_data; + if (P->outbuf) { - if (P->outbuf) { - unsigned long ulen; - char *srcbuf; - unsigned long srclen = 0; - - switch (P->len) { - case SQL_NULL_DATA: - zval_dtor(param->parameter); - ZVAL_NULL(param->parameter); - break; - default: - convert_to_string(param->parameter); - switch (pdo_odbc_ucs22utf8(stmt, P->is_unicode, P->outbuf, P->len, &ulen)) { - case PDO_ODBC_CONV_FAIL: - /* something fishy, but allow it to come back as binary */ - case PDO_ODBC_CONV_NOT_REQUIRED: - srcbuf = P->outbuf; - srclen = P->len; - break; - case PDO_ODBC_CONV_OK: - srcbuf = S->convbuf; - srclen = ulen; - break; - } - - Z_STRVAL_P(param->parameter) = erealloc(Z_STRVAL_P(param->parameter), srclen+1); - memcpy(Z_STRVAL_P(param->parameter), srcbuf, srclen); - Z_STRLEN_P(param->parameter) = srclen; - Z_STRVAL_P(param->parameter)[srclen] = '\0'; - } + zend_ulong ulen; + char *srcbuf; + zend_ulong srclen = 0; + + if (Z_ISREF(param->parameter)) { + parameter = Z_REFVAL(param->parameter); + } else { + parameter = ¶m->parameter; + } + zval_ptr_dtor(parameter); + ZVAL_NULL(parameter); + + switch (P->len) { + case SQL_NULL_DATA: + break; + default: + switch (pdo_odbc_ucs22utf8(stmt, P->is_unicode, P->outbuf, P->len, &ulen)) { + case PDO_ODBC_CONV_FAIL: + /* something fishy, but allow it to come back as binary */ + case PDO_ODBC_CONV_NOT_REQUIRED: + srcbuf = P->outbuf; + srclen = P->len; + break; + case PDO_ODBC_CONV_OK: + srcbuf = S->convbuf; + srclen = ulen; + break; + } + + ZVAL_NEW_STR(parameter, zend_string_alloc(srclen, 0)); + memcpy(Z_STRVAL_P(parameter), srcbuf, srclen); + Z_STRVAL_P(parameter)[Z_STRLEN_P(parameter)] = '\0'; } } return 1; @@ -508,7 +524,7 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p } static int odbc_stmt_fetch(pdo_stmt_t *stmt, - enum pdo_fetch_orientation ori, long offset TSRMLS_DC) + enum pdo_fetch_orientation ori, zend_long offset) { RETCODE rc; SQLSMALLINT odbcori; @@ -521,7 +537,7 @@ static int odbc_stmt_fetch(pdo_stmt_t *stmt, case PDO_FETCH_ORI_LAST: odbcori = SQL_FETCH_LAST; break; case PDO_FETCH_ORI_ABS: odbcori = SQL_FETCH_ABSOLUTE; break; case PDO_FETCH_ORI_REL: odbcori = SQL_FETCH_RELATIVE; break; - default: + default: strcpy(stmt->error_code, "HY106"); return 0; } @@ -545,7 +561,7 @@ static int odbc_stmt_fetch(pdo_stmt_t *stmt, return 0; } -static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) +static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno) { pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; struct pdo_column_data *col = &stmt->columns[colno]; @@ -612,15 +628,15 @@ static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) return 1; } -static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len, int *caller_frees TSRMLS_DC) +static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees) { pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; pdo_odbc_column *C = &S->cols[colno]; - unsigned long ulen; + zend_ulong ulen; /* if it is a column containing "long" data, perform late binding now */ if (C->is_long) { - unsigned long used = 0; + zend_ulong used = 0; char *buf; RETCODE rc; @@ -639,10 +655,10 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned l if (rc == SQL_SUCCESS_WITH_INFO) { /* this is a 'long column' - + read the column in 255 byte blocks until the end of the column is reached, reassembling those blocks in order into the output buffer - + this loop has to work whether or not SQLGetData() provides the total column length. calling SQLDescribeCol() or other, specifically to get the column length, then doing a single read for that size would be slower except maybe for extremely long columns.*/ @@ -651,12 +667,12 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned l buf2 = emalloc(256); buf = estrndup(C->data, 256); used = 255; /* not 256; the driver NUL terminated the buffer */ - + do { C->fetched_len = 0; /* read block. 256 bytes => 255 bytes are actually read, the last 1 is NULL */ rc = SQLGetData(S->stmt, colno+1, SQL_C_CHAR, buf2, 256, &C->fetched_len); - + /* resize output buffer and reassemble block */ if (rc==SQL_SUCCESS_WITH_INFO) { /* point 5, in section "Retrieving Data with SQLGetData" in http://msdn.microsoft.com/en-us/library/windows/desktop/ms715441(v=vs.85).aspx @@ -673,11 +689,11 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned l /* includes SQL_NO_DATA */ break; } - + } while (1); - + efree(buf2); - + /* NULL terminate the buffer once, when finished, for use with the rest of PHP */ buf[used] = '\0'; @@ -739,7 +755,7 @@ in_data: return 1; } -static int odbc_stmt_set_param(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC) +static int odbc_stmt_set_param(pdo_stmt_t *stmt, zend_long attr, zval *val) { SQLRETURN rc; pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; @@ -766,7 +782,7 @@ static int odbc_stmt_set_param(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC) } } -static int odbc_stmt_get_attr(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC) +static int odbc_stmt_get_attr(pdo_stmt_t *stmt, zend_long attr, zval *val) { SQLRETURN rc; pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data; @@ -779,7 +795,7 @@ static int odbc_stmt_get_attr(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC) rc = SQLGetCursorName(S->stmt, buf, sizeof(buf), &len); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - ZVAL_STRINGL(val, buf, len, 1); + ZVAL_STRINGL(val, buf, len); return 1; } pdo_odbc_stmt_error("SQLGetCursorName"); @@ -798,7 +814,7 @@ static int odbc_stmt_get_attr(pdo_stmt_t *stmt, long attr, zval *val TSRMLS_DC) } } -static int odbc_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) +static int odbc_stmt_next_rowset(pdo_stmt_t *stmt) { SQLRETURN rc; SQLSMALLINT colcount; @@ -813,7 +829,7 @@ static int odbc_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) return 0; } - free_cols(stmt, S TSRMLS_CC); + free_cols(stmt, S); /* how many columns do we have ? */ SQLNumResultCols(S->stmt, &colcount); stmt->column_count = (int)colcount; diff --git a/ext/pdo_odbc/pdo_odbc.c b/ext/pdo_odbc/pdo_odbc.c index 71b8d489b2..144f318ac7 100644 --- a/ext/pdo_odbc/pdo_odbc.c +++ b/ext/pdo_odbc/pdo_odbc.c @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -127,7 +127,7 @@ PHP_MINIT_FUNCTION(pdo_odbc) } else if (*pooling_val == '\0' || strcasecmp(pooling_val, "off") == 0) { pdo_odbc_pool_on = SQL_CP_OFF; } else { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in pdo_odbc.connection_pooling configuration. Value MUST be one of 'strict', 'relaxed' or 'off'"); + php_error_docref(NULL, E_ERROR, "Error in pdo_odbc.connection_pooling configuration. Value MUST be one of 'strict', 'relaxed' or 'off'"); return FAILURE; } @@ -141,7 +141,7 @@ PHP_MINIT_FUNCTION(pdo_odbc) REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_IF_NEEDED", SQL_CUR_USE_IF_NEEDED); REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_DRIVER", SQL_CUR_USE_DRIVER); REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_ODBC", SQL_CUR_USE_ODBC); - + return SUCCESS; } /* }}} */ diff --git a/ext/pdo_odbc/php_pdo_odbc.h b/ext/pdo_odbc/php_pdo_odbc.h index 0d296afa2f..4cca0b494d 100644 --- a/ext/pdo_odbc/php_pdo_odbc.h +++ b/ext/pdo_odbc/php_pdo_odbc.h @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -34,9 +34,9 @@ PHP_RINIT_FUNCTION(pdo_odbc); PHP_RSHUTDOWN_FUNCTION(pdo_odbc); PHP_MINFO_FUNCTION(pdo_odbc); -/* +/* Declare any global variables you may need between the BEGIN - and END macros here: + and END macros here: ZEND_BEGIN_MODULE_GLOBALS(pdo_odbc) long global_value; @@ -44,12 +44,12 @@ ZEND_BEGIN_MODULE_GLOBALS(pdo_odbc) ZEND_END_MODULE_GLOBALS(pdo_odbc) */ -/* In every utility function you add that needs to use variables - in php_pdo_odbc_globals, call TSRMLS_FETCH(); after declaring other - variables used by that function, or better yet, pass in TSRMLS_CC +/* In every utility function you add that needs to use variables + in php_pdo_odbc_globals, call TSRMLS_FETCH(); after declaring other + variables used by that function, or better yet, pass in after the last function argument and declare your utility function - with TSRMLS_DC after the last declared argument. Always refer to - the globals in your function as PDO_ODBC_G(variable). You are + with after the last declared argument. Always refer to + the globals in your function as PDO_ODBC_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */ diff --git a/ext/pdo_odbc/php_pdo_odbc_int.h b/ext/pdo_odbc/php_pdo_odbc_int.h index a30ee2be20..2098c7c1bc 100644 --- a/ext/pdo_odbc/php_pdo_odbc_int.h +++ b/ext/pdo_odbc/php_pdo_odbc_int.h @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -135,7 +135,7 @@ typedef struct { typedef struct { char *data; - unsigned long datalen; + zend_ulong datalen; SQLLEN fetched_len; SWORD coltype; char colname[128]; @@ -150,7 +150,7 @@ typedef struct { pdo_odbc_db_handle *H; pdo_odbc_errinfo einfo; char *convbuf; - unsigned long convbufsize; + zend_ulong convbufsize; unsigned going_long:1; unsigned assume_utf8:1; unsigned _spare:30; @@ -163,14 +163,14 @@ typedef struct { unsigned is_unicode:1; unsigned _spare:31; } pdo_odbc_param; - + extern pdo_driver_t pdo_odbc_driver; extern struct pdo_stmt_methods odbc_stmt_methods; -void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line TSRMLS_DC); -#define pdo_odbc_drv_error(what) pdo_odbc_error(dbh, NULL, SQL_NULL_HSTMT, what, __FILE__, __LINE__ TSRMLS_CC) -#define pdo_odbc_stmt_error(what) pdo_odbc_error(stmt->dbh, stmt, SQL_NULL_HSTMT, what, __FILE__, __LINE__ TSRMLS_CC) -#define pdo_odbc_doer_error(what) pdo_odbc_error(dbh, NULL, stmt, what, __FILE__, __LINE__ TSRMLS_CC) +void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line); +#define pdo_odbc_drv_error(what) pdo_odbc_error(dbh, NULL, SQL_NULL_HSTMT, what, __FILE__, __LINE__) +#define pdo_odbc_stmt_error(what) pdo_odbc_error(stmt->dbh, stmt, SQL_NULL_HSTMT, what, __FILE__, __LINE__) +#define pdo_odbc_doer_error(what) pdo_odbc_error(dbh, NULL, stmt, what, __FILE__, __LINE__) void pdo_odbc_init_error_table(void); void pdo_odbc_fini_error_table(void); |