Class: DBI::DBD::OCI8::Database
- Includes:
- Util
- Defined in:
- lib/dbd/OCI8.rb
Defined Under Namespace
Classes: DummyQuoter
Constant Summary
Constants included from Util
Instance Method Summary collapse
- #[](attr) ⇒ Object
- #[]=(attr, value) ⇒ Object
-
#columns(table) ⇒ Object
SQLs are copied from DBD::Oracle.
- #commit ⇒ Object
- #disconnect ⇒ Object
- #ping ⇒ Object
- #prepare(statement) ⇒ Object
- #rollback ⇒ Object
- #tables ⇒ Object
Methods included from Util
Instance Method Details
#[](attr) ⇒ Object
302 303 304 305 306 307 |
# File 'lib/dbd/OCI8.rb', line 302 def [](attr) case attr when 'AutoCommit' @handle.autocommit? end end |
#[]=(attr, value) ⇒ Object
309 310 311 312 313 314 |
# File 'lib/dbd/OCI8.rb', line 309 def []=(attr, value) case attr when 'AutoCommit' @handle.autocommit = value end end |
#columns(table) ⇒ Object
SQLs are copied from DBD::Oracle.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/dbd/OCI8.rb', line 239 def columns(table) tab = @handle.describe_table(table) cols = tab.columns cols.collect! do |col| (col) end dbh = DBI::DatabaseHandle.new(self) primaries = {} dbh.select_all(<<EOS, tab.obj_schema, tab.obj_name) do |row| select column_name from all_cons_columns a, all_constraints b where a.owner = b.owner and a.constraint_name = b.constraint_name and a.table_name = b.table_name and b.constraint_type = 'P' and b.owner = :1 and b.table_name = :2 EOS primaries[row[0]] = true end indices = {} uniques = {} dbh.select_all(<<EOS, tab.obj_schema, tab.obj_name) do |row| select a.column_name, a.index_name, b.uniqueness from all_ind_columns a, all_indexes b where a.index_name = b.index_name and a.index_owner = b.owner and a.table_owner = :1 and a.table_name = :2 EOS col_name, index_name, uniqueness = row indices[col_name] = true uniques[col_name] = true if uniqueness == 'UNIQUE' end dbh.select_all(<<EOS, tab.obj_schema, tab.obj_name).collect do |row| select column_id, column_name, data_default from all_tab_columns where owner = :1 and table_name = :2 EOS col_id, col_name, default = row col = cols[col_id.to_i - 1] col_name = col['name'] if default && default[0] == ?' default = default[1..-2].gsub(/''/, "'") end col['indexed'] = indices[col_name] || false col['primary'] = primaries[col_name] || false col['unique'] = uniques[col_name] || false col['default'] = default col end rescue OCIException => err raise_dbierror(err) end |
#commit ⇒ Object
219 220 221 222 223 |
# File 'lib/dbd/OCI8.rb', line 219 def commit @handle.commit() rescue OCIException => err raise_dbierror(err) end |
#disconnect ⇒ Object
193 194 195 196 197 |
# File 'lib/dbd/OCI8.rb', line 193 def disconnect @handle.logoff rescue OCIException => err raise_dbierror(err) end |
#ping ⇒ Object
212 213 214 215 216 217 |
# File 'lib/dbd/OCI8.rb', line 212 def ping @handle.exec("BEGIN NULL; END;") true rescue false end |
#prepare(statement) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/dbd/OCI8.rb', line 199 def prepare( statement ) # convert ?-style parameters to :1, :2 etc. prep_statement = DBI::SQL::PreparedStatement.new(DummyQuoter.new, statement) if prep_statement.unbound.size > 0 arr = (1..(prep_statement.unbound.size)).collect{|i| ":#{i}"} statement = prep_statement.bind( arr ) end cursor = @handle.parse(statement) Statement.new(cursor) rescue OCIException => err raise_dbierror(err) end |
#rollback ⇒ Object
225 226 227 228 229 |
# File 'lib/dbd/OCI8.rb', line 225 def rollback @handle.rollback() rescue OCIException => err raise_dbierror(err) end |
#tables ⇒ Object
231 232 233 234 235 236 |
# File 'lib/dbd/OCI8.rb', line 231 def tables stmt = execute("SELECT object_name FROM user_objects where object_type in ('TABLE', 'VIEW')") rows = stmt.fetch_all || [] stmt.finish rows.collect {|row| row[0]} end |