diff --git a/pdo_sqlsrv/CREDITS b/pdo_sqlsrv/CREDITS index f083a7a0..c3489015 100644 --- a/pdo_sqlsrv/CREDITS +++ b/pdo_sqlsrv/CREDITS @@ -1 +1 @@ -Microsoft Drivers for PHP for SQL Server 2.0 +Microsoft Drivers for PHP for SQL Server 2.0 Cumulative Update 1 diff --git a/pdo_sqlsrv/config.w32 b/pdo_sqlsrv/config.w32 index ea9ef4d5..27359d65 100644 --- a/pdo_sqlsrv/config.w32 +++ b/pdo_sqlsrv/config.w32 @@ -23,16 +23,16 @@ ARG_WITH("pdo-sqlsrv", "MS SQL Server support for PDO", "no"); if( PHP_PDO_SQLSRV != "no" ) { - if (CHECK_LIB("odbc32.lib", "pdo_sqlsrv") && CHECK_LIB("odbccp32.lib", "pdo_sqlsrv") && - CHECK_LIB("version.lib", "pdo_sqlsrv") && CHECK_LIB("psapi.lib", "pdo_sqlsrv")) { + if (CHECK_LIB("odbc32.lib", "pdo_sqlsrv") && CHECK_LIB("odbccp32.lib", "pdo_sqlsrv") && + CHECK_LIB("version.lib", "pdo_sqlsrv") && CHECK_LIB("psapi.lib", "pdo_sqlsrv")) { - EXTENSION("pdo_sqlsrv", "pdo_dbh.cpp pdo_init.cpp pdo_stmt.cpp pdo_util.cpp pdo_parser.cpp core_init.cpp core_conn.cpp core_stmt.cpp core_util.cpp core_stream.cpp" ) - CHECK_HEADER_ADD_INCLUDE('sql.h', 'CFLAGS_PDO_SQLSRV_ODBC'); - CHECK_HEADER_ADD_INCLUDE('sqlext.h', 'CFLAGS_PDO_SQLSRV_ODBC'); - ADD_FLAG( 'LDFLAGS_PDO_SQLSRV', '/NXCOMPAT /DYNAMICBASE' ); - ADD_FLAG( 'CFLAGS_PDO_SQLSRV', '/EHsc' ); - ADD_FLAG( 'CFLAGS_PDO_SQLSRV', '/GS' ); - ADD_EXTENSION_DEP('pdo_sqlsrv', 'pdo'); - } + EXTENSION("pdo_sqlsrv", "pdo_dbh.cpp pdo_init.cpp pdo_stmt.cpp pdo_util.cpp pdo_parser.cpp core_init.cpp core_conn.cpp core_stmt.cpp core_util.cpp core_stream.cpp" ) + CHECK_HEADER_ADD_INCLUDE('sql.h', 'CFLAGS_PDO_SQLSRV_ODBC'); + CHECK_HEADER_ADD_INCLUDE('sqlext.h', 'CFLAGS_PDO_SQLSRV_ODBC'); + ADD_FLAG( 'LDFLAGS_PDO_SQLSRV', '/NXCOMPAT /DYNAMICBASE' ); + ADD_FLAG( 'CFLAGS_PDO_SQLSRV', '/EHsc' ); + ADD_FLAG( 'CFLAGS_PDO_SQLSRV', '/GS' ); + ADD_EXTENSION_DEP('pdo_sqlsrv', 'pdo'); + } } diff --git a/pdo_sqlsrv/core_stmt.cpp b/pdo_sqlsrv/core_stmt.cpp index a0a96f71..4d250820 100644 --- a/pdo_sqlsrv/core_stmt.cpp +++ b/pdo_sqlsrv/core_stmt.cpp @@ -1618,7 +1618,18 @@ SQLSMALLINT default_c_type( sqlsrv_stmt* stmt, unsigned int paramno, zval const* switch( php_type ) { case IS_NULL: - sql_c_type = SQL_C_CHAR; + switch( encoding ) { + // The c type is set to match to the corresponding sql_type. For NULL cases, if the server type + // is a binary type, than the server expects the sql_type to be binary type as well, otherwise + // an error stating "Implicit conversion not allowed.." is thrown by the server. + // For all other server types, setting the sql_type to sql_char works fine. + case SQLSRV_ENCODING_BINARY: + sql_c_type = SQL_C_BINARY; + break; + default: + sql_c_type = SQL_C_CHAR; + break; + } break; case IS_BOOL: case IS_LONG: @@ -1670,7 +1681,18 @@ void default_sql_type( sqlsrv_stmt* stmt, unsigned int paramno, zval* param_z, S switch( php_type ) { case IS_NULL: - sql_type = SQL_CHAR; + switch( encoding ) { + // Use the encoding to guess whether the sql_type is binary type or char type. For NULL cases, + // if the server type is a binary type, than the server expects the sql_type to be binary type + // as well, otherwise an error stating "Implicit conversion not allowed.." is thrown by the + // server. For all other server types, setting the sql_type to sql_char works fine. + case SQLSRV_ENCODING_BINARY: + sql_type = SQL_BINARY; + break; + default: + sql_type = SQL_CHAR; + break; + } break; case IS_BOOL: case IS_LONG: @@ -1838,7 +1860,7 @@ void finalize_output_parameters( sqlsrv_stmt* stmt TSRMLS_DC ) if( output_param->encoding != SQLSRV_ENCODING_CHAR && output_param->encoding != SQLSRV_ENCODING_BINARY ) { bool converted = convert_string_from_utf16( output_param->encoding, &str, str_len ); - CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_OUTPUT_PARAM_ENCODING_TRANSLATE ) { + CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_OUTPUT_PARAM_ENCODING_TRANSLATE, get_last_error_message()) { throw core::CoreException(); } } diff --git a/pdo_sqlsrv/pdo_dbh.cpp b/pdo_sqlsrv/pdo_dbh.cpp index 9010ff4b..abc511ce 100644 --- a/pdo_sqlsrv/pdo_dbh.cpp +++ b/pdo_sqlsrv/pdo_dbh.cpp @@ -1113,8 +1113,8 @@ int pdo_sqlsrv_dbh_quote( pdo_dbh_t* dbh, const char* unquoted, int unquoted_len } } - *quoted_len = unquoted_len + 1 + quotes_needed; // include the NULL terminator in case it isn't included already - *quoted = reinterpret_cast( sqlsrv_malloc( *quoted_len )); + *quoted_len = unquoted_len + quotes_needed; // length returned to the caller should not account for null terminator. + *quoted = reinterpret_cast( sqlsrv_malloc( *quoted_len + 1 )); // include space for null terminator. unsigned int out_current = 0; // insert initial quote diff --git a/pdo_sqlsrv/version.h b/pdo_sqlsrv/version.h index cb85107e..6be3f9e7 100644 --- a/pdo_sqlsrv/version.h +++ b/pdo_sqlsrv/version.h @@ -18,9 +18,9 @@ // limitations under the License. //--------------------------------------------------------------------------------------------------------------------------------- -#define VER_FILEVERSION_STR "2.0.0.0" -#define _FILEVERSION 2,0,0,0 +#define VER_FILEVERSION_STR "2.0.0.200" +#define _FILEVERSION 2,0,0,200 #define SQLVERSION_MAJOR 2 #define SQLVERSION_MINOR 0 #define SQLVERSION_MMDD 0 -#define SQLVERSION_REVISION 0 +#define SQLVERSION_REVISION 200 diff --git a/sqlsrv/CREDITS b/sqlsrv/CREDITS index f083a7a0..c3489015 100644 --- a/sqlsrv/CREDITS +++ b/sqlsrv/CREDITS @@ -1 +1 @@ -Microsoft Drivers for PHP for SQL Server 2.0 +Microsoft Drivers for PHP for SQL Server 2.0 Cumulative Update 1 diff --git a/sqlsrv/config.w32 b/sqlsrv/config.w32 index b573ca81..3cb98510 100644 --- a/sqlsrv/config.w32 +++ b/sqlsrv/config.w32 @@ -22,15 +22,15 @@ ARG_ENABLE("sqlsrv", "enable MS SQL Server extension", "no"); if( PHP_SQLSRV != "no" ) { - if (CHECK_LIB("odbc32.lib", "sqlsrv") && CHECK_LIB("odbccp32.lib", "sqlsrv") && - CHECK_LIB("version.lib", "sqlsrv") && CHECK_LIB("psapi.lib", "sqlsrv")) { - - EXTENSION("sqlsrv", "conn.cpp init.cpp stmt.cpp util.cpp core_init.cpp core_conn.cpp core_stmt.cpp core_util.cpp core_stream.cpp" ) + if (CHECK_LIB("odbc32.lib", "sqlsrv") && CHECK_LIB("odbccp32.lib", "sqlsrv") && + CHECK_LIB("version.lib", "sqlsrv") && CHECK_LIB("psapi.lib", "sqlsrv")) { + + EXTENSION("sqlsrv", "conn.cpp init.cpp stmt.cpp util.cpp core_init.cpp core_conn.cpp core_stmt.cpp core_util.cpp core_stream.cpp" ) - CHECK_HEADER_ADD_INCLUDE('sql.h', 'CFLAGS_SQLSRV_ODBC'); - CHECK_HEADER_ADD_INCLUDE('sqlext.h', 'CFLAGS_SQLSRV_ODBC'); - ADD_FLAG( 'LDFLAGS_SQLSRV', '/NXCOMPAT /DYNAMICBASE' ); - ADD_FLAG( 'CFLAGS_SQLSRV', '/EHsc' ); - ADD_FLAG( 'CFLAGS_SQLSRV', '/GS' ); - } + CHECK_HEADER_ADD_INCLUDE('sql.h', 'CFLAGS_SQLSRV_ODBC'); + CHECK_HEADER_ADD_INCLUDE('sqlext.h', 'CFLAGS_SQLSRV_ODBC'); + ADD_FLAG( 'LDFLAGS_SQLSRV', '/NXCOMPAT /DYNAMICBASE' ); + ADD_FLAG( 'CFLAGS_SQLSRV', '/EHsc' ); + ADD_FLAG( 'CFLAGS_SQLSRV', '/GS' ); + } } diff --git a/sqlsrv/core_stmt.cpp b/sqlsrv/core_stmt.cpp index a0a96f71..4d250820 100644 --- a/sqlsrv/core_stmt.cpp +++ b/sqlsrv/core_stmt.cpp @@ -1618,7 +1618,18 @@ SQLSMALLINT default_c_type( sqlsrv_stmt* stmt, unsigned int paramno, zval const* switch( php_type ) { case IS_NULL: - sql_c_type = SQL_C_CHAR; + switch( encoding ) { + // The c type is set to match to the corresponding sql_type. For NULL cases, if the server type + // is a binary type, than the server expects the sql_type to be binary type as well, otherwise + // an error stating "Implicit conversion not allowed.." is thrown by the server. + // For all other server types, setting the sql_type to sql_char works fine. + case SQLSRV_ENCODING_BINARY: + sql_c_type = SQL_C_BINARY; + break; + default: + sql_c_type = SQL_C_CHAR; + break; + } break; case IS_BOOL: case IS_LONG: @@ -1670,7 +1681,18 @@ void default_sql_type( sqlsrv_stmt* stmt, unsigned int paramno, zval* param_z, S switch( php_type ) { case IS_NULL: - sql_type = SQL_CHAR; + switch( encoding ) { + // Use the encoding to guess whether the sql_type is binary type or char type. For NULL cases, + // if the server type is a binary type, than the server expects the sql_type to be binary type + // as well, otherwise an error stating "Implicit conversion not allowed.." is thrown by the + // server. For all other server types, setting the sql_type to sql_char works fine. + case SQLSRV_ENCODING_BINARY: + sql_type = SQL_BINARY; + break; + default: + sql_type = SQL_CHAR; + break; + } break; case IS_BOOL: case IS_LONG: @@ -1838,7 +1860,7 @@ void finalize_output_parameters( sqlsrv_stmt* stmt TSRMLS_DC ) if( output_param->encoding != SQLSRV_ENCODING_CHAR && output_param->encoding != SQLSRV_ENCODING_BINARY ) { bool converted = convert_string_from_utf16( output_param->encoding, &str, str_len ); - CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_OUTPUT_PARAM_ENCODING_TRANSLATE ) { + CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_OUTPUT_PARAM_ENCODING_TRANSLATE, get_last_error_message()) { throw core::CoreException(); } } diff --git a/sqlsrv/stmt.cpp b/sqlsrv/stmt.cpp index 32f5e2a6..5ef7024f 100644 --- a/sqlsrv/stmt.cpp +++ b/sqlsrv/stmt.cpp @@ -1815,13 +1815,13 @@ void fetch_fields_common( __inout ss_sqlsrv_stmt* stmt, int fetch_type, __out zv if(( fetch_type & SQLSRV_FETCH_ASSOC ) && stmt->fetch_field_names == NULL ) { SQLSMALLINT field_name_len; - char field_name_temp[ SQL_MAX_COLUMN_NAME_LEN ]; + char field_name_temp[ SS_MAXCOLNAMELEN+1 ]; sqlsrv_malloc_auto_ptr field_names; field_names = static_cast( sqlsrv_malloc( num_cols * sizeof( sqlsrv_fetch_field_name ))); for( int i = 0; i < num_cols; ++i ) { - core::SQLColAttribute( stmt, i + 1, SQL_DESC_NAME, field_name_temp, SQL_MAX_COLUMN_NAME_LEN, &field_name_len, NULL + core::SQLColAttribute( stmt, i + 1, SQL_DESC_NAME, field_name_temp, SS_MAXCOLNAMELEN+1, &field_name_len, NULL TSRMLS_CC ); field_names[ i ].name = static_cast( sqlsrv_malloc( field_name_len + 1 )); memcpy( (void*) field_names[ i ].name, field_name_temp, field_name_len ); diff --git a/sqlsrv/version.h b/sqlsrv/version.h index cb85107e..6be3f9e7 100644 --- a/sqlsrv/version.h +++ b/sqlsrv/version.h @@ -18,9 +18,9 @@ // limitations under the License. //--------------------------------------------------------------------------------------------------------------------------------- -#define VER_FILEVERSION_STR "2.0.0.0" -#define _FILEVERSION 2,0,0,0 +#define VER_FILEVERSION_STR "2.0.0.200" +#define _FILEVERSION 2,0,0,200 #define SQLVERSION_MAJOR 2 #define SQLVERSION_MINOR 0 #define SQLVERSION_MMDD 0 -#define SQLVERSION_REVISION 0 +#define SQLVERSION_REVISION 200