Class: Sequel::DBI::Database

Inherits:
Sequel::Database show all
Defined in:
lib/sequel/lib/sequel/adapters/dbi.rb

Constant Summary collapse

DBI_ADAPTERS =
{
  :ado => "ADO",
  :db2 => "DB2",
  :frontbase => "FrontBase",
  :interbase => "InterBase",
  :msql => "Msql",
  :mysql => "Mysql",
  :odbc => "ODBC",
  :oracle => "Oracle",
  :pg => "pg",
  :proxy => "Proxy",
  :sqlite => "SQLite",
  :sqlrelay => "SQLRelay"
}

Constants inherited from Sequel::Database

Sequel::Database::ADAPTERS, Sequel::Database::AUTOINCREMENT, Sequel::Database::CASCADE, Sequel::Database::COMMA_SEPARATOR, Sequel::Database::MSSQL_DEFAULT_RE, Sequel::Database::MYSQL_TIMESTAMP_RE, Sequel::Database::NOT_NULL, Sequel::Database::NO_ACTION, Sequel::Database::NULL, Sequel::Database::POSTGRES_DEFAULT_RE, Sequel::Database::PRIMARY_KEY, Sequel::Database::RESTRICT, Sequel::Database::SET_DEFAULT, Sequel::Database::SET_NULL, Sequel::Database::SQL_BEGIN, Sequel::Database::SQL_COMMIT, Sequel::Database::SQL_RELEASE_SAVEPOINT, Sequel::Database::SQL_ROLLBACK, Sequel::Database::SQL_ROLLBACK_TO_SAVEPOINT, Sequel::Database::SQL_SAVEPOINT, Sequel::Database::STRING_DEFAULT_RE, Sequel::Database::TEMPORARY, Sequel::Database::TRANSACTION_BEGIN, Sequel::Database::TRANSACTION_COMMIT, Sequel::Database::TRANSACTION_ROLLBACK, Sequel::Database::UNDERSCORE, Sequel::Database::UNIQUE, Sequel::Database::UNSIGNED

Instance Attribute Summary

Attributes inherited from Sequel::Database

#default_schema, #loggers, #opts, #pool, #prepared_statements

Instance Method Summary collapse

Methods inherited from Sequel::Database

#<<, #[], adapter_class, adapter_scheme, #add_column, #add_index, #alter_table, #call, #cast_type_literal, connect, #create_or_replace_view, #create_table, #create_table!, #create_table?, #create_view, #database_type, #disconnect, #drop_column, #drop_index, #drop_table, #drop_view, #dump_indexes_migration, #dump_schema_migration, #dump_table_schema, #execute_ddl, #execute_insert, #fetch, #from, #get, #identifier_input_method, identifier_input_method, #identifier_input_method=, identifier_input_method=, #identifier_output_method, identifier_output_method, identifier_output_method=, #identifier_output_method=, #inspect, #literal, #log_info, #logger=, #query, quote_identifiers=, #quote_identifiers=, #quote_identifiers?, #rename_column, #rename_table, #run, #schema, #select, #serial_primary_key_options, #set_column_default, #set_column_type, single_threaded=, #single_threaded?, #supports_savepoints?, #synchronize, #table_exists?, #test_connection, #transaction, #typecast_value, #uri, #url

Methods included from Metaprogramming

#meta_def

Constructor Details

#initialize(opts) ⇒ Database


23
24
25
26
27
28
29
30
# File 'lib/sequel/lib/sequel/adapters/dbi.rb', line 23

def initialize(opts)
  super(opts)
  case opts[:db_type]
  when 'mssql'
    Sequel.require 'adapters/shared/mssql'
    extend Sequel::MSSQL::DatabaseMethods
  end
end

Instance Method Details

#connect(server) ⇒ Object


51
52
53
54
55
56
57
58
59
# File 'lib/sequel/lib/sequel/adapters/dbi.rb', line 51

def connect(server)
  opts = server_opts(server)
  dbname = opts[:database]
  if dbname !~ /^DBI:/ then
    dbname = "DBI:#{dbname}"
    [:host, :port].each{|sym| dbname += ";#{sym}=#{opts[sym]}" unless blank_object?(opts[sym])}
  end
  ::DBI.connect(dbname, opts[:user], opts[:password])
end

#dataset(opts = nil) ⇒ Object


61
62
63
# File 'lib/sequel/lib/sequel/adapters/dbi.rb', line 61

def dataset(opts = nil)
  DBI::Dataset.new(self, opts)
end

#do(sql, opts = {}) ⇒ Object Also known as: execute_dui


74
75
76
77
# File 'lib/sequel/lib/sequel/adapters/dbi.rb', line 74

def do(sql, opts={})
  log_info(sql)
  synchronize(opts[:server]){|conn| conn.do(sql)}
end

#execute(sql, opts = {}) ⇒ Object


65
66
67
68
69
70
71
72
# File 'lib/sequel/lib/sequel/adapters/dbi.rb', line 65

def execute(sql, opts={})
  log_info(sql)
  synchronize(opts[:server]) do |conn|
    r = conn.execute(sql)
    yield(r) if block_given?
    r
  end
end