The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

   BridgeServer.pm - Server for remote UnixODBC clients.

SYNOPSIS

    use UnixODBC::BridgeServer;
    &UnixODBC::BridgeServer::main();

DESCRIPTION

The API function names correspond to the ODBC functions in UnixODBC.pm. Instead of setting multiple parameters as in the C library functions, the bridge API functions return multiple parameters as a list.

Application Programming Interface

ODBC Return Values

    The ODBC API defines these return values for the status of function
    calls.

    Perl Variable                   Numeric Value
    -------------                   -------------
    $SQL_NULL_DATA                  -1
    $SQL_DATA_AT_EXEC               -2
    $SQL_SUCCESS                    0
    $SQL_SUCCESS_WITH_INFO          1
    $SQL_NO_DATA                    100
    $SQL_NO_DATA_FOUND              100
    $SQL_ERROR                      -1
    $SQL_INVALID_HANDLE             -2
    $SQL_STILL_EXECUTING            2
    $SQL_NEED_DATA                  99

Methods in the UnixODBC::BridgeServer API

$c is an instance of a UnixODBC client connected to a UnixODBC server. Refer to the example scripts for sample applications.

dm_log_open ($appname, $logfilename)

   Opens a log file on the remote server.  You must have 
   write privileges in that directory.

   Returns 0;

   $c -> dm_log_open ('ODBC Bridge', '/tmp/odbcbridge.log');

dm_log_close

   Closes the log file on the remote server.

   $c -> dm_log_close;

sql_alloc_handle ($handle_type, $parent_handle)

    Returns the new handle, or undef on error.

    # Allocate an environment handle

    $evh = $c -> sql_alloc_handle ($SQL_HANDLE_ENV, $SQL_NULL_HANDLE);

    # Allocate a connection handle

    $cnh = $c -> sql_alloc_handle ($SQL_HANDLE_DBC, $evh);

    # Allocate a statement handle

    $sth = $c -> sql_alloc_handle ($SQL_HANDLE_STMT, $cnh);

sql_cancel ($sth)

    Returns the ODBC API return value.

    $r = $c -> sql_cancel ($sth);

sql_col_attribute ($sth, $colno, $attr, $maxlen)

    Returns a list of
    - SQL return value
    - Text attribute if any
    - Length of text attribute
    - Numeric attribute

    ($r, $text, $textlen, $num) = 
        $c -> sql_col_attribute ($sth, 1, $SQL_COLUMN_NAME, 255);

sql_columns ($sth, $catalog, $catalog_length, $schema, $schema_length, $titles, $titles_length, $type, $type_length)

    Returns the ODBC API return value.

    # Retrieve and print all column names for table named $table
    $r = $c -> sql_columns ($sth, '', 0, '', 0, 
                            "$table", length($table), '' 0);
    while (1) {
        $r = $c -> sql_fetch ($sth);
        last if $r == $SQL_NO_DATA;
        if ($r != $SQL_SUCCESS) {
            ($r, $sqlstate, $native, $text, $textlen) = 
                $c -> sql_get_diag_rec ($SQL_HANDLE_STMT, $sth, 1, 255);
            print "[sql_fetch]$text\n";
            return 1;
        } 

        # Column names are the fourth column of the result set.
        ($r, $text, $textlen) = 
            $c -> sql_get_data ($sth, 4, $SQL_C_CHAR, 255);
        last if $r == $SQL_NO_DATA;
        print "$text\n";
        if ($r != $SQL_SUCCESS) {
            ($r, $sqlstate, $native, $text, $textlen) = 
                $c -> sql_get_diag_rec ($SQL_HANDLE_STMT, $sth, 1, 255);
            print "[sql_get_data]$text\n";
            return 1;
        } 
    }

sql_connect ($cnh, $dsn, $username, $username_len, $password, $password_len)

    Returns the ODBC API return value.

    $r = $c -> sql_connect ($cnh, 'Customers', 
                      'joe', length('joe'),
                      'password', length('password'));

sql_data_sources ($evh, $order, $maxlength1, $maxlength2);

    Returns a list of
    - ODBC API return value.
    - DSN name.
    - Length of DSN name text.
    - Name of DBMS Driver for DSN.
    - Length of driver text.

    ($r, $dsnname, $dsnlength, $drivername, $drivernamelength) = 
      $c -> sql_data_sources ( $evh, $SQL_FETCH_FIRST, 
                               $messagelength1, 
                               $messagelength2 );

sql_describe_col ($sth, $colno, $maxlen)

    Returns a list of 
    - SQL API return value
    - Column name
    - Name length
    - Data type
    - Size
    - Decimal digits
    - Nullable

    ($r, $name, $namelength, $type, $size, $decimal_digits, $nullable) 
       = $c -> sql_describe_col ($sth, 1, 255);

sql_disconnect ($cnh)

    Returns the ODBC API return value.

    $r = sql_disconnect ($cnh);

sql_drivers ($evh, $order, $desc_max_len, $attr_max_len)

    Returns a list of: 
    - SQL API return value
    - Driver description string
    - Driver description string length
    - Attribute description string
    - Attribute description string length

    my ($r, $desc, $desc_len, $attr, $attr_len) =
        sql_drivers ($evh, $order, $desc_max_len, $attr_max_len);

sql_end_tran ($handle_type, $handle, $completion_type)

    Returns the ODBC API return value.

    $r = sql_end_tran ($SQL_HANDLE_STMT, $sth, 0);

sql_exec_direct ($sth, $query, $querylength)

    Returns the ODBC SQL return value

    $r = $c -> sql_exec_direct ($sth, $query, length ($query));

sql_execute ($sth)

    Returns the ODBC API return value

    $r = $c -> sql_execute ($sth);

sql_fetch ($sth)

    Returns the ODBC API return value.

    $r = sql_fetch ($sth);

sql_fetch_scroll ($sth, $order, $offset);

    Returns the ODBC API return value.

    $r = &UnixODBC::SQLFetchScroll ($sth, $SQL_FETCH_NEXT, $row++);

sql_foreign_keys ($sth, $catalog, $catalog_length, $schema, $schema_length, $table, $table_length, $foreign_catalog, $foreign_catalog_length, $foreign_schema, $foreign_schema_length, $foreign_table, $foreign_table_length)

    Returns the ODBC API return value.

    $r = $c -> sql_foreign_keys ($sth, '', 0, '', 0, $table, length ($table),
                                 '', 0, '', 0, $foreign_table, 
                                 length ($foreign_table));

sql_free_connect ($cnh)

    Returns the ODBC API return value.

    $r = $c -> sql_free_connect ($cnh);

sql_free_handle ($handle_type, $handle)

    Returns the ODBC API return value.

    # Free environment handle

    $r = $c -> sql_free_handle ($SQL_HANDLE_ENV, $evh);

    # Free connection handle

    $r = $c -> sql_free_handle ($SQL_HANDLE_DBC, $cnh);

    # Free statement handle

    $r = $c -> sql_free_handle ($SQL_HANDLE_STMT, $sth);

sql_get_cursor_name ($sth, $maxlen)

    Returns a list of 
    - API return value
    - Cursor name
    - Length of cursor name

    ($r, $cursorname, $length) = 
       $c -> sql_get_cursor_name ($sth, 255);

sql_get_data ($sth, $colno, $datatype, $maxlen)

    Returns a list of
    - API return value
    - Result text
    - Result text length

    ($r, $text, $len) = sql_get_data ($sth, 1, $SQL_C_CHAR, 255);

sql_get_diag_field ($handle_type, $handle, $fieldno, $maxlen)

    Returns a list of
    - API return value
    - Server native error
    - ODBC error
    - ODBC error length

    ($r, $native, $text, $textlen) = 
       $c -> sql_get_diag_field ($SQL_HANDLE_STMT, $sth, 1, 255);

sql_get_diag_rec ($handle_type, $handle, $recno, $maxlength)

   Returns a list of: 
    - API return value
    - SQL state
    - DBMS error number
    - Error text
    - Error text length

    If the return value is $SQL_NO_DATA, the remaining list elements
    are empty.

   ($r, $sqlstate, $native, $text, $textlen) = 
       $c -> sql_get_diag_rec ($SQL_HANDLE_ENV, $evh, 1, 255);

sql_get_functions ($cnh, $function);

    Returns a list of 
    - API return value
    - Non-zero if function is supported, zero if not supported.

    my ($r, $s) = $c -> sql_get_functions ($cnh, $SQL_API_SQLALLOCHANDLESTD);

sql_get_type_info ($sth, $type)

    Returns the ODBC API return value.

    $r = $c -> sql_get_type_info ($sth, $SQL_ALL_TYPES);

sql_more_results ($sth)

    Returns the ODBC API return value.

    $r = $c -> sql_more_results ($sth);

sql_native_sql ($cnh, $query, $querylength, $maxlen)

    Returns a list of 
    - API return value
    - Translated SQL query
    - Length of translated query

    ($r, $nativequery, $length) = 
       $c -> sql_native_sql ($cnh, $query, length ($query), 255);

sql_num_result_columns ($sth)

    Returns a list of 
    - API return value
    - Number of columns in result set

    ($r, $ncols) = sql_num_result_columns ($sth);

sql_prepare ($sth, $query, $querylength)

    Returns the ODBC API value.

    $r = $c -> sql_prepare ($sth, $query, length ($query) );

sql_procedure_columns ($sth, $catalog, $catalog_length, $schema, $schema_length, $proc, $proc_length, $column, $column_length);

    Returns the ODBC API return value.

    $r = $c -> sql_procedure_columns ($sth, '', 0, '', 0, '', 0, '', 0);

sql_procedures ($sth, $catalog, $catalog_length, $schema, $schema_length, $proc, $proc_length);

    Returns the ODBC API return value.

    $r = &UnixODBC::SQLProcedures ($sth, '', 0, '', 0, '', 0);

sql_row_count ($sth)

    Returns a list of
    - API return value
    - Number of rows in result set

    ($r, $nrows) = sql_row_count ($sth);

sql_set_cursor_name ($sth, $cursorname, $length)

    Returns the ODBC API return value.

    $r = $c -> sql_set_cursor_name ($sth, 'cursor', length('cursor'));

sql_set_env_attr ($evh, $attribute, $value, $strlen)

    Returns the ODBC function return value.

    $r = sql_set_env_attr ($evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0);

sql_set_pos ($sth, $row, $order, $lock)

    Returns the ODBC API return value.

    $r = $c -> sql_set_pos ($sth, 1, $SQL_POSITION, $SQL_LOCK_NO_CHANGE);

sql_special_columns ($sth, $id_type, $catalog, $catalog_length, $schema, $schema_length, $table, $table_length, $scope, $nullable)

    Returns the ODBC API return value.

    $r = sql_special_columns ($sth, $SQL_ROWVER, '', 0, '', 0, 'titles', 6,
                              $SQL_SCOPE_CURROW, 0);

sql_statistics ($sth, $catalog, $catalog_length, $schema, $schema_length, $table, $table_length, $unique, $reserved)

    Returns the ODBC API return value.

    $r = $c -> sql_statistics ($sth, '', 0, '', 0, '', 0, 1, 1);

sql_table_privileges ($sth, $catalog, $catalog_length, $schema, $schema_length, $table, $table_length)

    Returns the ODBC API return value.

    $r = $c -> sql_table_privileges ($sth, '', 0, '', 0, '', 0);
    

sql_tables ($sth, $cat_name, $cat_name_len, $schema_name, $schema_name_len, $table_name, $table_name_len, $table_type, $table_type_len)

    Returns SQL API return value.  ODBC Level 3 drivers can specify
    wildcards.  Calls to sql_fetch and sql_get_data return a result
    set of:

    - Catalog name
    - Schema name
    - Table name
    - Table type
    - Remarks

    # Print the names of all tables of a DSN
    $r = sql_tables ($sth, '', 0, '', 0, '', 0, '' 0);
    while (1) {
        $r = $c -> sql_fetch ($sth);
        last if $r == $SQL_NO_DATA;
        ($r, $text, $textlen) = 
            $c -> sql_get_data ($sth, 3, $SQL_C_CHAR, 255);
        if ($r != $SQL_SUCCESS) {
            ($r, $sqlstate, $native, $text, $textlen) = 
                $c -> sql_get_diag_rec ($SQL_HANDLE_STMT, $sth, 1, 255);
            print "Error: [sql_get_data]$text\n";
        } 
        print "$text\n";
    }

VERSION INFORMATION AND CREDITS

UnixODBC::BridgeServer.pm is part of the UnixODBC package.

Version: 0.19

Written by: Robert Allan Kiesling <rkiesling@earthlink.net>

SEE ALSO

perl(1), tkdm(1), UnixODBC(3).