class Database
Public Class Methods
from_connection(con)
click to toggle source
# File lib/dbexpect/database.rb, line 20 def self.from_connection(con) new(con) end
hash_from_config()
click to toggle source
# File lib/dbexpect/database.rb, line 24 def self.hash_from_config databases = {} YAML.load_file('database.yml').each do |(dsn,config)| databases[dsn.to_sym] = from_connection(OdbcConnection.new(dsn,config)) end databases end
new(con)
click to toggle source
# File lib/dbexpect/database.rb, line 33 def initialize(con) @connection = con end
Public Instance Methods
close()
click to toggle source
# File lib/dbexpect/database.rb, line 55 def close #@connection.close end
insert_rows(insert_statements)
click to toggle source
# File lib/dbexpect/database.rb, line 49 def insert_rows(insert_statements) insert_statements.each do |stmt| @connection.run(stmt) end end
num_rows_match(schema,table,query)
click to toggle source
# File lib/dbexpect/database.rb, line 37 def num_rows_match(schema,table,query) @connection.run("select * from #{schema}.#{table} where (#{query})").count end
truncate_table(schema,name)
click to toggle source
# File lib/dbexpect/database.rb, line 41 def truncate_table(schema,name) if @connection.type == 'db2' @connection.run("truncate table #{schema}.#{name} immediate") else @connection.run("truncate table #{schema}.#{name}") end end