Class: DBI::DBD::ODBC::Database

Inherits:
BaseDatabase show all
Defined in:
lib/dbd/odbc/database.rb

Overview

See DBI::BaseDatabase.

Instance Method Summary collapse

Methods inherited from BaseDatabase

#[], #initialize

Constructor Details

This class inherits a constructor from DBI::BaseDatabase

Instance Method Details

#[]=(attr, value) ⇒ Object

Additional Attributes on the DatabaseHandle:

  • AutoCommit: force a commit after each statement execution.

  • odbc_ignorecase: Be case-insensitive in operations.

  • odbc_timeout: Return after a certain time regardless of whether the operation returned anything.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/dbd/odbc/database.rb', line 96

def []=(attr, value)
    case attr
    when 'AutoCommit'
        @handle.autocommit(value)
    when 'odbc_ignorecase'
        @handle.ignorecase(value)
    when 'odbc_timeout'
        @handle.timeout(value)
    else
        if attr =~ /^odbc_/ or attr != /_/
            raise DBI::NotSupportedError, "Option '#{attr}' not supported"
        else # option for some other driver - quitly ignore
            return
        end
    end
    @attr[attr] = value
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#columns(table) ⇒ Object

See DBI::BaseDatabase#columns. Additional Attributes:

  • nullable: boolean, true if NULLs are allowed in this column.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dbd/odbc/database.rb', line 25

def columns(table)
    cols = []

    stmt = @handle.columns(table)
    stmt.ignorecase = true

    stmt.each_hash do |row|
        info = Hash.new
        cols << info

        info['name']      = row['COLUMN_NAME']
        info['type_name'] = row['TYPE_NAME']
        info['sql_type']  = row['DATA_TYPE']
        info['nullable']  = 
            case row['NULLABLE']
            when 1
                true
            when 0
                false
            else
                nil
            end
        info['precision'] = row['PRECISION']
        info['scale']     = row['SCALE']
    end

    stmt.drop
    cols
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#commitObject



116
117
118
119
120
# File 'lib/dbd/odbc/database.rb', line 116

def commit
    @handle.commit
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#database_nameObject



12
13
14
# File 'lib/dbd/odbc/database.rb', line 12

def database_name
    @handle.get_info('SQL_DATABASE_NAME')
end

#disconnectObject



5
6
7
8
9
10
# File 'lib/dbd/odbc/database.rb', line 5

def disconnect
    @handle.rollback
    @handle.disconnect 
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#do(statement, *bindvars) ⇒ Object



76
77
78
79
80
# File 'lib/dbd/odbc/database.rb', line 76

def do(statement, *bindvars)
    @handle.do(statement, *bindvars) 
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#execute(statement, *bindvars) ⇒ Object



82
83
84
85
86
87
# File 'lib/dbd/odbc/database.rb', line 82

def execute(statement, *bindvars)
    stmt = @handle.run(statement, *bindvars) 
    DBI::DBD::ODBC::Statement.new(stmt, statement)
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#pingObject



16
17
18
# File 'lib/dbd/odbc/database.rb', line 16

def ping
    @handle.connected?
end

#prepare(statement) ⇒ Object



70
71
72
73
74
# File 'lib/dbd/odbc/database.rb', line 70

def prepare(statement)
    DBI::DBD::ODBC::Statement.new(@handle.prepare(statement), statement)
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#rollbackObject



122
123
124
125
126
# File 'lib/dbd/odbc/database.rb', line 122

def rollback
    @handle.rollback
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end

#tablesObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dbd/odbc/database.rb', line 57

def tables
    stmt = @handle.tables
    stmt.ignorecase = true
    tabs = [] 
    stmt.each_hash {|row|
        tabs << row["TABLE_NAME"]
    }
    stmt.drop
    tabs
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end