From c62bf03a62a2db1089ad843567447c3ab36feb56 Mon Sep 17 00:00:00 2001 From: icosahedron Date: Thu, 16 Oct 2008 21:59:02 +0000 Subject: [PATCH] SQL Server 2005 Driver for PHP October 2008 Cumulative Update. Please see README.txt for information about changes made for this update. --- README.TXT | 24 ++++++++++++++++++------ conn.cpp | 35 +++++++++++++---------------------- init.cpp | 6 +++--- php_sqlsrv.h | 4 ++-- stmt.cpp | 40 ++++++++++++++++++++++++---------------- stream.cpp | 10 +++++----- util.cpp | 14 +++++++------- version.h | 6 +++--- 8 files changed, 75 insertions(+), 64 deletions(-) diff --git a/README.TXT b/README.TXT index 6136b7f3..1d86a6db 100644 --- a/README.TXT +++ b/README.TXT @@ -1,18 +1,24 @@ -*Notes on compiling SQL Server 2005 Driver for PHP* +* Notes about changes to the SQL Server 2005 Driver for PHP October 2008 Cumulative Update (CU) * -Prerequisites: You must first be able to build PHP not including -this extension. For help on doing so, see the official PHP website, -http://php.net. +For details about the changes included in this CU, please see our blog at +http://blogs.msdn.com/sqlphp or see the SQLServerDriverForPHP_Readme.htm +file that is part of the download package. -To compile SQL Server 2005 Driver for PHP: +* Notes about compiling the SQL Server 2005 Driver for PHP October 2008 CU * + +Prerequisites: You must first be able to build PHP without including +the SQL Server 2005 Driver for PHP extension. For help with doing this, see +the official PHP website, http://php.net. + +To compile the SQL Server 2005 Driver for PHP: 1) Copy the source code into the ext\sqlsrv directory. 2) run buildconf.bat 3) run "cscript configure.js --enable-sqlsrv=shared " to -generate the makefile. run "cscript configure.js --help" to see what other +generate the makefile. Run "cscript configure.js --help" to see what other options are available. It is possible (and even probable) that other extensions will have to be disabled or enabled for the compile to succeed. Search live.com for configurations that have worked for other people. @@ -32,3 +38,9 @@ using the Visual C++ 2005 Express and Visual C++ 2008 Standard compilers. This software is released under the Microsoft Public License. A copy of the license agreement may be found online at http://www.codeplex.com/SQL2K5PHP/license. + +* Note about version.h * + +The version numbers in version.h in the source do not match the version numbers +in the supported PHP extension and have not been updated for this CU in the +published source code. diff --git a/conn.cpp b/conn.cpp index d7f60ee5..1e3fed2d 100644 --- a/conn.cpp +++ b/conn.cpp @@ -29,10 +29,6 @@ int current_log_subsystem = LOG_CONN; // an arbitrary figure that should be large enough for most connection strings. const int DEFAULT_CONN_STR_LEN = 2048; -// the largest packet size that can be sent with the default options that we use -// without causing a warning to happen at login time. If the warning did occur, -// it would cause an error when 'WarningsReturnAsErrors' is set to true. -const int DEFAULT_PACKET_SIZE = 32564; // PHP streams generally return no more than 8k. const int PHP_STREAM_BUFFER_SIZE = 8192; // connection timeout string @@ -176,20 +172,15 @@ PHP_FUNCTION( sqlsrv_connect ) handle_warning( &SQLSRV_G( henv_context )->ctx, LOG_CONN, _FN_, NULL TSRMLS_CC ); } - // set the packet size to ~32k - r = SQLSetConnectAttr( conn->ctx.handle, SQL_ATTR_PACKET_SIZE, reinterpret_cast( DEFAULT_PACKET_SIZE ), SQL_IS_UINTEGER ); - CHECK_SQL_ERROR( r, conn, _FN_, NULL, SQLFreeHandle( conn->ctx.handle_type, conn->ctx.handle ); RETURN_FALSE; ); - CHECK_SQL_WARNING( r ,conn, _FN_, NULL ); - - try { + try { r = build_connection_string_and_set_conn_attr( conn, server, options_z, conn_str TSRMLS_CC ); CHECK_SQL_ERROR( r, SQLSRV_G( henv_context ), _FN_, NULL, memset( const_cast( conn_str.c_str()), 0, conn_str.size() ); conn_str.clear(); - SQLFreeHandle( conn->ctx.handle_type, conn->ctx.handle ); - conn->ctx.handle = NULL; - RETURN_FALSE ); + SQLFreeHandle( conn->ctx.handle_type, conn->ctx.handle ); + conn->ctx.handle = NULL; + RETURN_FALSE ); } catch( std::bad_alloc& ex ) { memset( const_cast( conn_str.c_str()), 0, conn_str.size() ); @@ -212,15 +203,15 @@ PHP_FUNCTION( sqlsrv_connect ) conn->ctx.handle = SQL_NULL_HANDLE; RETURN_FALSE; } - - SQLSRV_STATIC_ASSERT( sizeof( char ) == sizeof( SQLCHAR )); // make sure that cast below is valid - r = SQLDriverConnect( conn->ctx.handle, NULL, reinterpret_cast( const_cast( conn_str.c_str() )), - static_cast( conn_str.length() ), NULL, - 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); - // Would rather use std::fill here, but that gives a warning about not being able to inline + + SQLSRV_STATIC_ASSERT( sizeof( char ) == sizeof( SQLCHAR )); // make sure that cast below is valid + r = SQLDriverConnect( conn->ctx.handle, NULL, reinterpret_cast( const_cast( conn_str.c_str() )), + static_cast( conn_str.length() ), NULL, + 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); + // Would rather use std::fill here, but that gives a warning about not being able to inline // the iterator functions, so we use this instead. - memset( const_cast( conn_str.c_str()), 0, conn_str.size() ); - conn_str.clear(); + memset( const_cast( conn_str.c_str()), 0, conn_str.size() ); + conn_str.clear(); CHECK_SQL_ERROR( r, conn, _FN_, NULL, SQLFreeHandle( conn->ctx.handle_type, conn->ctx.handle ); conn->ctx.handle = SQL_NULL_HANDLE; RETURN_FALSE ); @@ -890,7 +881,7 @@ struct _attr_return { // or set to NO_ATTRIBUTE if it's not a connection attribute int attr; // the value of the attribute if it's a connection attribute rather than a connection string keyword - int value; + int value; char* str_value; // connection string keyword if that's what it is unsigned int str_len; // length of the connection string keyword (save ourselves a strlen) bool add; // see build_connect_string_and_attr for this field's use diff --git a/init.cpp b/init.cpp index 0a3ae0e3..58c9f9a2 100644 --- a/init.cpp +++ b/init.cpp @@ -210,15 +210,15 @@ zend_module_entry g_sqlsrv_module_entry = "sqlsrv", sqlsrv_functions, // exported function table // initialization and shutdown functions - PHP_MINIT(sqlsrv), + PHP_MINIT(sqlsrv), PHP_MSHUTDOWN(sqlsrv), PHP_RINIT(sqlsrv), PHP_RSHUTDOWN(sqlsrv), - PHP_MINFO(sqlsrv), + PHP_MINFO(sqlsrv), // version of the extension. Matches the version resource of the extension dll VER_FILEVERSION_STR, PHP_MODULE_GLOBALS(sqlsrv), - NULL, + NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES_EX diff --git a/php_sqlsrv.h b/php_sqlsrv.h index fcb466a1..593d470a 100644 --- a/php_sqlsrv.h +++ b/php_sqlsrv.h @@ -457,7 +457,7 @@ struct sqlsrv_error { char const* sqlstate; char const* native_message; int native_code; - bool format; + bool format; }; // defintions for PHP specific errors returned by sqlsrv @@ -629,7 +629,7 @@ inline bool is_truncated_warning( SQLCHAR* state ) // generic functions used to validate parameters to a PHP function. -// Register an invalid parameter error and returns NULL when parameters don't match the spec given. +// Register an invalid parameter error and returns NULL when parameters don't match the spec given. // Each function is nearly identical, except the number of parameters each accepts. // We do this since template functions can't be variadic. diff --git a/stmt.cpp b/stmt.cpp index 792ec00c..5f096b2e 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -1006,12 +1006,12 @@ bool sqlsrv_stmt_common_execute( sqlsrv_stmt* stmt, const SQLCHAR* sql_string, i column_size, decimal_digits TSRMLS_CC ); // an error occurred, so return false if( param_z == NULL ) { - return false; - } - } + return false; + } + } // otherwise use the defaults else { - + bool success = determine_param_defaults( stmt, _FN_, param_z, i, php_type, direction, sql_type, sql_c_type, column_size, decimal_digits TSRMLS_CC ); if( !success ) { @@ -1138,18 +1138,26 @@ bool sqlsrv_stmt_common_execute( sqlsrv_stmt* stmt, const SQLCHAR* sql_string, i if( sql_string != NULL ) DIE( "sqlsrv_stmt_common_execute: sql_string must be NULL when direct = false"); r = SQLExecute( stmt->ctx.handle ); } - if( r != SQL_NEED_DATA ) { + + // if stream parameters were bound + if( r == SQL_NEED_DATA ) { + + // if they are to be sent at execute time, then send them now. + if( stmt->send_at_exec == true ) { + + zval return_value; + while( send_stream_packet( stmt, &return_value, _FN_ TSRMLS_CC )) { } + if( Z_TYPE( return_value ) != IS_NULL ) { + return false; + } + } + } + // if a result set was generated, check for errors. Otherwise, it completed successfully but no data was + // generated. + else if( r != SQL_NO_DATA ) { CHECK_SQL_ERROR( r, stmt, _FN_, NULL, SQLFreeStmt( stmt->ctx.handle, SQL_RESET_PARAMS ); return false; ); CHECK_SQL_WARNING( r, stmt, _FN_, NULL ); } - else if( stmt->send_at_exec == true ) { - - zval return_value; - while( send_stream_packet( stmt, &return_value, _FN_ TSRMLS_CC )) { } - if( Z_TYPE( return_value ) != IS_NULL ) { - return false; - } - } // false means to not release the datetime buffers we just allocated. stmt->new_result_set( false ); @@ -1315,7 +1323,7 @@ bool check_for_next_stream_parameter( __inout sqlsrv_stmt* stmt, __out zval* ret stmt->current_parameter_read = 0; } // otherwise if it wasn't an error, we've exhausted the bound parameters, so return that we're done - else if( SQL_SUCCEEDED( r )) { + else if( SQL_SUCCEEDED( r ) || r == SQL_NO_DATA ) { CHECK_SQL_WARNING( r, stmt, "sqlsrv_send_stream_data", NULL ); RETVAL_NULL(); return false; @@ -1969,8 +1977,8 @@ void get_field_as_string( sqlsrv_stmt const* s, SQLSMALLINT c_type, SQLUSMALLINT } } else { - CHECK_SQL_ERROR( r, s, _FN_, NULL, efree( field ); RETURN_FALSE; ); - } + CHECK_SQL_ERROR( r, s, _FN_, NULL, efree( field ); RETURN_FALSE; ); + } } else if( sql_display_size >= 1 && sql_display_size <= SQL_SERVER_2005_MAX_FIELD_SIZE ) { // only allow binary retrievals for char and binary types. All others get a char type automatically. diff --git a/stream.cpp b/stream.cpp index 6d94be22..0f8fa5d6 100644 --- a/stream.cpp +++ b/stream.cpp @@ -127,10 +127,10 @@ OACR_WARNING_DISABLE( UNANNOTATED_BUFFER, "STREAMS_DC is a Zend macro that evals // return value. There is only one valid way to open a stream, using sqlsrv_get_field on // certain field types. A sqlsrv stream may only be opened in read mode. static php_stream* sqlsrv_stream_opener( php_stream_wrapper* wrapper, - __in char*, __in char* mode, - int options, __in char **, - php_stream_context* - STREAMS_DC TSRMLS_DC ) + __in char*, __in char* mode, + int options, __in char **, + php_stream_context* + STREAMS_DC TSRMLS_DC ) { #if ZEND_DEBUG SQLSRV_UNUSED( __zend_orig_lineno ); @@ -150,7 +150,7 @@ static php_stream* sqlsrv_stream_opener( php_stream_wrapper* wrapper, php_stream_wrapper_log_error( wrapper, options TSRMLS_CC, "Invalid option: no options except REPORT_ERRORS may be specified with a sqlsrv stream" ); return NULL; } - + // allocate the stream from PHP php_stream* php_str = php_stream_alloc( &sqlsrv_stream_ops, ss, 0, mode ); if( php_str != NULL ) { diff --git a/util.cpp b/util.cpp index c2eda036..8d161cdc 100644 --- a/util.cpp +++ b/util.cpp @@ -242,7 +242,7 @@ PHP_FUNCTION( sqlsrv_errors ) zend_hash_destroy( Z_ARRVAL_P( both_z )); RETURN_FALSE; } - + if( Z_TYPE_P( SQLSRV_G( warnings )) == IS_ARRAY && !sqlsrv_merge_zend_hash( both_z, SQLSRV_G( warnings ) TSRMLS_CC )) { zend_hash_destroy( Z_ARRVAL_P( both_z )); @@ -573,7 +573,7 @@ bool handle_errors_and_warnings( sqlsrv_context const* ctx, zval** reported_chai int zr = SUCCESS; int reported_before = 0; int ignored_before = 0; - + LOG( SEV_NOTICE, LOG_UTIL, "handle_errors_and_warnings: entering" ); // create an array of arrays @@ -592,13 +592,13 @@ bool handle_errors_and_warnings( sqlsrv_context const* ctx, zval** reported_chai if( ignored_chain != NULL ) { if( Z_TYPE_P( *ignored_chain ) == IS_NULL ) { - ignored_chain_was_null = true; + ignored_chain_was_null = true; ignored_before = 0; - zr = array_init( *ignored_chain ); - if( zr == FAILURE ) { - DIE( "Fatal error in handle_errors_and_warnings" ); + zr = array_init( *ignored_chain ); + if( zr == FAILURE ) { + DIE( "Fatal error in handle_errors_and_warnings" ); + } } - } else { ignored_before = zend_hash_num_elements( Z_ARRVAL_PP( ignored_chain )); } diff --git a/version.h b/version.h index fde628c5..63678457 100644 --- a/version.h +++ b/version.h @@ -11,9 +11,9 @@ // may be found online at http://www.codeplex.com/SQL2K5PHP/license. //---------------------------------------------------------------------------------------------------------------------------------- -#define VER_FILEVERSION_STR "1.0.0.0" -#define _FILEVERSION 1,0,0,0 +#define VER_FILEVERSION_STR "1.0.1015.0" +#define _FILEVERSION 1,0,1015,0 #define SQLVERSION_MAJOR 1 #define SQLVERSION_MINOR 0 -#define SQLVERSION_MMDD 0 +#define SQLVERSION_MMDD 1015 #define SQLVERSION_REVISION 0