Skip to content

Commit

Permalink
Merge pull request #1 from v-chojas/master
Browse files Browse the repository at this point in the history
Fixes various minor issues in 2.3.5pre
  • Loading branch information
lurcher authored Jul 6, 2017
2 parents 2fabb0b + a6c811b commit 58dae31
Show file tree
Hide file tree
Showing 58 changed files with 753 additions and 260 deletions.
6 changes: 2 additions & 4 deletions DriverManager/SQLAllocHandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@ SQLRETURN __SQLAllocHandle( SQLSMALLINT handle_type,
connection -> cursors = SQL_CUR_DEFAULT;
connection -> login_timeout = SQL_LOGIN_TIMEOUT_DEFAULT;
connection -> login_timeout_set = 0;
connection -> auto_commit = 0;
connection -> auto_commit_set = 0;
connection -> auto_commit = 0;
connection -> auto_commit = SQL_AUTOCOMMIT_ON;
connection -> auto_commit_set = 0;
connection -> async_enable = 0;
connection -> async_enable_set = 0;
Expand Down Expand Up @@ -1287,7 +1285,7 @@ SQLRETURN __SQLAllocHandle( SQLSMALLINT handle_type,
}
else
{
return SQL_ERROR;
return SQL_INVALID_HANDLE;
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions DriverManager/SQLAllocHandleStd.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ SQLRETURN SQLAllocHandleStd(
DMHENV environment = (DMHENV) *output_handle;

environment -> requested_version = SQL_OV_ODBC3;
environment -> version_set = 1;
}

return ret;
Expand Down
6 changes: 3 additions & 3 deletions DriverManager/SQLBindCol.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@

static char const rcsid[]= "$RCSfile: SQLBindCol.c,v $ $Revision: 1.8 $";

int check_target_type( int c_type )
int check_target_type( int c_type, int connection_mode)
{
/*
* driver defined types
*/
if ( c_type >= 0x4000 && c_type <= 0x7FFF ) {
if ( connection_mode >= SQL_OV_ODBC3_80 && c_type >= 0x4000 && c_type <= 0x7FFF ) {
return 1;
}

Expand Down Expand Up @@ -294,7 +294,7 @@ SQLRETURN SQLBindCol( SQLHSTMT statement_handle,
* Its possible to call with the indicator and buffer NULL to unbind without setting the type
*/

if (( target_value || strlen_or_ind ) && !check_target_type( target_type ))
if (( target_value || strlen_or_ind ) && !check_target_type( target_type, statement -> connection -> environment -> requested_version ))
{
dm_log_write( __FILE__,
__LINE__,
Expand Down
2 changes: 1 addition & 1 deletion DriverManager/SQLBindParam.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ SQLRETURN SQLBindParam( SQLHSTMT statement_handle,
* check valid C_TYPE
*/

if ( !check_target_type( value_type ))
if ( !check_target_type( value_type, statement -> connection -> environment -> requested_version ))
{
dm_log_write( __FILE__,
__LINE__,
Expand Down
16 changes: 14 additions & 2 deletions DriverManager/SQLBindParameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,19 @@ SQLRETURN SQLBindParameter(
return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
}

if ( cb_value_max < 0 && cb_value_max != SQL_NTS )
if ( ((f_c_type == SQL_C_CHAR || f_c_type == SQL_C_BINARY || f_c_type == SQL_C_WCHAR) ||
(f_c_type == SQL_C_DEFAULT &&
(f_sql_type == SQL_DEFAULT ||
f_sql_type == SQL_CHAR ||
f_sql_type == SQL_BINARY ||
f_sql_type == SQL_LONGVARCHAR ||
f_sql_type == SQL_LONGVARBINARY ||
f_sql_type == SQL_VARBINARY ||
f_sql_type == SQL_VARCHAR ||
f_sql_type == SQL_WCHAR ||
f_sql_type == SQL_WLONGVARCHAR ||
f_sql_type == SQL_WVARCHAR)))
&& cb_value_max < 0 && cb_value_max != SQL_NTS )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down Expand Up @@ -354,7 +366,7 @@ SQLRETURN SQLBindParameter(
* check valid C_TYPE
*/

if ( !check_target_type( f_c_type ))
if ( !check_target_type( f_c_type, statement -> connection -> environment -> requested_version ))
{
dm_log_write( __FILE__,
__LINE__,
Expand Down
27 changes: 27 additions & 0 deletions DriverManager/SQLCancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,33 @@ SQLRETURN SQLCancel( SQLHSTMT statement_handle )

if ( SQL_SUCCEEDED( ret ))
{
if (ret == SQL_SUCCESS_WITH_INFO )
{
SQLULEN nRecs = 0;
SQLSMALLINT len;
SQLRETURN ret2 = statement->connection->unicode_driver && CHECK_SQLGETDIAGFIELDW( statement->connection ) ?
SQLGETDIAGFIELDW ( statement -> connection, SQL_HANDLE_STMT, statement->driver_stmt, 0, SQL_DIAG_NUMBER, &nRecs, 0, &len ) :
SQLGETDIAGFIELD( statement -> connection, SQL_HANDLE_STMT, statement->driver_stmt, 0, SQL_DIAG_NUMBER, &nRecs, 0, &len);
if ( SQL_SUCCEEDED( ret2 ) && nRecs )
{
SQLSMALLINT recNo = 1;
while (nRecs--)
{
SQLCHAR state[12]; /* use the same buffer for both, length must be long enough to hold 5 SQLWCHARs + NULL */
ret2 = statement->connection->unicode_driver && CHECK_SQLGETDIAGRECW( statement->connection ) ?
SQLGETDIAGRECW( statement->connection, SQL_HANDLE_STMT, statement->driver_stmt, recNo, (SQLWCHAR*)state, NULL, NULL, 0, NULL ) :
SQLGETDIAGREC( statement->connection, SQL_HANDLE_STMT, statement->driver_stmt, recNo, state, NULL, NULL, 0, NULL ) ;
if ( SQL_SUCCEEDED( ret2 ) && (statement->connection->unicode_driver ?
!memcmp(state, "0\0001\000S\0000\0005\0", 10) : !memcmp(state, "01S05", 5)) )
{
ret = SQL_SUCCESS;
break;
}
recNo++;
}
}
}

if ( statement -> state == STATE_S8 ||
statement -> state == STATE_S9 ||
statement -> state == STATE_S10 ||
Expand Down
22 changes: 13 additions & 9 deletions DriverManager/SQLColAttribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ SQLRETURN SQLColAttribute ( SQLHSTMT statement_handle,

if ( column_number == 0 &&
statement -> bookmarks_on == SQL_UB_OFF && statement -> connection -> bookmarks_on == SQL_UB_OFF &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_DESC_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down Expand Up @@ -352,7 +352,7 @@ SQLRETURN SQLColAttribute ( SQLHSTMT statement_handle,
}
/* MS Driver manager passes this to driver
else if ( statement -> state == STATE_S2 &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_DESC_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down Expand Up @@ -590,7 +590,7 @@ SQLRETURN SQLColAttribute ( SQLHSTMT statement_handle,
}
/*
BUGBUG: Windows DM returns the number of bytes for the Unicode string
but only for certain ODBC-defined string fields
but only for certain ODBC-defined string fields, and when truncating
*/
switch ( field_identifier )
{
Expand All @@ -600,12 +600,16 @@ SQLRETURN SQLColAttribute ( SQLHSTMT statement_handle,
case SQL_COLUMN_OWNER_NAME:
case SQL_COLUMN_TABLE_NAME:
case SQL_COLUMN_TYPE_NAME:
case SQL_DESC_BASE_COLUMN_NAME:
case SQL_DESC_BASE_TABLE_NAME:
case SQL_DESC_LITERAL_PREFIX:
case SQL_DESC_LITERAL_SUFFIX:
case SQL_DESC_LOCAL_TYPE_NAME:
case SQL_DESC_NAME:
case SQL_DESC_BASE_COLUMN_NAME:
case SQL_DESC_BASE_TABLE_NAME:
case SQL_DESC_LITERAL_PREFIX:
case SQL_DESC_LITERAL_SUFFIX:
case SQL_DESC_LOCAL_TYPE_NAME:
case SQL_DESC_NAME:
if ( ret == SQL_SUCCESS && string_length )
{
*string_length /= sizeof( SQLWCHAR );
}
break;
default:
if ( string_length )
Expand Down
4 changes: 2 additions & 2 deletions DriverManager/SQLColAttributeW.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ SQLRETURN SQLColAttributeW ( SQLHSTMT statement_handle,

if ( column_number == 0 &&
statement -> bookmarks_on == SQL_UB_OFF && statement -> connection -> bookmarks_on == SQL_UB_OFF &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_DESC_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down Expand Up @@ -214,7 +214,7 @@ SQLRETURN SQLColAttributeW ( SQLHSTMT statement_handle,
}
/*
else if ( statement -> state == STATE_S2 &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_DESC_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down
8 changes: 6 additions & 2 deletions DriverManager/SQLColAttributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ SQLRETURN SQLColAttributes( SQLHSTMT statement_handle,

if ( column_number == 0 &&
statement -> bookmarks_on == SQL_UB_OFF && statement -> connection -> bookmarks_on == SQL_UB_OFF &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_COLUMN_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down Expand Up @@ -346,7 +346,7 @@ SQLRETURN SQLColAttributes( SQLHSTMT statement_handle,
}
/*
else if ( statement -> state == STATE_S2 &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_DESC_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down Expand Up @@ -482,6 +482,10 @@ SQLRETURN SQLColAttributes( SQLHSTMT statement_handle,

if ( SQL_SUCCEEDED( ret ) && isStringAttr && character_attribute && buffer_length > 0 && s1 )
{
if ( string_length && ret == SQL_SUCCESS )
{
*string_length /= sizeof ( SQLWCHAR );
}
unicode_to_ansi_copy( character_attribute, buffer_length, s1, SQL_NTS, statement -> connection, NULL );
}

Expand Down
4 changes: 2 additions & 2 deletions DriverManager/SQLColAttributesW.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ SQLRETURN SQLColAttributesW( SQLHSTMT statement_handle,

if ( column_number == 0 &&
statement -> bookmarks_on == SQL_UB_OFF && statement -> connection -> bookmarks_on == SQL_UB_OFF &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_COLUMN_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down Expand Up @@ -255,7 +255,7 @@ SQLRETURN SQLColAttributesW( SQLHSTMT statement_handle,
return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
}
else if ( statement -> state == STATE_S2 &&
field_identifier != SQL_DESC_COUNT && field_identifier != SQL_COLUMN_COUNT )
field_identifier != SQL_DESC_COUNT )
{
dm_log_write( __FILE__,
__LINE__,
Expand Down
30 changes: 15 additions & 15 deletions DriverManager/SQLColumnPrivileges.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ SQLRETURN SQLColumnPrivileges(

thread_protect( SQL_HANDLE_STMT, statement );

if ( table_name == NULL )
{
dm_log_write( __FILE__,
__LINE__,
LOG_INFO,
LOG_INFO,
"Error: HY009" );

__post_internal_error( &statement -> error,
ERROR_HY009, NULL,
statement -> connection -> environment -> requested_version );

return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
}

if (( name_length1 < 0 && name_length1 != SQL_NTS ) ||
( name_length2 < 0 && name_length2 != SQL_NTS ) ||
( name_length3 < 0 && name_length3 != SQL_NTS ) ||
Expand Down Expand Up @@ -287,21 +302,6 @@ SQLRETURN SQLColumnPrivileges(
}
}

if ( table_name == NULL )
{
dm_log_write( __FILE__,
__LINE__,
LOG_INFO,
LOG_INFO,
"Error: HY009" );

__post_internal_error( &statement -> error,
ERROR_HY009, NULL,
statement -> connection -> environment -> requested_version );

return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
}

/*
* TO_DO Check the SQL_ATTR_METADATA_ID settings
*/
Expand Down
30 changes: 15 additions & 15 deletions DriverManager/SQLColumnPrivilegesW.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ SQLRETURN SQLColumnPrivilegesW(

thread_protect( SQL_HANDLE_STMT, statement );

if ( table_name == NULL )
{
dm_log_write( __FILE__,
__LINE__,
LOG_INFO,
LOG_INFO,
"Error: HY009" );

__post_internal_error( &statement -> error,
ERROR_HY009, NULL,
statement -> connection -> environment -> requested_version );

return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
}

if (( name_length1 < 0 && name_length1 != SQL_NTS ) ||
( name_length2 < 0 && name_length2 != SQL_NTS ) ||
( name_length3 < 0 && name_length3 != SQL_NTS ) ||
Expand Down Expand Up @@ -259,21 +274,6 @@ SQLRETURN SQLColumnPrivilegesW(
}
}

if ( table_name == NULL )
{
dm_log_write( __FILE__,
__LINE__,
LOG_INFO,
LOG_INFO,
"Error: HY009" );

__post_internal_error( &statement -> error,
ERROR_HY009, NULL,
statement -> connection -> environment -> requested_version );

return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
}

/*
* TO_DO Check the SQL_ATTR_METADATA_ID settings
*/
Expand Down
8 changes: 4 additions & 4 deletions DriverManager/SQLColumns.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ SQLRETURN SQLColumns( SQLHSTMT statement_handle,

thread_protect( SQL_HANDLE_STMT, statement );

if (( name_length1 < 0 && name_length1 != SQL_NTS ) ||
( name_length2 < 0 && name_length2 != SQL_NTS ) ||
( name_length3 < 0 && name_length3 != SQL_NTS ) ||
( name_length4 < 0 && name_length4 != SQL_NTS ))
if (( catalog_name && name_length1 < 0 && name_length1 != SQL_NTS ) ||
( schema_name && name_length2 < 0 && name_length2 != SQL_NTS ) ||
( table_name && name_length3 < 0 && name_length3 != SQL_NTS ) ||
( column_name && name_length4 < 0 && name_length4 != SQL_NTS ))
{
dm_log_write( __FILE__,
__LINE__,
Expand Down
8 changes: 4 additions & 4 deletions DriverManager/SQLColumnsW.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ SQLRETURN SQLColumnsW( SQLHSTMT statement_handle,

thread_protect( SQL_HANDLE_STMT, statement );

if (( name_length1 < 0 && name_length1 != SQL_NTS ) ||
( name_length2 < 0 && name_length2 != SQL_NTS ) ||
( name_length3 < 0 && name_length3 != SQL_NTS ) ||
( name_length4 < 0 && name_length4 != SQL_NTS ))
if (( catalog_name && name_length1 < 0 && name_length1 != SQL_NTS ) ||
( schema_name && name_length2 < 0 && name_length2 != SQL_NTS ) ||
( table_name && name_length3 < 0 && name_length3 != SQL_NTS ) ||
( column_name && name_length4 < 0 && name_length4 != SQL_NTS ))
{
__post_internal_error( &statement -> error,
ERROR_HY090, NULL,
Expand Down
2 changes: 1 addition & 1 deletion DriverManager/SQLConnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -3964,7 +3964,7 @@ SQLRETURN SQLConnect( SQLHDBC connection_handle,
connection -> password_length = name_length3;
}

if ( !__find_lib_name( dsn, lib_name, driver_name ))
if ( !*dsn || !__find_lib_name( dsn, lib_name, driver_name ))
{
/*
* if not found look for a default
Expand Down
2 changes: 1 addition & 1 deletion DriverManager/SQLConnectW.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ SQLRETURN SQLConnectW( SQLHDBC connection_handle,

unicode_to_ansi_copy((char*) ansi_dsn, sizeof( ansi_dsn ), dsn, sizeof( ansi_dsn ), NULL, NULL );

if ( !__find_lib_name((char*) ansi_dsn, lib_name, driver_name ))
if ( !*ansi_dsn || !__find_lib_name((char*) ansi_dsn, lib_name, driver_name ))
{
/*
* if not found look for a default
Expand Down
7 changes: 4 additions & 3 deletions DriverManager/SQLCopyDesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,13 @@ SQLRETURN SQLCopyDesc( SQLHDESC source_desc_handle,
}

/*
* if both descriptors are from the same connection the we can just
* if both descriptors are from the same driver then we can just
* pass it on
*/

if ( src_descriptor -> connection ==
target_descriptor -> connection &&
if ( (src_descriptor -> connection == target_descriptor -> connection ||
!strcmp(src_descriptor -> connection -> dl_name,
target_descriptor -> connection -> dl_name) ) &&
CHECK_SQLCOPYDESC( src_descriptor -> connection ))
{
SQLRETURN ret;
Expand Down
Loading

0 comments on commit 58dae31

Please sign in to comment.