Class: Sequel::ODBC::Database

Class | Sequel::ODBC::Database
In: | lib/sequel_core/adapters/odbc.rb
Parent: | Sequel::Database

### Methods

connect dataset do execute execute_dui new transaction

### Constants

GUARDED_DRV_NAME | = | /^\{.+\}$/.freeze
DRV_NAME_GUARDS | = | '{%s}'.freeze

### Public Class methods

new(opts)

[Source]

        # File lib/sequel_core/adapters/odbc.rb, line 11
    11:       def initialize(opts)
    12:         super(opts)
    13:         case opts[:db_type]
    14:         when 'mssql'
    15:           require 'sequel_core/adapters/shared/mssql'
    16:           extend Sequel::MSSQL::DatabaseMethods
    17:         when 'progress'
    18:           require 'sequel_core/adapters/shared/progress'
    19:           extend Sequel::Progress::DatabaseMethods
    20:         end
    21:       end

### Public Instance methods

connect(server)

[Source]

        # File lib/sequel_core/adapters/odbc.rb, line 23
    23:       def connect(server)
    24:         opts = server_opts(server)
    25:         if opts.include? :driver
    26:           drv = ::ODBC::Driver.new
    27:           drv.name = 'Sequel ODBC Driver130'
    28:           opts.each do |param, value|
    29:             if :driver == param and not (value =~ GUARDED_DRV_NAME)
    30:               value = DRV_NAME_GUARDS % value
    31:             end
    32:             drv.attrs[param.to_s.capitalize] = value
    33:           end
    34:           db = ::ODBC::Database.new
    35:           conn = db.drvconnect(drv)
    36:         else
    37:           conn = ::ODBC::connect(opts[:database], opts[:user], opts[:password])
    38:         end
    39:         conn.autocommit = true
    40:         conn
    41:       end

dataset(opts = nil)

[Source]

        # File lib/sequel_core/adapters/odbc.rb, line 43
    43:       def dataset(opts = nil)
    44:         ODBC::Dataset.new(self, opts)
    45:       end

do(sql, opts={})

Alias for execute_dui

execute(sql, opts={}) {|r| ...}

ODBC returns native statement objects, which must be dropped if you call execute manually, or you will get warnings. See the fetch_rows method source code for an example of how to drop the statements.

[Source]

        # File lib/sequel_core/adapters/odbc.rb, line 51
    51:       def execute(sql, opts={})
    52:         log_info(sql)
    53:         synchronize(opts[:server]) do |conn|
    54:           r = conn.run(sql)
    55:           yield(r) if block_given?
    56:           r
    57:         end
    58:       end

execute_dui(sql, opts={})

[Source]

        # File lib/sequel_core/adapters/odbc.rb, line 60
    60:       def execute_dui(sql, opts={})
    61:         log_info(sql)
    62:         synchronize(opts[:server]){|conn| conn.do(sql)}
    63:       end

transaction(server=nil) {|conn| ...}

Support single level transactions on ODBC

[Source]

        # File lib/sequel_core/adapters/odbc.rb, line 67
    67:       def transaction(server=nil)
    68:         synchronize(server) do |conn|
    69:           return yield(conn) if @transactions.include?(Thread.current)
    70:           log_info(begin_transaction_sql)
    71:           conn.do(begin_transaction_sql)
    72:           begin
    73:             @transactions << Thread.current
    74:             yield(conn)
    75:           rescue ::Exception => e
    76:             log_info(rollback_transaction_sql)
    77:             conn.do(rollback_transaction_sql)
    78:             transaction_error(e)
    79:           ensure
    80:             unless e
    81:               log_info(commit_transaction_sql)
    82:               conn.do(commit_transaction_sql)
    83:             end
    84:             @transactions.delete(Thread.current)
    85:           end
    86:         end
    87:       end

[Validate]