SQLRETURN SQLGetConnectAttrW( SQLHDBC connection_handle, SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER buffer_length, SQLINTEGER *string_length ) { DMHDBC connection = (DMHDBC)connection_handle; int type = 0; char *ptr; SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; /* * doesn't require a handle */ if ( attribute == SQL_ATTR_TRACE ) { if ( value ) { if ( log_info.log_flag ) { *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON; } else { *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON; } } return SQL_SUCCESS; } else if ( attribute == SQL_ATTR_TRACEFILE ) { SQLRETURN ret = SQL_SUCCESS; ptr = log_info.log_file_name; if ( ptr ) { int len = strlen( ptr ) * sizeof( SQLWCHAR ); if ( string_length ) { *string_length = len; } if ( value ) { if ( buffer_length > len + sizeof( SQLWCHAR )) { ansi_to_unicode_copy( value, ptr, SQL_NTS, connection ); } else { ansi_to_unicode_copy( value, ptr, buffer_length - 1, connection ); ((SQLWCHAR*)value)[( buffer_length - 1 ) / sizeof( SQLWCHAR )] = 0; ret = SQL_SUCCESS_WITH_INFO; } } } else { if ( string_length ) { *string_length = 0; } if ( value ) { if ( buffer_length > 0 ) { ((SQLWCHAR*)value)[ 0 ] = 0; } else { ret = SQL_SUCCESS_WITH_INFO; } } } return ret; } /* * check connection */ if ( !__validate_dbc( connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: SQL_INVALID_HANDLE" ); return SQL_INVALID_HANDLE; } function_entry( connection ); if ( log_info.log_flag ) { sprintf( connection -> msg, "\n\t\tEntry:\ \n\t\t\tConnection = %p\ \n\t\t\tAttribute = %s\ \n\t\t\tValue = %p\ \n\t\t\tBuffer Length = %d\ \n\t\t\tStrLen = %p", connection, __con_attr_as_string( s1, attribute ), value, (int)buffer_length, (void*)string_length ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, connection -> msg ); }
SQLRETURN SQLSetConnectOptionW( SQLHDBC connection_handle, SQLUSMALLINT option, SQLULEN value ) { DMHDBC connection = (DMHDBC)connection_handle; SQLRETURN ret; SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; SQLWCHAR buffer[ 512 ]; /* * doesn't require a handle */ if ( option == SQL_ATTR_TRACE ) { if ((SQLLEN) value != SQL_OPT_TRACE_OFF && (SQLLEN) value != SQL_OPT_TRACE_ON ) { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY024" ); __post_internal_error( &connection -> error, ERROR_HY024, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } if ( value == SQL_OPT_TRACE_OFF ) { log_info.log_flag = 0; } else { log_info.log_flag = 1; } return SQL_SUCCESS; } else if ( option == SQL_ATTR_TRACEFILE ) { if ( value ) { if (((SQLWCHAR*)value)[ 0 ] == 0 ) { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY024" ); __post_internal_error( &connection -> error, ERROR_HY024, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } else { if ( log_info.log_file_name ) { free( log_info.log_file_name ); } log_info.log_file_name = unicode_to_ansi_alloc((SQLWCHAR *) value, SQL_NTS, connection ); } } else { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY009" ); __post_internal_error( &connection -> error, ERROR_HY009, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } return SQL_SUCCESS; } /* * check connection */ if ( !__validate_dbc( connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: SQL_INVALID_HANDLE" ); #ifdef WITH_HANDLE_REDIRECT { DMHDBC parent_connection; parent_connection = find_parent_handle( connection, SQL_HANDLE_DBC ); if ( parent_connection ) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Info: found parent handle" ); if ( CHECK_SQLSETCONNECTOPTIONW( parent_connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Info: calling redirected driver function" ); return SQLSETCONNECTOPTIONW( parent_connection, connection_handle, option, value ); } } } #endif return SQL_INVALID_HANDLE; } function_entry( connection ); if ( log_info.log_flag ) { sprintf( connection -> msg, "\n\t\tEntry:\ \n\t\t\tConnection = %p\ \n\t\t\tOption = %s\ \n\t\t\tValue = %d", connection, __con_attr_as_string( s1, option ), (int)value ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, connection -> msg ); }
SQLRETURN SQLGetConnectOptionW( SQLHDBC connection_handle, SQLUSMALLINT option, SQLPOINTER value ) { DMHDBC connection = (DMHDBC)connection_handle; int type = 0; SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; /* * doesn't require a handle */ if ( option == SQL_ATTR_TRACE ) { if ( value ) { if ( log_info.log_flag ) { *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON; } else { *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON; } } return SQL_SUCCESS; } else if ( option == SQL_ATTR_TRACEFILE ) { SQLRETURN ret = SQL_SUCCESS; if ( log_info.log_file_name ) { ansi_to_unicode_copy( value, log_info.log_file_name, SQL_NTS, connection ); } else { ansi_to_unicode_copy( value, "", SQL_NTS, connection ); } return ret; } /* * check connection */ if ( !__validate_dbc( connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: SQL_INVALID_HANDLE" ); #ifdef WITH_HANDLE_REDIRECT { DMHDBC parent_connection; parent_connection = find_parent_handle( connection, SQL_HANDLE_DBC ); if ( parent_connection ) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Info: found parent handle" ); if ( CHECK_SQLGETCONNECTOPTIONW( parent_connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Info: calling redirected driver function" ); return SQLGETCONNECTOPTIONW( parent_connection, connection, option, value ); } } } #endif return SQL_INVALID_HANDLE; } function_entry( connection ); if ( log_info.log_flag ) { sprintf( connection -> msg, "\n\t\tEntry:\ \n\t\t\tConnection = %p\ \n\t\t\tOption = %s\ \n\t\t\tValue = %p", connection, __con_attr_as_string( s1, option ), value ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, connection -> msg ); }
SQLRETURN SQLSetConnectOption( SQLHDBC connection_handle, SQLUSMALLINT option, SQLULEN value ) { DMHDBC connection = (DMHDBC)connection_handle; SQLRETURN ret; SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; /* * doesn't require a handle */ if ( option == SQL_ATTR_TRACE ) { if ( value == SQL_OPT_TRACE_OFF ) { log_info.log_flag = 0; } else { log_info.log_flag = 1; } return SQL_SUCCESS; } else if ( option == SQL_ATTR_TRACEFILE ) { if ( value ) { if ( log_info.log_file_name ) { free( log_info.log_file_name ); } log_info.log_file_name = (char*)strdup((char*)(void*) value ); } return SQL_SUCCESS; } /* * check connection */ if ( !__validate_dbc( connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: SQL_INVALID_HANDLE" ); return SQL_INVALID_HANDLE; } function_entry( connection ); if ( log_info.log_flag ) { sprintf( connection -> msg, "\n\t\tEntry:\ \n\t\t\tConnection = %p\ \n\t\t\tOption = %s\ \n\t\t\tValue = %d", connection, __con_attr_as_string( s1, option ), (int)value ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, connection -> msg ); }
SQLRETURN SQLSetConnectOption( SQLHDBC connection_handle, SQLUSMALLINT option, SQLULEN value ) { DMHDBC connection = (DMHDBC)connection_handle; SQLRETURN ret; SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; /* * doesn't require a handle */ if ( option == SQL_ATTR_TRACE ) { if ((SQLLEN) value != SQL_OPT_TRACE_OFF && (SQLLEN) value != SQL_OPT_TRACE_ON ) { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY024" ); __post_internal_error( &connection -> error, ERROR_HY024, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } if ( value == SQL_OPT_TRACE_OFF ) { log_info.log_flag = 0; } else { log_info.log_flag = 1; } return SQL_SUCCESS; } else if ( option == SQL_ATTR_TRACEFILE ) { if ( value ) { if (((SQLCHAR*)value)[ 0 ] == '\0' ) { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY024" ); __post_internal_error( &connection -> error, ERROR_HY024, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } else { if ( log_info.log_file_name ) { free( log_info.log_file_name ); } log_info.log_file_name = strdup((char*) value ); } } else { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY009" ); __post_internal_error( &connection -> error, ERROR_HY009, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } } /* * check connection */ if ( !__validate_dbc( connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: SQL_INVALID_HANDLE" ); return SQL_INVALID_HANDLE; } function_entry( connection ); if ( log_info.log_flag ) { sprintf( connection -> msg, "\n\t\tEntry:\ \n\t\t\tConnection = %p\ \n\t\t\tOption = %s\ \n\t\t\tValue = %d", connection, __con_attr_as_string( s1, option ), (int)value ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, connection -> msg ); }
SQLRETURN SQLSetConnectAttrW( SQLHDBC connection_handle, SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER string_length ) { DMHDBC connection = (DMHDBC)connection_handle; SQLRETURN ret; SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; SQLWCHAR buffer[ 512 ]; /* * doesn't require a handle */ if ( attribute == SQL_ATTR_TRACE ) { if ((SQLLEN) value != SQL_OPT_TRACE_OFF && (SQLLEN) value != SQL_OPT_TRACE_ON ) { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY024" ); __post_internal_error( &connection -> error, ERROR_HY024, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } if ((SQLLEN) value == SQL_OPT_TRACE_OFF ) { char force_string[ 30 ]; SQLGetPrivateProfileString( "ODBC", "ForceTrace", "0", force_string, sizeof( force_string ), "ODBCINST.INI" ); if ( force_string[ 0 ] == '1' || toupper( force_string[ 0 ] ) == 'Y' || ( toupper( force_string[ 0 ] ) == 'O' && toupper( force_string[ 1 ] ) == 'N' )) { if ( log_info.log_flag ) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Application tried to turn logging off" ); } } else { if ( log_info.log_flag ) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Application turning logging off" ); } log_info.log_flag = 0; } } else { log_info.log_flag = 1; } return SQL_SUCCESS; } else if ( attribute == SQL_ATTR_TRACEFILE ) { if ( value ) { if (((SQLWCHAR*)value)[ 0 ] == 0 ) { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY024" ); __post_internal_error( &connection -> error, ERROR_HY024, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } else { if ( log_info.log_file_name ) { free( log_info.log_file_name ); } log_info.log_file_name = unicode_to_ansi_alloc((SQLWCHAR *) value, SQL_NTS, connection ); } } else { if ( __validate_dbc( connection )) { thread_protect( SQL_HANDLE_DBC, connection ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: HY009" ); __post_internal_error( &connection -> error, ERROR_HY009, NULL, connection -> environment -> requested_version ); return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR ); } else { return SQL_INVALID_HANDLE; } } return SQL_SUCCESS; } /* * check connection */ if ( !__validate_dbc( connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Error: SQL_INVALID_HANDLE" ); #ifdef WITH_HANDLE_REDIRECT { DMHDBC parent_connection; parent_connection = find_parent_handle( connection, SQL_HANDLE_DBC ); if ( parent_connection ) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Info: found parent handle" ); if ( CHECK_SQLSETCONNECTATTRW( parent_connection )) { dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, "Info: calling redirected driver function" ); return SQLSETCONNECTATTRW( parent_connection, connection_handle, attribute, value, string_length ); } } } #endif return SQL_INVALID_HANDLE; } function_entry( connection ); if ( log_info.log_flag ) { sprintf( connection -> msg, "\n\t\tEntry:\ \n\t\t\tConnection = %p\ \n\t\t\tAttribute = %s\ \n\t\t\tValue = %p\ \n\t\t\tStrLen = %d", connection, __con_attr_as_string( s1, attribute ), value, (int)string_length ); dm_log_write( __FILE__, __LINE__, LOG_INFO, LOG_INFO, connection -> msg ); }