Skip to content

Commit

Permalink
Merge c161887 into 2dbbdc1
Browse files Browse the repository at this point in the history
  • Loading branch information
v-dareck committed Jan 9, 2017
2 parents 2dbbdc1 + c161887 commit 36ed86f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
5 changes: 3 additions & 2 deletions source/pdo_sqlsrv/pdo_dbh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1355,8 +1355,9 @@ void add_stmt_option_key( sqlsrv_context& ctx, size_t key, HashTable* options_ht
option_key = PDO_STMT_OPTION_EMULATE_PREPARES;
break;

case SQLSRV_ATTR_FETCHES_NUMERIC_TYPE:
option_key = PDO_STMT_OPTION_FETCHES_NUMERIC_TYPE;
case SQLSRV_ATTR_FETCHES_NUMERIC_TYPE:
option_key = PDO_STMT_OPTION_FETCHES_NUMERIC_TYPE;
break;

default:
CHECK_CUSTOM_ERROR( true, ctx, PDO_SQLSRV_ERROR_INVALID_STMT_OPTION ) {
Expand Down
15 changes: 1 addition & 14 deletions source/pdo_sqlsrv/pdo_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,16 @@ PHP_MINIT_FUNCTION(pdo_sqlsrv)
DWORD needed = 0;
#ifndef __linux__
HANDLE hprocess = GetCurrentProcess();
#endif
HMODULE pdo_hmodule;

#ifndef __linux__
pdo_hmodule = GetModuleHandle( PDO_DLL_NAME );
#else
pdo_hmodule = dlopen( PDO_DLL_NAME, RTLD_LAZY );
#endif
if( pdo_hmodule == 0 ) {
#ifndef __linux__
if( pdo_hmodule == 0 ) {
pdo_hmodule = GetModuleHandle( PHP_DLL_NAME );
#else
pdo_hmodule = dlopen( PHP_DLL_NAME, RTLD_LAZY );
#endif
#ifndef __linux__
if( pdo_hmodule == NULL ) {
LOG( SEV_ERROR, "Failed to get PHP module handle.");
return FAILURE;
}
#endif
}

#ifndef __linux__
pdo_register_driver = reinterpret_cast<pdo_register_func>( GetProcAddress( pdo_hmodule, "php_pdo_register_driver" ));
if( pdo_register_driver == NULL ) {
LOG( SEV_ERROR, "Failed to register driver." );
Expand Down
2 changes: 2 additions & 0 deletions source/pdo_sqlsrv/pdo_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ conn_string_parser:: conn_string_parser( sqlsrv_context& ctx, const char* dsn, i
this->conn_options_ht = conn_options_ht;
this->pos = -1;
this->ctx = &ctx;
this->current_key = 0;
this->current_key_name = NULL;
}

// Move to the next character
Expand Down
21 changes: 14 additions & 7 deletions source/shared/core_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ SQLRETURN number_to_string( Number *number_data, _Out_ void* buffer, SQLLEN buff
std::mbstate_t mbs = std::mbstate_t();

int len = mbrtoc16( &ch16, &mb, str_num_end - str_num_ptr, &mbs );
if ( len > 0 )
if ( len > 0 || len == -3 )
{
str.append( std::u16string( &ch16, len ) );
str_num_ptr += len;
//str.append( std::u16string( &ch16, len ) );
str.push_back( ch16 );
if ( len > 0 )
{
str_num_ptr += len;
}
}
}

Expand Down Expand Up @@ -386,7 +390,8 @@ sqlsrv_buffered_result_set::sqlsrv_buffered_result_set( sqlsrv_stmt* stmt TSRMLS
meta(NULL),
current(0),
last_field_index(-1),
read_so_far(0)
read_so_far(0),
temp_length(0)
{
// 10 is an arbitrary number for now for the initial size of the cache
ALLOC_HASHTABLE( cache );
Expand Down Expand Up @@ -778,10 +783,12 @@ SQLRETURN sqlsrv_buffered_result_set::get_data( SQLUSMALLINT field_index, SQLSMA
return SQL_SUCCESS;
}

conv_matrix_t::const_iterator conv_iter = conv_matrix.find(meta[field_index].c_type);

// check to make sure the conversion type is valid
if( conv_matrix.find( meta[ field_index ].c_type ) == conv_matrix.end() ||
conv_matrix.find( meta[ field_index ].c_type )->second.find( target_type ) ==
conv_matrix.find( meta[ field_index ].c_type )->second.end() ) {
if( conv_iter == conv_matrix.end() ||
conv_iter->second.find( target_type ) ==
conv_iter->second.end() ) {

last_error = new (sqlsrv_malloc( sizeof( sqlsrv_error )))
sqlsrv_error( (SQLCHAR*) "07006",
Expand Down
13 changes: 9 additions & 4 deletions source/shared/core_sqlsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,10 @@ class sqlsrv_context {
{
}

virtual ~sqlsrv_context()
{
}

void set_func( const char* f )
{
name_ = f;
Expand Down Expand Up @@ -1026,6 +1030,8 @@ struct sqlsrv_conn : public sqlsrv_context {
sqlsrv_conn( SQLHANDLE h, error_callback e, void* drv, SQLSRV_ENCODING encoding TSRMLS_DC ) :
sqlsrv_context( h, SQL_HANDLE_DBC, e, drv, encoding )
{
server_version = SERVER_VERSION_UNKNOWN;
driver_version = ODBC_DRIVER_13;
}

// sqlsrv_conn has no destructor since its allocated using placement new, which requires that the destructor be
Expand Down Expand Up @@ -1199,14 +1205,13 @@ struct sqlsrv_stream {
SQLUSMALLINT field_index;
SQLSMALLINT sql_type;
sqlsrv_stmt* stmt;
std::size_t stmt_index;

sqlsrv_stream( zval* str_z, SQLSRV_ENCODING enc ) :
stream_z( str_z ), encoding( enc )
stream_z( str_z ), encoding( enc ), field_index( 0 ), sql_type( SQL_UNKNOWN_TYPE ), stmt( NULL )
{
}

sqlsrv_stream() : stream_z( NULL ), encoding( SQLSRV_ENCODING_INVALID ), stmt( NULL )
sqlsrv_stream() : stream_z( NULL ), encoding( SQLSRV_ENCODING_INVALID ), field_index( 0 ), sql_type( SQL_UNKNOWN_TYPE ), stmt( NULL )
{
}
};
Expand Down Expand Up @@ -2292,7 +2297,7 @@ namespace core {
inline void sqlsrv_zend_hash_add( sqlsrv_context& ctx, HashTable* ht, zend_string* key, unsigned int key_len, zval* data,
unsigned int data_size, zval* pDest TSRMLS_DC )
{
int zr = (pDest = ::zend_hash_add(ht, key, data)) != NULL ? SUCCESS : FAILURE;
int zr = ::zend_hash_add(ht, key, data) != NULL ? SUCCESS : FAILURE;
CHECK_ZEND_ERROR( zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
throw CoreException();
}
Expand Down
2 changes: 1 addition & 1 deletion source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ void core_sqlsrv_get_field( sqlsrv_stmt* stmt, SQLUSMALLINT field_index, sqlsrv_
sqlsrv_phptype invalid;
invalid.typeinfo.type = SQLSRV_PHPTYPE_INVALID;
for( int i = stmt->last_field_index + 1; i < field_index; ++i ) {
SQLSRV_ASSERT((cached = reinterpret_cast<field_cache*>(zend_hash_index_find_ptr(Z_ARRVAL(stmt->field_cache), i))) == NULL,
SQLSRV_ASSERT(reinterpret_cast<field_cache*>(zend_hash_index_find_ptr(Z_ARRVAL(stmt->field_cache), i)) == NULL,
"Field already cached." );
core_sqlsrv_get_field( stmt, i, invalid, prefer_string, field_value, field_len, cache_field,
sqlsrv_php_type_out TSRMLS_CC );
Expand Down

0 comments on commit 36ed86f

Please sign in to comment.