Class: DBI::DBD::ODBC::Database
Overview
Instance Method Summary
collapse
#[], #initialize
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 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
|
#database_name ⇒ Object
12
13
14
|
# File 'lib/dbd/odbc/database.rb', line 12
def database_name
@handle.get_info('SQL_DATABASE_NAME')
end
|
#disconnect ⇒ Object
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
#ping ⇒ Object
16
17
18
|
# File 'lib/dbd/odbc/database.rb', line 16
def ping
@handle.connected?
end
|
#prepare(statement) ⇒ Object
#tables ⇒ Object
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
|