Esempio n. 1
0
SQLRETURN SQLPrepareW( SQLHSTMT statement_handle,
           SQLWCHAR *statement_text,
           SQLINTEGER text_length )
{
    DMHSTMT statement = (DMHSTMT) statement_handle;
    SQLRETURN ret;
    SQLCHAR *s1;
    SQLCHAR s2[ 100 + LOG_MESSAGE_LEN ];

    /*
     * check statement
     */

    if ( !__validate_stmt( statement ))
    {
        dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: SQL_INVALID_HANDLE" );

        return SQL_INVALID_HANDLE;
    }

    function_entry( statement );

    if ( log_info.log_flag  )
    {
        /*
         * allocate some space for the buffer
         */

        if ( statement_text && text_length == SQL_NTS )
        {
            s1 = malloc( wide_strlen( statement_text ) + 100 );
        }
        else if ( statement_text )
        {
            s1 = malloc( text_length + 100 );
        }
        else
        {
            s1 = malloc( 101 );
        }

        sprintf( statement -> msg, "\n\t\tEntry:\
            \n\t\t\tStatement = %p\
            \n\t\t\tSQL = %s",
                statement,
                __wstring_with_length( s1, statement_text, text_length ));

        free( s1 );

        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                statement -> msg );
    }

    thread_protect( SQL_HANDLE_STMT, statement );

    if ( !statement_text )
    {
        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( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }

    if ( text_length <= 0 && text_length != SQL_NTS )
    {
        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: HY090" );

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

        return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }

    /*
     * check states
     */
#ifdef NR_PROBE
    if ( statement -> state == STATE_S5 ||
            statement -> state == STATE_S6 ||
            statement -> state == STATE_S7 )
#else
    if ( statement -> state == STATE_S6 ||
            statement -> state == STATE_S7 )
#endif
    {
        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: 24000" );

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

        return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }
    else if ( statement -> state == STATE_S8 ||
            statement -> state == STATE_S9 ||
            statement -> state == STATE_S10 )
    {
        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: HY010" );

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

        return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }

    if ( statement -> state == STATE_S11 ||
            statement -> state == STATE_S12 )
    {
        if ( statement -> interupted_func != SQL_API_SQLPREPARE )
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: HY010" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }
    }

    if ( statement -> connection -> unicode_driver )
    {
        if ( !CHECK_SQLPREPAREW( statement -> connection ))
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: IM001" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }

        ret = SQLPREPAREW( statement -> connection ,
                statement -> driver_stmt,
                statement_text,
                text_length );
    }
    else
    {
        SQLCHAR *as1;

        if ( !CHECK_SQLPREPARE( statement -> connection ))
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: IM001" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }

        as1 = (SQLCHAR*) unicode_to_ansi_alloc( statement_text, text_length, statement -> connection );

        ret = SQLPREPARE( statement -> connection ,
                statement -> driver_stmt,
                as1, 
                text_length );

        if ( as1 ) free( as1 );
    }

    if ( SQL_SUCCEEDED( ret ))
    {
        statement -> hascols = 0;
		statement -> state = STATE_S3;
        statement -> prepared = 1;
    }
    else if ( ret == SQL_STILL_EXECUTING )
    {
        statement -> interupted_func = SQL_API_SQLPREPARE;
        if ( statement -> state != STATE_S11 &&
                statement -> state != STATE_S12 )
            statement -> state = STATE_S11;
    }
    else
    {
        statement -> state = STATE_S1;
    }

    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, 
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s2 ));

        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                statement -> msg );
    }

    return function_return( SQL_HANDLE_STMT, statement, ret );
}
Esempio n. 2
0
SQLRETURN SQLEndTran( SQLSMALLINT handle_type,
        SQLHANDLE handle,
        SQLSMALLINT completion_type )
{
    SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];

    if ( handle_type != SQL_HANDLE_ENV && handle_type != SQL_HANDLE_DBC ) 
    {
        DMHSTMT statement;
        DMHDESC descriptor;

        if ( handle_type == SQL_HANDLE_STMT ) {
            if ( !__validate_stmt(( DMHSTMT ) handle ))
            {
                 dm_log_write( __FILE__, 
                        __LINE__, 
                         LOG_INFO, 
                        LOG_INFO, 
                        "Error: SQL_INVALID_HANDLE" );

                return SQL_INVALID_HANDLE;
            }
            statement = (DMHSTMT) handle;

            function_entry( statement );
            thread_protect( SQL_HANDLE_STMT, statement );

            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: HY092" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }
        else if ( handle_type == SQL_HANDLE_DESC ) {
            if ( !__validate_desc(( DMHDESC ) handle ))
            {
                 dm_log_write( __FILE__, 
                        __LINE__, 
                         LOG_INFO, 
                        LOG_INFO, 
                        "Error: SQL_INVALID_HANDLE" );

                return SQL_INVALID_HANDLE;
            }
            descriptor = (DMHDESC) handle;

            function_entry( descriptor );
            thread_protect( SQL_HANDLE_DESC, descriptor );

            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: HY092" );

            __post_internal_error( &descriptor -> error,
                    ERROR_HY092, NULL,
                    descriptor -> connection -> environment -> requested_version );

            return function_return( SQL_HANDLE_DESC, descriptor, SQL_ERROR );
        }
        else {
             dm_log_write( __FILE__, 
                    __LINE__, 
                     LOG_INFO, 
                    LOG_INFO, 
                    "Error: SQL_INVALID_HANDLE" );

            return SQL_INVALID_HANDLE;
        }
    }

    if ( handle_type == SQL_HANDLE_ENV )
    {
        DMHENV environment = (DMHENV) handle;
        DMHDBC connection;
        SQLRETURN ret;

        if ( !__validate_env( environment ))
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: SQL_INVALID_HANDLE" );

            return SQL_INVALID_HANDLE;
        }

        function_entry( environment );

        if ( log_info.log_flag )
        {
            sprintf( environment -> msg, "\n\t\tEntry:\
\n\t\t\tEnvironment = %p\
\n\t\t\tCompletion Type = %d",
                    (void*)environment,
                    (int)completion_type );

            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    environment -> msg );
        }
Esempio n. 3
0
SQLRETURN SQLExecDirectW( SQLHSTMT statement_handle,
           SQLWCHAR *statement_text,
           SQLINTEGER text_length )
{
    DMHSTMT statement = (DMHSTMT) statement_handle;
    SQLRETURN ret;
    SQLCHAR *s1;
    SQLCHAR s2[ 100 + LOG_MESSAGE_LEN ];

    /*
     * check statement
     */

    if ( !__validate_stmt( statement ))
    {
        dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: SQL_INVALID_HANDLE" );

#ifdef WITH_HANDLE_REDIRECT
		{
			DMHSTMT parent_statement;

			parent_statement = find_parent_handle( statement, SQL_HANDLE_STMT );

			if ( parent_statement ) {
        		dm_log_write( __FILE__, 
                	__LINE__, 
                    	LOG_INFO, 
                    	LOG_INFO, 
                    	"Info: found parent handle" );

				if ( CHECK_SQLEXECDIRECTW( parent_statement -> connection ))
				{
        			dm_log_write( __FILE__, 
                		__LINE__, 
                   		 	LOG_INFO, 
                   		 	LOG_INFO, 
                   		 	"Info: calling redirected driver function" );

                	return  SQLEXECDIRECTW( parent_statement -> connection,
							statement,
							statement_text,
							text_length );
				}
			}
		}
#endif
        return SQL_INVALID_HANDLE;
    }

    function_entry( statement );

    if ( log_info.log_flag )
    {
        /*
         * allocate some space for the buffer
         */

        if ( statement_text && text_length == SQL_NTS )
        {
             s1 = malloc( wide_strlen( statement_text ) * 2 + LOG_MESSAGE_LEN * 2 );
        }
        else if ( statement_text )
        {
            s1 = malloc( text_length + LOG_MESSAGE_LEN * 2 );
        }
        else
        {
            s1 = malloc( LOG_MESSAGE_LEN * 2 );
        }

        sprintf( statement -> msg, "\n\t\tEntry:\
\n\t\t\tStatement = %p\
\n\t\t\tSQL = %s",
                statement,
                __wstring_with_length( s1, statement_text, text_length ));

        free( s1 );

        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                statement -> msg );
    }

    thread_protect( SQL_HANDLE_STMT, statement );

    if ( !statement_text )
    {
        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( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }

    if ( text_length <= 0 && text_length != SQL_NTS )
    {
        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: HY090" );

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

        return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }

    /*
     * check states
     */

#ifdef NR_PROBE
    if ( statement -> state == STATE_S5 ||
            statement -> state == STATE_S6 ||
            statement -> state == STATE_S7 )
#else
    if (( statement -> state == STATE_S6 && statement -> eod == 0 ) ||
            statement -> state == STATE_S7 )
#endif
    {
        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: 24000" );

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

        return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }
    else if ( statement -> state == STATE_S8 ||
            statement -> state == STATE_S9 ||
            statement -> state == STATE_S10 )
    {
        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: HY010" );

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

        return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
    }

    if ( statement -> state == STATE_S11 ||
            statement -> state == STATE_S12 )
    {
        if ( statement -> interupted_func != SQL_API_SQLEXECDIRECT )
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: HY010" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }
    }

    if ( statement -> connection -> unicode_driver ||
		    CHECK_SQLEXECDIRECTW( statement -> connection ))
    {
#ifdef NR_PROBE
        if ( !CHECK_SQLEXECDIRECTW( statement -> connection ) ||
                !CHECK_SQLNUMRESULTCOLS( statement -> connection ))
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: IM001" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }
#else
        if ( !CHECK_SQLEXECDIRECTW( statement -> connection ))
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: IM001" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }
#endif

        ret = SQLEXECDIRECTW( statement -> connection,
                statement -> driver_stmt,
                statement_text,
                text_length );
    }
    else
    {
        SQLCHAR *as1 = NULL;
        int clen;

#ifdef NR_PROBE
        if ( !CHECK_SQLEXECDIRECT( statement -> connection ) ||
                !CHECK_SQLNUMRESULTCOLS( statement -> connection ))
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: IM001" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }
#else
        if ( !CHECK_SQLEXECDIRECT( statement -> connection ))
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: IM001" );

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

            return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
        }
#endif

        as1 = (SQLCHAR*) unicode_to_ansi_alloc( statement_text, text_length, statement -> connection, &clen );

        text_length = clen;

        ret = SQLEXECDIRECT( statement -> connection,
                statement -> driver_stmt,
                as1,
                text_length );

        if ( as1 )
            free( as1 );
    }

    if ( SQL_SUCCEEDED( ret ))
    {
#ifdef NR_PROBE
        SQLRETURN local_ret;
  
        /*
         * grab any errors
         */

        if ( ret == SQL_SUCCESS_WITH_INFO )
        {
            function_return_ex( IGNORE_THREAD, statement, ret, TRUE );
        }

        local_ret = SQLNUMRESULTCOLS( statement -> connection,
                statement -> driver_stmt, &statement -> numcols );

        if ( statement -> numcols > 0 )
        {
            statement -> state = STATE_S5;
        }
        else
        {
            statement -> state = STATE_S4;
        }
#else
        /*
         * We don't know for sure
         */
        statement -> hascols = 1;
        statement -> state = STATE_S5;
#endif

        statement -> prepared = 0;

        /*
         * there is a issue here with transactions, but for the
         * moment
         *
        statement -> connection -> state = STATE_C6;
         */
    }
    else if ( ret == SQL_NEED_DATA )
    {
        statement -> interupted_func = SQL_API_SQLEXECDIRECT;
        statement -> interupted_state = statement -> state;
        statement -> state = STATE_S8;

        statement -> prepared = 0;
    }
    else if ( ret == SQL_PARAM_DATA_AVAILABLE )
    {
        statement -> interupted_func = SQL_API_SQLEXECDIRECT;
        statement -> interupted_state = statement -> state;
        statement -> state = STATE_S13;
    }
    else if ( ret == SQL_STILL_EXECUTING )
    {
        statement -> interupted_func = SQL_API_SQLEXECDIRECT;
        if ( statement -> state != STATE_S11 &&
                statement -> state != STATE_S12 )
            statement -> state = STATE_S11;

        statement -> prepared = 0;
    }
    else
    {
        statement -> state = STATE_S1;
    }

    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, 
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s2 ));

        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                statement -> msg );
    }

    return function_return( SQL_HANDLE_STMT, statement, ret );
}
Esempio n. 4
0
/* { dg-do compile } */
/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */

extern void (*bar) (void);

__attribute__ ((function_return("thunk-inline")))
int
foo (void)
{
  bar ();
  return 0;
}

/* { dg-final { scan-assembler-times {\tpause} 1 } } */
/* { dg-final { scan-assembler-times {\tlfence} 1 } } */
/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?bar" { target { { ! x32 } && *-*-linux* } } } } */
/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
/* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target { x32 } }  } } */
/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
Esempio n. 5
0
SQLRETURN SQLSetDescRec( SQLHDESC descriptor_handle,
           SQLSMALLINT rec_number, 
           SQLSMALLINT type,
           SQLSMALLINT subtype, 
           SQLLEN length,
           SQLSMALLINT precision, 
           SQLSMALLINT scale,
           SQLPOINTER data, 
           SQLLEN *string_length,
           SQLLEN *indicator )
{
    /*
     * not quite sure how the descriptor can be
     * allocated to a statement, all the documentation talks
     * about state transitions on statement states, but the
     * descriptor may be allocated with more than one statement
     * at one time. Which one should I check ?
     */
    DMHDESC descriptor = (DMHDESC) descriptor_handle;
    SQLRETURN ret;

    /*
     * check descriptor
     */

    if ( !__validate_desc( descriptor ))
    {
        dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: SQL_INVALID_HANDLE" );

        return SQL_INVALID_HANDLE;
    }

    function_entry( descriptor );

    thread_protect( SQL_HANDLE_DESC, descriptor );

    if ( descriptor -> connection -> state < STATE_C4 )
    {
        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: HY010" );

        __post_internal_error( &descriptor -> error,
                ERROR_HY010, NULL,
                descriptor -> connection -> environment -> requested_version );

        return function_return( SQL_HANDLE_DESC, descriptor, SQL_ERROR );
    }

    /*
     * check status of statements associated with this descriptor
     */

    if( __check_stmt_from_desc( descriptor, STATE_S8 ) ||
        __check_stmt_from_desc( descriptor, STATE_S9 ) ||
        __check_stmt_from_desc( descriptor, STATE_S10 ) ||
        __check_stmt_from_desc( descriptor, STATE_S11 ) ||
        __check_stmt_from_desc( descriptor, STATE_S12 )) {

        dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                "Error: HY010" );

        __post_internal_error( &descriptor -> error,
                ERROR_HY010, NULL,
                descriptor -> connection -> environment -> requested_version );

        return function_return( SQL_HANDLE_DESC, descriptor, SQL_ERROR );
    }

    if ( !CHECK_SQLSETDESCREC( descriptor -> connection ))
    {
        __post_internal_error( &descriptor -> error,
                ERROR_IM001, NULL,
                descriptor -> connection -> environment -> requested_version );

        return function_return( SQL_HANDLE_DESC, descriptor, SQL_ERROR ); 
    }

    ret = SQLSETDESCREC( descriptor -> connection,
            descriptor -> driver_desc,
            rec_number, 
            type,
            subtype, 
            length,
            precision, 
            scale,
            data, 
            string_length,
            indicator );

    return function_return( SQL_HANDLE_DESC, descriptor, ret );
}
Esempio n. 6
0
SQLRETURN __SQLFreeHandle( SQLSMALLINT handle_type,
        SQLHANDLE handle )
{
    switch( handle_type )
    {
      case SQL_HANDLE_ENV:
        {
            DMHENV environment = (DMHENV)handle;

            /*
             * check environment
             */

            if ( !__validate_env( environment ))
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: SQL_INVALID_HANDLE" );

                return SQL_INVALID_HANDLE;
            }
            
            function_entry( environment );

            if ( log_info.log_flag )
            {
                sprintf( environment -> msg,
                        "\n\t\tEntry:\n\t\t\tHandle Type = %d\n\t\t\tInput Handle = %p",
                        handle_type,
                        (void*)handle );

                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        environment -> msg );
            }

            thread_protect( SQL_HANDLE_ENV, environment );

            /*
             * check states
             */
            if ( environment -> state != STATE_E1 )
            {
                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        "Error: HY010" );

                __post_internal_error( &environment -> error,
                        ERROR_HY010, NULL,
                        environment -> requested_version );

                return function_return( SQL_HANDLE_ENV, environment, SQL_ERROR );
            }

            thread_release( SQL_HANDLE_ENV, environment );

            __release_env( environment );
            return SQL_SUCCESS;
        }
        break;

      case SQL_HANDLE_DBC:
        {
            DMHDBC connection = (DMHDBC)handle;
            DMHENV environment;

            /*
             * 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 );

            environment = connection -> environment;

            if ( log_info.log_flag )
            {
                sprintf( connection -> msg,
                        "\n\t\tEntry:\n\t\t\tHandle Type = %d\n\t\t\tInput Handle = %p",
                        handle_type,
                        (void*)handle );

                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        connection -> msg );
            }

            thread_protect( SQL_HANDLE_ENV, environment );

            /*
             * check states
             */
            if ( connection -> state != STATE_C2 )
            {
                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        "Error: HY010" );

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

                return function_return( SQL_HANDLE_ENV, environment, SQL_ERROR );
            }

            environment -> connection_count --;

            if ( environment -> connection_count == 0 )
            {
                environment -> state = STATE_E1;
            }

            environment = connection -> environment;

            __release_attr_str( &connection -> env_attribute );
            __release_attr_str( &connection -> dbc_attribute );
            __release_attr_str( &connection -> stmt_attribute );

            __disconnect_part_one( connection );

            __release_dbc( connection );

            if ( log_info.log_flag )
            {
                sprintf( environment -> msg,
                        "\n\t\tExit:[SQL_SUCCESS]" );

                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        environment -> msg );
            }
#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
            uodbc_update_stats(environment->sh, UODBC_STATS_TYPE_HDBC,
                               (void *)-1);
#endif

            thread_release( SQL_HANDLE_ENV, environment );

            return SQL_SUCCESS;
        }
        break;

      case SQL_HANDLE_STMT:
        {
            DMHSTMT statement = (DMHSTMT)handle;
            DMHDBC connection;
            SQLRETURN ret;

            /*
             * check statement
             */
            if ( !__validate_stmt( statement ))
            {
                dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            "Error: SQL_INVALID_HANDLE" );

                return SQL_INVALID_HANDLE;
            }

            function_entry( statement );

            connection = statement -> connection;

            if ( log_info.log_flag )
            {
                sprintf( statement -> msg,
                        "\n\t\tEntry:\n\t\t\tHandle Type = %d\n\t\t\tInput Handle = %p",
                        handle_type,
                        (void*)handle );

                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        statement -> msg );
            }

            thread_protect( SQL_HANDLE_STMT, statement );

            /*
             * check states
             */
            if ( statement -> state == STATE_S8 ||
                    statement -> state == STATE_S9 ||
                    statement -> state == STATE_S10 ||
                    statement -> state == STATE_S11 ||
                    statement -> state == STATE_S12 )
            {
                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        "Error: HY010" );

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

                return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
            }

            if ( !CHECK_SQLFREEHANDLE( statement -> connection ))
            {
                if ( !CHECK_SQLFREESTMT( statement -> connection ))
                {
                    dm_log_write( __FILE__,
                            __LINE__,
                            LOG_INFO,
                            LOG_INFO,
                            "Error: IM001" );

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

                    return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
                }
                else
                {
                    ret = SQLFREESTMT( statement -> connection,
                        statement -> driver_stmt,
                        SQL_DROP );
                }
            }
            else
            {
                ret = SQLFREEHANDLE( statement -> connection,
                        handle_type,
                        statement -> driver_stmt );
            }

            if ( SQL_SUCCEEDED( ret ))
            {
                /*
                 * break any association
                 */

                if ( statement -> ard ) {
                    statement -> ard -> associated_with = NULL;
                }
                if ( statement -> apd ) {
                    statement -> apd -> associated_with = NULL;
                }
                /*
                 * release the implicit descriptors, 
				 * this matches the tests in SQLAllocHandle
                 */
                if (( statement -> connection -> driver_act_ver == 3 &&
						CHECK_SQLGETSTMTATTR( connection )) ||
						CHECK_SQLGETSTMTATTRW( connection ))
                {
                    if ( statement -> implicit_ard )
                        __release_desc( statement -> implicit_ard );
                    if ( statement -> implicit_apd )
                        __release_desc( statement -> implicit_apd );
                    if ( statement -> implicit_ird )
                        __release_desc( statement -> implicit_ird );
                    if ( statement -> implicit_ipd )
                        __release_desc( statement -> implicit_ipd );
                }
                statement -> connection -> statement_count --;

                thread_release( SQL_HANDLE_STMT, statement );
#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
                uodbc_update_stats(connection->environment->sh,
                                   UODBC_STATS_TYPE_HSTMT, (void *)-1);
#endif

                __release_stmt( statement );
            }
            else
            {
                thread_release( SQL_HANDLE_STMT, statement );
            }

            if ( log_info.log_flag )
            {
                sprintf( connection -> msg,
                        "\n\t\tExit:[SQL_SUCCESS]" );

                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        connection -> msg );
            }

            return function_return( IGNORE_THREAD, connection, ret ); 
        }
        break;

      case SQL_HANDLE_DESC:
        {
            DMHDESC descriptor = (DMHDESC)handle;
            DMHDBC connection;
            SQLRETURN ret;

            /*
             * check descriptor
             */
            if ( !__validate_desc( descriptor ))
            {
                return SQL_INVALID_HANDLE;
            }

            function_entry( descriptor );

            connection = descriptor -> connection;

            if ( log_info.log_flag )
            {
                sprintf( descriptor -> msg,
                        "\n\t\tEntry:\n\t\t\tHandle Type = %d\n\t\t\tInput Handle = %p",
                        handle_type,
                        (void*)handle );

                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        descriptor -> msg );
            }

			if ( descriptor -> implicit )
			{
				dm_log_write( __FILE__,
						__LINE__,
						LOG_INFO,
						LOG_INFO,
						"Error: HY017" );
		
				__post_internal_error( &descriptor -> error,
						ERROR_HY017, NULL,
						connection -> environment -> requested_version );
		
				return function_return( IGNORE_THREAD, descriptor, SQL_ERROR );
			}
		
            thread_protect( SQL_HANDLE_DESC, descriptor );

            if ( !CHECK_SQLFREEHANDLE( connection ))
            {
                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        "Error: IM001" );

                __post_internal_error( &descriptor -> error,
                        ERROR_IM001, NULL,
                        connection -> environment -> requested_version );

                return function_return( SQL_HANDLE_DESC, descriptor, SQL_ERROR );
            }
            else
            {
                ret = SQLFREEHANDLE( connection,
                        handle_type,
                        descriptor -> driver_desc );
            }

            /*
             * check status of statements associated with this descriptor
             */

            if( __check_stmt_from_desc( descriptor, STATE_S8 ) ||
                __check_stmt_from_desc( descriptor, STATE_S9 ) ||
                __check_stmt_from_desc( descriptor, STATE_S10 ) ||
                __check_stmt_from_desc( descriptor, STATE_S11 ) ||
                __check_stmt_from_desc( descriptor, STATE_S12 )) {

                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: HY010" );

                __post_internal_error( &descriptor -> error,
                        ERROR_HY010, NULL,
                        descriptor -> connection -> environment -> requested_version );

                return function_return( SQL_HANDLE_DESC, descriptor, SQL_ERROR );
            }

            thread_release( SQL_HANDLE_DESC, descriptor );

            __release_desc( descriptor );

            if ( log_info.log_flag )
            {
                sprintf( connection -> msg,
                        "\n\t\tExit:[SQL_SUCCESS]" );

                dm_log_write( __FILE__,
                        __LINE__,
                        LOG_INFO,
                        LOG_INFO,
                        connection -> msg );
            }
#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
            uodbc_update_stats(connection->environment->sh,
                               UODBC_STATS_TYPE_HDESC, (void *)-1);
#endif

            return function_return( IGNORE_THREAD, connection, SQL_SUCCESS ); 
        }
        break;

      default:
        /*
         * there is nothing to report a error on
         */
        return SQL_ERROR;
    }
}
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 );
    }
Esempio n. 8
0
SQLRETURN __SQLAllocHandle( SQLSMALLINT handle_type,
           SQLHANDLE input_handle,
           SQLHANDLE *output_handle,
           SQLINTEGER requested_version )
{
    switch( handle_type )
    {
      case SQL_HANDLE_ENV:
        {
            DMHENV environment;
            char pooling_string[ 128 ];

            if ( !output_handle ) 
            {
                return SQL_ERROR;
            }

            if ( input_handle )
            {
                return SQL_INVALID_HANDLE;
            }

            /*
             * check connection pooling attributes
             */

            SQLGetPrivateProfileString( "ODBC", "Pooling", "0",
				pooling_string, sizeof( pooling_string ), 
                "ODBCINST.INI" );

            if ( pooling_string[ 0 ] == '1' ||
                toupper( pooling_string[ 0 ] ) == 'Y' ||
                ( toupper( pooling_string[ 0 ] ) == 'O' &&
                    toupper( pooling_string[ 1 ] ) == 'N' ))
            {
                pooling_enabled = 1;
            }
            else
            {
                pooling_enabled = 0;
            }

            if ( !( environment = __alloc_env()))
            {
                *output_handle = SQL_NULL_HENV;
                return SQL_ERROR;
            }
            *output_handle = (SQLHANDLE) environment;

            /*
             * setup environment state
             */

            environment -> state = STATE_E1;
            environment -> requested_version = requested_version;
        	environment -> sql_driver_count = -1;

            /*
             * if SQLAllocEnv is called then it's probable that
             * the application wants ODBC2.X type behaviour
             *
             * In this case we don't need to set the version via
             * SQLSetEnvAttr()
             *
             */

            environment -> connection_count = 0;

            return SQL_SUCCESS;
        }
        break;

      case SQL_HANDLE_DBC:
        {
            DMHENV environment = (DMHENV) input_handle;
            DMHDBC connection;

            if ( !__validate_env( environment ))
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: SQL_INVALID_HANDLE" );

                return SQL_INVALID_HANDLE;
            }

            if ( output_handle )
                *output_handle = SQL_NULL_HDBC;

            thread_protect( SQL_HANDLE_ENV, environment );

            function_entry(( void * ) input_handle );

            if ( log_info.log_flag )
            { 
                /*
                 * log that we are here
                 */

                sprintf( environment -> msg, 
                        "\n\t\tEntry:\n\t\t\tHandle Type = %d\n\t\t\tInput Handle = %p",
                        handle_type,
                        (void*)input_handle );

                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        environment -> msg );
            }

            if ( !output_handle )
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: HY009" );

                __post_internal_error( &environment -> error,
                        ERROR_HY009, NULL, 
                        SQL_OV_ODBC3 );

                return function_return( SQL_HANDLE_ENV, environment, SQL_ERROR );
            }

            /*
             * check that a version has been requested
             */

            if ( environment -> requested_version == 0 )
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: HY010" );

                __post_internal_error( &environment -> error,
                        ERROR_HY010, NULL,
                        SQL_OV_ODBC3 );

                *output_handle = SQL_NULL_HDBC;

                return function_return( SQL_HANDLE_ENV, environment, SQL_ERROR );
            }

            connection = __alloc_dbc();
            if ( !connection )
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: HY013" );

                __post_internal_error( &environment -> error,
                    ERROR_HY013, NULL,
                    environment -> requested_version );

                *output_handle = SQL_NULL_HDBC;

                return function_return( SQL_HANDLE_ENV, environment, SQL_ERROR );
            }

            /*
             * sort out the states
             */

            connection -> state = STATE_C2;
            if ( environment -> state == STATE_E1 )
            {
                environment -> state = STATE_E2;
            }
            environment -> connection_count ++;
            connection -> environment = environment;

            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_set = 0;
            connection -> async_enable = 0;
            connection -> async_enable_set = 0;
            connection -> auto_ipd = 0;
            connection -> auto_ipd_set = 0;
            connection -> connection_timeout = 0;
            connection -> connection_timeout_set = 0;
            connection -> metadata_id = 0;
            connection -> metadata_id_set = 0;
            connection -> packet_size = 0;
            connection -> packet_size_set = 0;
            connection -> quite_mode = 0;
            connection -> quite_mode_set = 0;
            connection -> txn_isolation = 0;
            connection -> txn_isolation_set = 0;
            strcpy( connection -> cli_year, "1995" );

            connection -> env_attribute.count = 0;
            connection -> env_attribute.list = NULL;
            connection -> dbc_attribute.count = 0;
            connection -> dbc_attribute.list = NULL;
            connection -> stmt_attribute.count = 0;
            connection -> stmt_attribute.list = NULL;
            connection -> save_attr = NULL;

#ifdef HAVE_ICONV
            connection -> iconv_cd_uc_to_ascii = (iconv_t)-1;
            connection -> iconv_cd_ascii_to_uc = (iconv_t)-1;
            strcpy( connection -> unicode_string, DEFAULT_ICONV_ENCODING );
#endif

            *output_handle = (SQLHANDLE) connection;

            if ( log_info.log_flag )
            {
                sprintf( environment -> msg, 
                        "\n\t\tExit:[SQL_SUCCESS]\n\t\t\tOutput Handle = %p",
                            connection );

                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        environment -> msg );
            }
#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
            uodbc_update_stats(environment->sh, UODBC_STATS_TYPE_HDBC,
                               (void *)1);
#endif

            thread_release( SQL_HANDLE_ENV, environment );
            return SQL_SUCCESS;
        }
        break;

      case SQL_HANDLE_STMT:
        {
            SQLRETURN ret, ret1;
            DMHDBC connection = (DMHDBC) input_handle;
            DMHSTMT statement;

            if ( !__validate_dbc( connection ))
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: SQL_INVALID_HANDLE" );

                return SQL_INVALID_HANDLE;
            }

            if ( output_handle )
                *output_handle = SQL_NULL_HSTMT;

            thread_protect( SQL_HANDLE_DBC, connection );

            function_entry(( void * ) input_handle );

            if ( log_info.log_flag )
            {
                sprintf( connection -> msg, 
                    "\n\t\tEntry:\n\t\t\tHandle Type = %d\n\t\t\tInput Handle = %p",
                    handle_type,
                    (void*)input_handle );

                dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    connection -> msg );
            }

            if ( !output_handle )
            {
                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 );
            }

            if ( connection -> state == STATE_C1 ||
                    connection -> state == STATE_C2 ||
                    connection -> state == STATE_C3 )
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: 08003" );

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

                *output_handle = SQL_NULL_HSTMT;

                return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
            }

            statement = __alloc_stmt();
            if ( !statement )
            {
                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: HY013" );

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

                *output_handle = SQL_NULL_HSTMT;

                return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
            }

            /*
             * pass the call on
             */

            if ( requested_version >= SQL_OV_ODBC3 )
            {
                if ( CHECK_SQLALLOCHANDLE( connection ))
                {
                    ret = SQLALLOCHANDLE( connection,
                            SQL_HANDLE_STMT,
                            connection -> driver_dbc,
                            &statement -> driver_stmt,
                            statement );

                    if ( !SQL_SUCCEEDED( ret ))
                        __release_stmt( statement );
                }
                else if ( CHECK_SQLALLOCSTMT( connection ))
                {
                    ret = SQLALLOCSTMT( connection,
                            connection -> driver_dbc,
                            &statement -> driver_stmt,
                            statement );

                    if ( !SQL_SUCCEEDED( ret ))
                        __release_stmt( statement );
                }
                else
                {
                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            "Error: IM003" );

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

                    __release_stmt( statement );

                    *output_handle = SQL_NULL_HSTMT;

                    return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                }
            }
            else
            {
                if ( CHECK_SQLALLOCSTMT( connection ))
                {
                    ret = SQLALLOCSTMT( connection,
                            connection -> driver_dbc,
                            &statement -> driver_stmt,
                            statement );

                    if ( !SQL_SUCCEEDED( ret ))
                        __release_stmt( statement );
                }
                else if ( CHECK_SQLALLOCHANDLE( connection ))
                {
                    ret = SQLALLOCHANDLE( connection,
                            SQL_HANDLE_STMT,
                            connection -> driver_dbc,
                            &statement -> driver_stmt,
                            statement );

                    if ( !SQL_SUCCEEDED( ret ))
                        __release_stmt( statement );
                }
                else
                {
                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            "Error: IM003" );

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

                    __release_stmt( statement );

                    *output_handle = SQL_NULL_HSTMT;
                
                    return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                }
            }

            if ( SQL_SUCCEEDED( ret ))
            {
                /*
                 * sort out the states
                 */

                statement -> state = STATE_S1;
                if ( connection -> state == STATE_C4 )
                    connection -> state = STATE_C5;

                __register_stmt ( connection, statement );

                *output_handle = (SQLHANDLE) statement;

                statement -> metadata_id = SQL_FALSE;

                /*
                 * if we are connected to a 3 driver then
                 * we need to get the 4 implicit descriptors
                 * so we know that they are valid
                 */

                if ( connection -> driver_act_ver == 3 &&
                        CHECK_SQLGETSTMTATTR( connection ))
                {
                    DRV_SQLHDESC desc;

                    /*
                     * ARD
                     */

                    ret1 = SQLGETSTMTATTR( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_APP_ROW_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> ard = __alloc_desc();
                        if ( !statement -> ard )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            __release_stmt( statement );

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_ard = statement -> ard;
                        statement -> ard -> implicit = 1;
                        statement -> ard -> associated_with = statement;
                        statement -> ard -> state = STATE_D1i;
                        statement -> ard -> driver_desc = desc;
                        statement -> ard -> connection = connection;
                    }

                    /*
                     * APD
                     */

                    ret1 = SQLGETSTMTATTR( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_APP_PARAM_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> apd = __alloc_desc();
                        if ( !statement -> apd )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            *output_handle = SQL_NULL_HSTMT;

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_apd = statement -> apd;
                        statement -> apd -> implicit = 1;
                        statement -> apd -> associated_with = statement;
                        statement -> apd -> state = STATE_D1i;
                        statement -> apd -> driver_desc = desc;
                        statement -> apd -> connection = connection;
                    }

                    /*
                     * IRD
                     */

                    ret1 = SQLGETSTMTATTR( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_IMP_ROW_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> ird = __alloc_desc();
                        if ( !statement -> ird )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            __release_stmt( statement );

                            *output_handle = SQL_NULL_HSTMT;

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_ird = statement -> ird;
                        statement -> ird -> implicit = 1;
                        statement -> ird -> associated_with = statement;
                        statement -> ird -> state = STATE_D1i;
                        statement -> ird -> driver_desc = desc;
                        statement -> ird -> connection = connection;
                    }

                    /*
                     * IPD
                     */

                    ret1 = SQLGETSTMTATTR( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_IMP_PARAM_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> ipd = __alloc_desc();
                        if ( !statement -> ipd )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            *output_handle = SQL_NULL_HSTMT;

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_ipd = statement -> ipd;
                        statement -> ipd -> implicit = 1;
                        statement -> ipd -> associated_with = statement;
                        statement -> ipd -> state = STATE_D1i;
                        statement -> ipd -> driver_desc = desc;
                        statement -> ipd -> connection = connection;
                    }
                }
                /* Driver may only have unicode API's */
                else if ( CHECK_SQLGETSTMTATTRW( connection ))
                {
                    DRV_SQLHDESC desc;

                    /*
                     * ARD
                     */

                    ret1 = SQLGETSTMTATTRW( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_APP_ROW_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> ard = __alloc_desc();
                        if ( !statement -> ard )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            __release_stmt( statement );

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_ard = statement -> ard;
                        statement -> ard -> implicit = 1;
                        statement -> ard -> associated_with = statement;
                        statement -> ard -> state = STATE_D1i;
                        statement -> ard -> driver_desc = desc;
                        statement -> ard -> connection = connection;
                    }

                    /*
                     * APD
                     */

                    ret1 = SQLGETSTMTATTRW( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_APP_PARAM_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> apd = __alloc_desc();
                        if ( !statement -> apd )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            *output_handle = SQL_NULL_HSTMT;

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_apd = statement -> apd;
                        statement -> apd -> implicit = 1;
                        statement -> apd -> associated_with = statement;
                        statement -> apd -> state = STATE_D1i;
                        statement -> apd -> driver_desc = desc;
                        statement -> apd -> connection = connection;
                    }

                    /*
                     * IRD
                     */

                    ret1 = SQLGETSTMTATTRW( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_IMP_ROW_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> ird = __alloc_desc();
                        if ( !statement -> ird )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            __release_stmt( statement );

                            *output_handle = SQL_NULL_HSTMT;

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_ird = statement -> ird;
                        statement -> ird -> implicit = 1;
                        statement -> ird -> associated_with = statement;
                        statement -> ird -> state = STATE_D1i;
                        statement -> ird -> driver_desc = desc;
                        statement -> ird -> connection = connection;
                    }

                    /*
                     * IPD
                     */

                    ret1 = SQLGETSTMTATTRW( connection,
                            statement -> driver_stmt,
                            SQL_ATTR_IMP_PARAM_DESC,
                            &desc,
                            sizeof( desc ),
                            NULL );

                    if ( SQL_SUCCEEDED( ret1 ))
                    {
                        /*
                         * allocate one of our descriptors
                         * to wrap around this
                         */
                        statement -> ipd = __alloc_desc();
                        if ( !statement -> ipd )
                        {
                            dm_log_write( __FILE__, 
                                __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: HY013" );

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

                            *output_handle = SQL_NULL_HSTMT;

                            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
                        }
                        statement -> implicit_ipd = statement -> ipd;
                        statement -> ipd -> implicit = 1;
                        statement -> ipd -> associated_with = statement;
                        statement -> ipd -> state = STATE_D1i;
                        statement -> ipd -> driver_desc = desc;
                        statement -> ipd -> connection = connection;
                    }
                } 
            }

            /*
             * set any preset statement attributes
             */

            if ( SQL_SUCCEEDED( ret ))
            {
                __set_attributes( statement, SQL_HANDLE_STMT );
            }

            if ( log_info.log_flag )
            {
                sprintf( connection -> msg, 
                        "\n\t\tExit:[SQL_SUCCESS]\n\t\t\tOutput Handle = %p",
                        statement );

                dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        connection -> msg );
            }
#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
            uodbc_update_stats(connection->environment->sh,
                               UODBC_STATS_TYPE_HSTMT, (void *)1);
#endif

            return function_return( SQL_HANDLE_DBC, connection, ret );
        }
        break;

      case SQL_HANDLE_DESC:
        {
        SQLRETURN ret;
        DMHDBC connection = (DMHDBC) input_handle;
        DMHDESC descriptor;

        if ( !__validate_dbc( connection ))
        {
            dm_log_write( __FILE__, 
                        __LINE__, 
                        LOG_INFO, 
                        LOG_INFO, 
                        "Error: SQL_INVALID_HANDLE" );

            return SQL_INVALID_HANDLE;
        }

        if ( output_handle )
            *output_handle = SQL_NULL_HDESC;

        thread_protect( SQL_HANDLE_DBC, connection );

        function_entry(( void * ) input_handle );

        if ( log_info.log_flag )
        {
            sprintf( connection -> msg, 
                "\n\t\tEntry:\n\t\t\tHandle Type = %d\n\t\t\tInput Handle = %p",
                handle_type,
                (void*)input_handle );

            dm_log_write( __FILE__, 
                __LINE__, 
                LOG_INFO, 
                LOG_INFO, 
                connection -> msg );
        }

        if ( !output_handle )
        {
            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 );
        }

        if ( connection -> state == STATE_C1 ||
                connection -> state == STATE_C2 ||
                connection -> state == STATE_C3 )
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: 08003" );

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

            *output_handle = SQL_NULL_HDESC;

            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
        }

        descriptor = __alloc_desc();
        if ( !descriptor )
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: HY013" );

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

            *output_handle = SQL_NULL_HDESC;

            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
        }

        /*
         * pass the call on
         */

        if ( CHECK_SQLALLOCHANDLE( connection ))
        {
            ret = SQLALLOCHANDLE( connection,
                    SQL_HANDLE_DESC,
                    connection -> driver_dbc,
                    &descriptor -> driver_desc,
                    NULL );

            if ( !SQL_SUCCEEDED( ret ))
                __release_desc( descriptor );
        }
        else
        {
            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    "Error: IM003" );

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

            __release_desc( descriptor );

            *output_handle = SQL_NULL_HDESC;

            return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
        }

        if ( SQL_SUCCEEDED( ret ))
        {
            /*
             * sort out the states
             */

            descriptor -> state = STATE_D1e;
            descriptor -> implicit = 0;
            descriptor -> associated_with = NULL;

            connection -> statement_count ++;

            descriptor -> connection = connection;

            *output_handle = (SQLHANDLE) descriptor;
        }

        if ( log_info.log_flag )
        {
            sprintf( connection -> msg, 
                    "\n\t\tExit:[SQL_SUCCESS]\n\t\t\tOutput Handle = %p",
                    descriptor );

            dm_log_write( __FILE__, 
                    __LINE__, 
                    LOG_INFO, 
                    LOG_INFO, 
                    connection -> msg );
        }
#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
        uodbc_update_stats(connection->environment->sh, UODBC_STATS_TYPE_HDESC,
                           (void *)1);
#endif

        return function_return( SQL_HANDLE_DBC, connection, ret );
        }
        break;

      default:
		if ( __validate_env( (DMHENV) input_handle ))
		{
			DMHENV environment = (DMHENV) input_handle;

            thread_protect( SQL_HANDLE_ENV, environment );

			__post_internal_error( &environment -> error,
						ERROR_HY092, NULL,
						environment -> requested_version );

			return function_return( SQL_HANDLE_ENV, environment, SQL_ERROR );
		}
		else if ( __validate_dbc( (DMHDBC) input_handle ))
		{
			DMHDBC connection = (DMHDBC) input_handle;

            thread_protect( SQL_HANDLE_DBC, connection );

			__post_internal_error( &connection -> error,
					ERROR_HY092, NULL,
					connection -> environment -> requested_version );
	
			return function_return( SQL_HANDLE_DBC, connection, SQL_ERROR );
		}
		else
		{
			return SQL_ERROR;
		}
		break;
    }
}
Esempio n. 9
0
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 );
    }
Esempio n. 10
0
SQLRETURN SQLCancelHandle( SQLSMALLINT HandleType, SQLHANDLE Handle )
{
    SQLRETURN ret;
    SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];

    switch ( HandleType ) {
        case SQL_HANDLE_STMT:
            {
                DMHSTMT statement = (DMHSTMT) Handle;
                /*
                 * check statement
                 */
                if ( !__validate_stmt( statement ))
                {
                    dm_log_write( __FILE__, 
                            __LINE__, 
                                LOG_INFO, 
                                LOG_INFO, 
                                "Error: SQL_INVALID_HANDLE" );

                    return SQL_INVALID_HANDLE;
                }

                function_entry( statement );

                if ( log_info.log_flag )
                {
                    sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p",
                            statement );

                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            statement -> msg );
                }

#if defined( HAVE_LIBPTH ) || defined( HAVE_LIBPTHREAD ) || defined( HAVE_LIBTHREAD )
                /*
                 * Allow this past the thread checks if the driver is at all thread safe, as SQLCancel can 
                 * be called across threads
                 */
                if ( statement -> connection -> protection_level == 3 ) 
                {
                    thread_protect( SQL_HANDLE_STMT, statement ); 
                }
#endif

                /*
                 * check states
                 */

                if ( !CHECK_SQLCANCEL( statement -> connection ))
                {
                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            "Error: IM001" );

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

#if defined( HAVE_LIBPTH ) || defined( HAVE_LIBPTHREAD ) || defined( HAVE_LIBTHREAD )
                    if ( statement -> connection -> protection_level == 3 ) 
                    {
                        return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
                    }
                    else 
                    {
                        return function_return( IGNORE_THREAD, statement, SQL_ERROR );
                    }
#else 
                    return function_return( IGNORE_THREAD, statement, SQL_ERROR );
#endif
                }

                ret = SQLCANCEL( statement -> connection,
                        statement -> driver_stmt );

                if ( SQL_SUCCEEDED( ret ))
                {
                    if ( statement -> state == STATE_S8 ||
                        statement -> state == STATE_S9 ||
                        statement -> state == STATE_S10 ||
                        statement -> state == STATE_S13 ||
                        statement -> state == STATE_S14 ||
                        statement -> state == STATE_S10 )
                    {
                        if ( statement -> interupted_func == SQL_API_SQLEXECDIRECT )
                        {
                            statement -> state = STATE_S1;
                        }
                        else if ( statement -> interupted_func == SQL_API_SQLEXECUTE )
                        {
                            if ( statement -> hascols )
                            {
                                statement -> state = STATE_S3;
                            }
                            else
                            {
                                statement -> state = STATE_S2;
                            }
                        }
                        else if ( statement -> interupted_func ==
                                SQL_API_SQLBULKOPERATIONS )
                        {
                            if ( statement -> interupted_state == STATE_S5 ||
                                    statement -> interupted_state == STATE_S6 ||
                                    statement -> interupted_state == STATE_S7 )
                            {
                                statement -> state = STATE_S6;
                                statement -> eod = 0;
                            }
                            else
                            {
                                statement -> state = STATE_S6;
                                statement -> eod = 0;
                            }
                        }
                        else if ( statement -> interupted_func ==
                                SQL_API_SQLSETPOS )
                        {
                            if ( statement -> interupted_state == STATE_S5 ||
                                    statement -> interupted_state == STATE_S6 )
                            {
                                statement -> state = STATE_S6;
                                statement -> eod = 0;
                            }
                            else if ( statement -> interupted_state == STATE_S7 )
                            {
                                statement -> state = STATE_S7;
                            }
                        }
                    }
                    else if ( statement -> state == STATE_S11 ||
                            statement -> state == STATE_S12 )
                    {
                        statement -> state = STATE_S12;
                    }
                    else {  /* Same action as SQLFreeStmt( SQL_CLOSE ) */
                        if ( statement -> state == STATE_S4 )
                        {
                            if ( statement -> prepared )
                                statement -> state = STATE_S2;
                            else
                                statement -> state = STATE_S1;
                        }
                        else
                        {
                            if ( statement -> prepared )
                                statement -> state = STATE_S3;
                            else
                                statement -> state = STATE_S1;
                        }
                        statement -> hascols = 0;
                    }
                }

                if ( log_info.log_flag )
                {
                    sprintf( statement -> msg, 
                            "\n\t\tExit:[%s]",
                                __get_return_status( ret, s1 ));

                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            statement -> msg );
                }

#if defined( HAVE_LIBPTH ) || defined( HAVE_LIBPTHREAD ) || defined( HAVE_LIBTHREAD )
                if ( statement -> connection -> protection_level == 3 ) 
                {
                    return function_return( SQL_HANDLE_STMT, statement, SQL_ERROR );
                }
                else 
                {
                    return function_return( IGNORE_THREAD, statement, ret );
                }
#else
                return function_return( IGNORE_THREAD, statement, ret );
#endif
            }
            break;

        case SQL_HANDLE_DBC:
            {
                DMHDBC connection = (DMHDBC) 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",
                            connection );

                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            connection -> msg );
                }

                /*
                 * check states
                 */

                if ( !CHECK_SQLCANCELHANDLE( connection ))
                {
                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            "Error: IM001" );

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

                    return function_return( IGNORE_THREAD, connection, SQL_ERROR );
                }

                ret = SQLCANCELHANDLE( connection, SQL_HANDLE_DBC,
                        connection -> driver_dbc );

                /*
                 * The effect this has on connection states is not defined AFAIKS
                 */

                if ( log_info.log_flag )
                {
                    sprintf( connection -> msg, 
                            "\n\t\tExit:[%s]",
                                __get_return_status( ret, s1 ));

                    dm_log_write( __FILE__, 
                            __LINE__, 
                            LOG_INFO, 
                            LOG_INFO, 
                            connection -> msg );
                }

                return function_return( IGNORE_THREAD, connection, ret );
            }
            break;

        default:
            return SQL_INVALID_HANDLE;
            break;
    }
}
Esempio n. 11
0
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 );
    }