Пример #1
0
DMHDBC __alloc_dbc( void )
{
    DMHDBC connection = NULL;

    mutex_entry( &mutex_lists );

    connection = calloc( sizeof( *connection ), 1 );

    if ( connection )
    {
        /*
         * add to list of connection handles
         */

        connection -> next_class_list = connection_root;
        connection_root = connection;
        connection -> type = HDBC_MAGIC;

        setup_error_head( &connection -> error, connection,
                SQL_HANDLE_DBC );

#ifdef HAVE_LIBPTH
        pth_mutex_init( &connection -> mutex );
        /*
         * for the moment protect at the environment level
         */
        connection -> protection_level = TS_LEVEL3;
#elif HAVE_LIBPTHREAD
        pthread_mutex_init( &connection -> mutex, NULL );
        /*
         * for the moment protect at the environment level
         */
        connection -> protection_level = TS_LEVEL3;
#elif HAVE_LIBTHREAD
        mutex_init( &connection -> mutex, USYNC_THREAD, NULL );
        connection -> protection_level = TS_LEVEL3;
#endif

    }

    mutex_exit( &mutex_lists );

    return connection;
}
Пример #2
0
DMHSTMT __alloc_stmt( void )
{
    DMHSTMT statement = NULL;

    mutex_entry( &mutex_lists );

    statement = calloc( sizeof( *statement ), 1 );

    if ( statement )
    {
        /*
         * add to list of statement handles
         */

        statement -> next_class_list = statement_root;
#ifdef FAST_HANDLE_VALIDATE
        if ( statement_root )
        {
            statement_root -> prev_class_list = statement;
        }
#endif    
        statement_root = statement;
        statement -> type = HSTMT_MAGIC;

        setup_error_head( &statement -> error, statement,
                SQL_HANDLE_STMT );

#ifdef HAVE_LIBPTH
        pth_mutex_init( &statement -> mutex );
#elif HAVE_LIBPTHREAD
        pthread_mutex_init( &statement -> mutex, NULL );
#elif HAVE_LIBTHREAD
        mutex_init( &statement -> mutex, USYNC_THREAD, NULL );
#endif

    }

    mutex_exit( &mutex_lists );

    return statement;
}
Пример #3
0
DMHDESC __alloc_desc( void )
{
    DMHDESC descriptor = NULL;

    mutex_entry( &mutex_lists );

    descriptor = calloc( sizeof( *descriptor ), 1 );

    if ( descriptor )
    {
        /*
         * add to list of descriptor handles
         */

        descriptor -> next_class_list = descriptor_root;
#ifdef FAST_HANDLE_VALIDATE
        if ( descriptor_root )
        {
            descriptor_root -> prev_class_list = descriptor;
        }
#endif    
        descriptor_root = descriptor;
        descriptor -> type = HDESC_MAGIC;
    }

    setup_error_head( &descriptor -> error, descriptor,
            SQL_HANDLE_DESC );

#ifdef HAVE_LIBPTH
    pth_mutex_init( &descriptor -> mutex );
#elif HAVE_LIBPTHREAD
    pthread_mutex_init( &descriptor -> mutex, NULL );
#elif HAVE_LIBTHREAD
    mutex_init( &descriptor -> mutex, USYNC_THREAD, NULL );
#endif

    mutex_exit( &mutex_lists );

    return descriptor;
}
Пример #4
0
DMHENV __alloc_env( void )
{
    DMHENV environment = NULL;

    mutex_entry( &mutex_lists );

    environment = calloc( sizeof( *environment ), 1 );

    if ( environment )
    {
        char tracing_string[ 64 ];
        char tracing_file[ 64 ];

#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
        if (uodbc_open_stats(&environment->sh, UODBC_STATS_WRITE) != 0)
        {
            ;
        }
        uodbc_update_stats(environment->sh, UODBC_STATS_TYPE_HENV, (void *)1);
#endif
        
        /*
         * add to list of env handles
         */

        environment -> next_class_list = enviroment_root;
        enviroment_root = environment;
        environment -> type = HENV_MAGIC;

        SQLGetPrivateProfileString( "ODBC", "Trace", "No",
                    tracing_string, sizeof( tracing_string ), 
                    "odbcinst.ini" );

        if ( tracing_string[ 0 ] == '1' ||
                toupper( tracing_string[ 0 ] ) == 'Y' ||
                    ( toupper( tracing_string[ 0 ] ) == 'O' &&
                    toupper( tracing_string[ 1 ] ) == 'N' ))
        {
            SQLGetPrivateProfileString( "ODBC", "TraceFile", "/tmp/sql.log",
                    tracing_file, sizeof( tracing_file ), 
                    "odbcinst.ini" );

            /*
             * start logging
             */

            SQLGetPrivateProfileString( "ODBC", "TracePid", "No",
                    tracing_string, sizeof( tracing_string ), 
                    "odbcinst.ini" );

            if ( tracing_string[ 0 ] == '1' ||
                        toupper( tracing_string[ 0 ] ) == 'Y' ||
                        ( toupper( tracing_string[ 0 ] ) == 'O' &&
                        toupper( tracing_string[ 1 ] ) == 'N' ))
            {
                dm_log_open( "ODBC", tracing_file, 1 );
            }
            else
            {
                dm_log_open( "ODBC", tracing_file, 0 );
            }

            sprintf( environment -> msg,
                    "\n\t\tExit:[SQL_SUCCESS]\n\t\t\tEnvironment = %p",	environment );

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

    setup_error_head( &environment -> error, environment,
            SQL_HANDLE_ENV );

    mutex_exit( &mutex_lists );

    return environment;
}