Class: DBI::DBD::Jdbc::Database
Overview
Instance Method Summary
collapse
#dbidate_to_jdbcdate, #dbitime_to_jdbctime, #dbitimestamp_to_jdbctimestamp, #jdbc_to_dbi_sqltype, #jdbcdate_to_dbidate, #jdbctime_to_dbitime, #jdbctimestamp_to_dbitimestamp
Constructor Details
#initialize(connection) ⇒ Database
Returns a new instance of Database.
62
63
64
65
66
67
68
|
# File 'lib/dbd/Jdbc.rb', line 62
def initialize(connection)
@connection = connection
@attributes = {
"nulltype" => java.sql.Types::VARCHAR
}
end
|
Instance Method Details
#[](attribute) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/dbd/Jdbc.rb', line 132
def [](attribute)
attribute.downcase!
check_attribute(attribute)
case attribute
when "autocommit" then @connection.getAutoCommit()
else
@attributes[attribute]
end
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#[]=(attribute, value) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/dbd/Jdbc.rb', line 144
def []=(attribute, value)
attribute.downcase!
check_attribute(attribute)
case attribute
when "autocommit" then @connection.setAutoCommit(value)
else
@attributes[attribute] = value
end
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#__get_java_connection ⇒ Object
156
157
158
|
# File 'lib/dbd/Jdbc.rb', line 156
def __get_java_connection
return @connection
end
|
#columns(table) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/dbd/Jdbc.rb', line 112
def columns(table)
metaData = @connection.getMetaData()
rs = metaData.getColumns(nil, nil, table, nil)
columns = []
while(rs.next())
columns << {
"name" => rs.getString(4),
"sql_type" => jdbc_to_dbi_sqltype(rs.getShort(5)),
"type_name" => rs.getString(6),
"precision" => rs.getInt(7),
"scale" => rs.getInt(9),
"default" => rs.getString(13),
"nullable" => (rs.getInt(11) == 1)
}
end
return columns
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#commit ⇒ Object
89
90
91
92
93
|
# File 'lib/dbd/Jdbc.rb', line 89
def commit
@connection.commit()
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#disconnect ⇒ Object
70
71
72
73
74
75
|
# File 'lib/dbd/Jdbc.rb', line 70
def disconnect
@connection.rollback unless self["autocommit"]
@connection.close
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#ping ⇒ Object
83
84
85
86
87
|
# File 'lib/dbd/Jdbc.rb', line 83
def ping
return !@connection.isClosed
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#prepare(sql) ⇒ Object
77
78
79
80
81
|
# File 'lib/dbd/Jdbc.rb', line 77
def prepare(sql)
return Statement.new(@connection.prepareStatement(sql), self["nulltype"])
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#rollback ⇒ Object
95
96
97
98
99
|
# File 'lib/dbd/Jdbc.rb', line 95
def rollback
@connection.rollback()
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|
#tables ⇒ Object
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/dbd/Jdbc.rb', line 101
def tables
rs = @connection.getMetaData.getTables(nil, nil, nil, nil)
tables = []
while(rs.next())
tables << rs.getString(3)
end
return tables
rescue NativeException => error
raise DBI::DatabaseError.new(error.message)
end
|