rename stmt_option_scrollable to driver specific names and put get_error_message into namespace

This commit is contained in:
v-kaywon 2017-03-21 15:28:13 -07:00
parent 7434d06507
commit 06a343f611
8 changed files with 38 additions and 34 deletions

View file

@ -76,7 +76,7 @@ enum PDO_STMT_OPTIONS {
const stmt_option PDO_STMT_OPTS[] = { const stmt_option PDO_STMT_OPTS[] = {
{ NULL, 0, SQLSRV_STMT_OPTION_QUERY_TIMEOUT, std::unique_ptr<stmt_option_query_timeout>( new stmt_option_query_timeout ) }, { NULL, 0, SQLSRV_STMT_OPTION_QUERY_TIMEOUT, std::unique_ptr<stmt_option_query_timeout>( new stmt_option_query_timeout ) },
{ NULL, 0, SQLSRV_STMT_OPTION_SCROLLABLE, std::unique_ptr<stmt_option_scrollable>( new stmt_option_scrollable ) }, { NULL, 0, SQLSRV_STMT_OPTION_SCROLLABLE, std::unique_ptr<stmt_option_pdo_scrollable>( new stmt_option_pdo_scrollable ) },
{ NULL, 0, PDO_STMT_OPTION_ENCODING, std::unique_ptr<stmt_option_encoding>( new stmt_option_encoding ) }, { NULL, 0, PDO_STMT_OPTION_ENCODING, std::unique_ptr<stmt_option_encoding>( new stmt_option_encoding ) },
{ NULL, 0, PDO_STMT_OPTION_DIRECT_QUERY, std::unique_ptr<stmt_option_direct_query>( new stmt_option_direct_query ) }, { NULL, 0, PDO_STMT_OPTION_DIRECT_QUERY, std::unique_ptr<stmt_option_direct_query>( new stmt_option_direct_query ) },
{ NULL, 0, PDO_STMT_OPTION_CURSOR_SCROLL_TYPE, std::unique_ptr<stmt_option_cursor_scroll_type>( new stmt_option_cursor_scroll_type ) }, { NULL, 0, PDO_STMT_OPTION_CURSOR_SCROLL_TYPE, std::unique_ptr<stmt_option_cursor_scroll_type>( new stmt_option_cursor_scroll_type ) },

View file

@ -305,7 +305,7 @@ struct pdo_stmt_methods pdo_sqlsrv_stmt_methods = {
}; };
void stmt_option_scrollable:: operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC ) void stmt_option_pdo_scrollable:: operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC )
{ {
set_stmt_cursors( stmt, value_z TSRMLS_CC ); set_stmt_cursors( stmt, value_z TSRMLS_CC );
} }

View file

@ -42,6 +42,9 @@ char log_msg[ LOG_MSG_SIZE ];
// internal error that says that FormatMessage failed // internal error that says that FormatMessage failed
SQLCHAR INTERNAL_FORMAT_ERROR[] = "An internal error occurred. FormatMessage failed writing an error message."; SQLCHAR INTERNAL_FORMAT_ERROR[] = "An internal error occurred. FormatMessage failed writing an error message.";
// Returns a sqlsrv_error for a given error code.
sqlsrv_error_const* get_error_message(unsigned int sqlsrv_error_code);
// build the object and throw the PDO exception // build the object and throw the PDO exception
void pdo_sqlsrv_throw_exception( sqlsrv_error_const* error TSRMLS_DC ); void pdo_sqlsrv_throw_exception( sqlsrv_error_const* error TSRMLS_DC );
@ -373,20 +376,6 @@ pdo_error PDO_ERRORS[] = {
{ UINT_MAX, {} } { UINT_MAX, {} }
}; };
// Returns a sqlsrv_error for a given error code.
sqlsrv_error_const* get_error_message(unsigned int sqlsrv_error_code) {
sqlsrv_error_const *error_message = NULL;
int zr = (error_message = reinterpret_cast<sqlsrv_error_const*>(zend_hash_index_find_ptr(g_pdo_errors_ht, sqlsrv_error_code))) != NULL ? SUCCESS : FAILURE;
if( zr == FAILURE ) {
DIE( "get_error_message: zend_hash_index_find returned failure for sqlsrv_error_code = %1!d!", sqlsrv_error_code );
}
SQLSRV_ASSERT( error_message != NULL, "get_error_message: error_message was null");
return error_message;
}
// PDO error handler for the environment context. // PDO error handler for the environment context.
bool pdo_sqlsrv_handle_env_error( sqlsrv_context& ctx, unsigned int sqlsrv_error_code, bool warning TSRMLS_DC, bool pdo_sqlsrv_handle_env_error( sqlsrv_context& ctx, unsigned int sqlsrv_error_code, bool warning TSRMLS_DC,
va_list* print_args ) va_list* print_args )
@ -561,6 +550,19 @@ void pdo_sqlsrv_log( unsigned int severity TSRMLS_DC, const char* msg, va_list*
namespace { namespace {
sqlsrv_error_const* get_error_message(unsigned int sqlsrv_error_code) {
sqlsrv_error_const *error_message = NULL;
int zr = (error_message = reinterpret_cast<sqlsrv_error_const*>(zend_hash_index_find_ptr(g_pdo_errors_ht, sqlsrv_error_code))) != NULL ? SUCCESS : FAILURE;
if (zr == FAILURE) {
DIE("get_error_message: zend_hash_index_find returned failure for sqlsrv_error_code = %1!d!", sqlsrv_error_code);
}
SQLSRV_ASSERT(error_message != NULL, "get_error_message: error_message was null");
return error_message;
}
void pdo_sqlsrv_throw_exception( sqlsrv_error_const* error TSRMLS_DC ) void pdo_sqlsrv_throw_exception( sqlsrv_error_const* error TSRMLS_DC )
{ {
zval ex_obj; zval ex_obj;

View file

@ -194,7 +194,7 @@ struct stmt_option_encoding : public stmt_option_functor {
virtual void operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC ); virtual void operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC );
}; };
struct stmt_option_scrollable : public stmt_option_functor { struct stmt_option_pdo_scrollable : public stmt_option_functor {
virtual void operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC ); virtual void operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC );
}; };

View file

@ -210,7 +210,7 @@ const stmt_option SS_STMT_OPTS[] = {
SSStmtOptionNames::SCROLLABLE, SSStmtOptionNames::SCROLLABLE,
sizeof( SSStmtOptionNames::SCROLLABLE ), sizeof( SSStmtOptionNames::SCROLLABLE ),
SQLSRV_STMT_OPTION_SCROLLABLE, SQLSRV_STMT_OPTION_SCROLLABLE,
std::unique_ptr<stmt_option_scrollable>( new stmt_option_scrollable ) std::unique_ptr<stmt_option_ss_scrollable>( new stmt_option_ss_scrollable )
}, },
{ {
SSStmtOptionNames::CLIENT_BUFFER_MAX_SIZE, SSStmtOptionNames::CLIENT_BUFFER_MAX_SIZE,

View file

@ -160,7 +160,7 @@ struct sqlsrv_fetch_field_name {
unsigned int len; unsigned int len;
}; };
struct stmt_option_scrollable : public stmt_option_functor { struct stmt_option_ss_scrollable : public stmt_option_functor {
virtual void operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC ); virtual void operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC );
}; };

View file

@ -1444,7 +1444,7 @@ PHP_FUNCTION( sqlsrv_free_stmt )
} }
} }
void stmt_option_scrollable:: operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC ) void stmt_option_ss_scrollable:: operator()( sqlsrv_stmt* stmt, stmt_option const* /*opt*/, zval* value_z TSRMLS_DC )
{ {
CHECK_CUSTOM_ERROR(( Z_TYPE_P( value_z ) != IS_STRING ), stmt, SQLSRV_ERROR_INVALID_OPTION_SCROLLABLE ) { CHECK_CUSTOM_ERROR(( Z_TYPE_P( value_z ) != IS_STRING ), stmt, SQLSRV_ERROR_INVALID_OPTION_SCROLLABLE ) {
throw ss::SSException(); throw ss::SSException();

View file

@ -34,6 +34,8 @@ char log_msg[ LOG_MSG_SIZE ];
SQLCHAR INTERNAL_FORMAT_ERROR[] = "An internal error occurred. FormatMessage failed writing an error message."; SQLCHAR INTERNAL_FORMAT_ERROR[] = "An internal error occurred. FormatMessage failed writing an error message.";
// *** internal functions *** // *** internal functions ***
sqlsrv_error_const* get_error_message(unsigned int sqlsrv_error_code);
void copy_error_to_zval( zval* error_z, sqlsrv_error_const* error, zval* reported_chain, zval* ignored_chain, void copy_error_to_zval( zval* error_z, sqlsrv_error_const* error, zval* reported_chain, zval* ignored_chain,
bool warning TSRMLS_DC ); bool warning TSRMLS_DC );
bool ignore_warning( char* sql_state, int native_code TSRMLS_DC ); bool ignore_warning( char* sql_state, int native_code TSRMLS_DC );
@ -375,20 +377,6 @@ ss_error SS_ERRORS[] = {
{ UINT_MAX, {} } { UINT_MAX, {} }
}; };
sqlsrv_error_const* get_error_message( unsigned int sqlsrv_error_code ) {
sqlsrv_error_const *error_message = NULL;
int zr = (error_message = reinterpret_cast<sqlsrv_error_const*>(zend_hash_index_find_ptr( g_ss_errors_ht, sqlsrv_error_code))) != NULL ? SUCCESS : FAILURE;
if( zr == FAILURE ) {
DIE( "get_error_message: zend_hash_index_find returned failure for sqlsrv_error_code = %1!d!", sqlsrv_error_code );
}
SQLSRV_ASSERT( error_message != NULL, "get_error_message: error_message was null");
return error_message;
}
// Formats an error message and finally writes it to the php log. // Formats an error message and finally writes it to the php log.
void ss_sqlsrv_log( unsigned int severity TSRMLS_DC, const char* msg, va_list* print_args ) void ss_sqlsrv_log( unsigned int severity TSRMLS_DC, const char* msg, va_list* print_args )
{ {
@ -692,6 +680,20 @@ PHP_FUNCTION( sqlsrv_get_config )
namespace { namespace {
sqlsrv_error_const* get_error_message(unsigned int sqlsrv_error_code) {
sqlsrv_error_const *error_message = NULL;
int zr = (error_message = reinterpret_cast<sqlsrv_error_const*>(zend_hash_index_find_ptr(g_ss_errors_ht, sqlsrv_error_code))) != NULL ? SUCCESS : FAILURE;
if (zr == FAILURE) {
DIE("get_error_message: zend_hash_index_find returned failure for sqlsrv_error_code = %1!d!", sqlsrv_error_code);
}
SQLSRV_ASSERT(error_message != NULL, "get_error_message: error_message was null");
return error_message;
}
void copy_error_to_zval( zval* error_z, sqlsrv_error_const* error, zval* reported_chain, zval* ignored_chain, void copy_error_to_zval( zval* error_z, sqlsrv_error_const* error, zval* reported_chain, zval* ignored_chain,
bool warning TSRMLS_DC ) bool warning TSRMLS_DC )
{ {