applied peer review comments

This commit is contained in:
Hadis Kakanejadi Fard 2017-01-30 13:05:38 -08:00
parent 64e08eb1a0
commit 0e70a95d63
6 changed files with 12 additions and 30 deletions

View file

@ -143,8 +143,7 @@ sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_
}
SQLSMALLINT output_conn_size;
r = SQLDriverConnectW( conn->handle(), NULL, reinterpret_cast<SQLWCHAR*>(wconn_string.get()),
static_cast<SQLSMALLINT>(wconn_len), NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT);
r = SQLDriverConnectW( conn->handle(), NULL, reinterpret_cast<SQLWCHAR*>(wconn_string.get()), static_cast<SQLSMALLINT>( wconn_len ), NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT );
// clear the connection string from memory to remove sensitive data (such as a password).
memset( const_cast<char*>(conn_str.c_str()), 0, conn_str.size());

View file

@ -53,7 +53,7 @@ void core_sqlsrv_minit( sqlsrv_context** henv_cp, sqlsrv_context** henv_ncp, err
LOG( SEV_ERROR, "Failed to retrieve Windows version information." );
throw core::CoreException();
}
#endif
#endif //_WIN32
SQLHANDLE henv = SQL_NULL_HANDLE;
SQLRETURN r;

View file

@ -26,7 +26,7 @@
#ifndef _WIN32
#include <type_traits>
#include <uchar.h>
#endif // _WIN32
#endif // !_WIN32
using namespace core;
@ -122,7 +122,7 @@ size_t get_float_precision(SQLLEN buffer_length, size_t unitsize)
#ifndef _WIN32
// copy the number into a char string using the num_put facet
template <typename Number>
SQLRETURN get_string_from_stream(Number number_data, std::basic_string<char> &str_num, size_t precision, sqlsrv_error_auto_ptr& last_error)
SQLRETURN get_string_from_stream( Number number_data, std::basic_string<char> &str_num, size_t precision, sqlsrv_error_auto_ptr& last_error)
{
//std::locale loc( std::locale(""), new std::num_put<char> ); // By default, SQL Server doesn't take user's locale into consideration
std::locale loc;
@ -236,7 +236,6 @@ SQLRETURN number_to_string( Number* number_data, _Out_ void* buffer, SQLLEN buff
#endif // _WIN32
}
template <typename Number, typename Char>
@ -828,7 +827,7 @@ SQLRETURN sqlsrv_buffered_result_set::get_data( SQLUSMALLINT field_index, SQLSMA
// check to make sure the conversion type is valid
conv_matrix_t::const_iterator conv_iter = conv_matrix.find(meta[field_index].c_type);
conv_matrix_t::const_iterator conv_iter = conv_matrix.find( meta[field_index].c_type );
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", (SQLCHAR*) "Restricted data type attribute violation", 0 );

View file

@ -233,7 +233,7 @@ sqlsrv_stmt* core_sqlsrv_create_stmt( sqlsrv_conn* conn, driver_stmt_factory stm
{
sqlsrv_malloc_auto_ptr<sqlsrv_stmt> stmt;
SQLHANDLE stmt_h = SQL_NULL_HANDLE;
sqlsrv_stmt* return_stmt;
sqlsrv_stmt* return_stmt = NULL;
try {
@ -1169,19 +1169,11 @@ void core_sqlsrv_set_query_timeout( sqlsrv_stmt* stmt, long timeout TSRMLS_DC )
// set the LOCK_TIMEOUT on the server.
char lock_timeout_sql[ 32 ];
#ifndef _WIN32
int written = snprintf( lock_timeout_sql, sizeof( lock_timeout_sql ), "SET LOCK_TIMEOUT %d",
lock_timeout );
int written = snprintf( lock_timeout_sql, sizeof( lock_timeout_sql ), "SET LOCK_TIMEOUT %d", lock_timeout );
SQLSRV_ASSERT( (written != -1 && written != sizeof( lock_timeout_sql )),
"stmt_option_query_timeout: snprintf failed. Shouldn't ever fail." );
#else
int written = sprintf_s( lock_timeout_sql, sizeof( lock_timeout_sql ), "SET LOCK_TIMEOUT %d",
lock_timeout );
SQLSRV_ASSERT( (written != -1 && written != sizeof( lock_timeout_sql )),
"stmt_option_query_timeout: sprintf_s failed. Shouldn't ever fail." );
#endif // !_WIN32
core::SQLExecDirect( stmt, lock_timeout_sql TSRMLS_CC );
stmt->query_timeout = timeout;
@ -1266,12 +1258,13 @@ bool core_sqlsrv_send_stream_packet( sqlsrv_stmt* stmt TSRMLS_DC )
// the size of wbuffer is set for the worst case of UTF-8 to UTF-16 conversion, which is a
// expansion of 2x the UTF-8 size.
SQLWCHAR wbuffer[ PHP_STREAM_BUFFER_SIZE + 1 ];
int wbuffer_size = static_cast<int>( sizeof( wbuffer ) / sizeof( SQLWCHAR ));
DWORD last_error_code = ERROR_SUCCESS;
// buffer_size is the # of wchars. Since it set to stmt->param_buffer_size / 2, this is accurate
#ifndef _WIN32
int wsize = SystemLocale::ToUtf16Strict( stmt->current_stream.encoding, buffer, static_cast<int>(read), wbuffer, static_cast<int>(sizeof( wbuffer ) / sizeof( SQLWCHAR )), &last_error_code );
int wsize = SystemLocale::ToUtf16Strict( stmt->current_stream.encoding, buffer, static_cast<int>(read), wbuffer, wbuffer_size, &last_error_code );
#else
int wsize = MultiByteToWideChar( stmt->current_stream.encoding, MB_ERR_INVALID_CHARS, buffer, static_cast<int>( read ), wbuffer, static_cast<int>( sizeof( wbuffer ) / sizeof( wchar_t )));
int wsize = MultiByteToWideChar( stmt->current_stream.encoding, MB_ERR_INVALID_CHARS, buffer, static_cast<int>( read ), wbuffer, wbuffer_size );
last_error_code = GetLastError();
#endif // !_WIN32

View file

@ -34,12 +34,6 @@
#define LANG_NEUTRAL 0x00
#define SUBLANG_DEFAULT 0x01 // user default
// #ifndef _GETLASTERROR
// #define _GETLASTERROR
// void SSetLastError(DWORD err);
// unsigned int GGetLastError();
// #endif
DWORD FormatMessageA(
DWORD dwFlags,
LPCVOID lpSource,

View file

@ -448,9 +448,6 @@ VerSetConditionMask(
);
//#include <basetsd.h>
//// ntdef.h
#define __unaligned
#ifndef UNALIGNED