Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename stmt_option_scrollable to driver specific names #335

Merged
merged 4 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/pdo_sqlsrv/pdo_dbh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ enum PDO_STMT_OPTIONS {
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_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_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 ) },
Expand Down
2 changes: 1 addition & 1 deletion source/pdo_sqlsrv/pdo_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
32 changes: 18 additions & 14 deletions source/pdo_sqlsrv/pdo_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ char log_msg[ LOG_MSG_SIZE ];
// internal error that says that FormatMessage failed
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
void pdo_sqlsrv_throw_exception( sqlsrv_error_const* error TSRMLS_DC );

Expand Down Expand Up @@ -373,20 +376,6 @@ pdo_error PDO_ERRORS[] = {
{ 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.
bool pdo_sqlsrv_handle_env_error( sqlsrv_context& ctx, unsigned int sqlsrv_error_code, bool warning TSRMLS_DC,
va_list* print_args )
Expand Down Expand Up @@ -561,6 +550,21 @@ void pdo_sqlsrv_log( unsigned int severity TSRMLS_DC, const char* msg, va_list*

namespace {

// Workaround for name collision problem between the SQLSRV and PDO_SQLSRV drivers on Mac
// Place get_error_message into the anonymous namespace in pdo_util.cpp
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 )
{
zval ex_obj;
Expand Down
2 changes: 1 addition & 1 deletion source/pdo_sqlsrv/php_pdo_sqlsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};

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 );
};
Expand Down
2 changes: 1 addition & 1 deletion source/sqlsrv/conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const stmt_option SS_STMT_OPTS[] = {
SSStmtOptionNames::SCROLLABLE,
sizeof( SSStmtOptionNames::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,
Expand Down
2 changes: 1 addition & 1 deletion source/sqlsrv/php_sqlsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct sqlsrv_fetch_field_name {
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 );
};
Expand Down
2 changes: 1 addition & 1 deletion source/sqlsrv/stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
throw ss::SSException();
Expand Down
32 changes: 18 additions & 14 deletions source/sqlsrv/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ char log_msg[ LOG_MSG_SIZE ];
SQLCHAR INTERNAL_FORMAT_ERROR[] = "An internal error occurred. FormatMessage failed writing an error message.";

// *** 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,
bool warning TSRMLS_DC );
bool ignore_warning( char* sql_state, int native_code TSRMLS_DC );
Expand Down Expand Up @@ -375,20 +377,6 @@ ss_error SS_ERRORS[] = {
{ 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.
void ss_sqlsrv_log( unsigned int severity TSRMLS_DC, const char* msg, va_list* print_args )
{
Expand Down Expand Up @@ -692,6 +680,22 @@ PHP_FUNCTION( sqlsrv_get_config )

namespace {

// Workaround for name collision problem between the SQLSRV and PDO_SQLSRV drivers on Mac
// Place get_error_message into the anonymous namespace in util.cpp
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,
bool warning TSRMLS_DC )
{
Expand Down