Class: Sequel::DBI::Database

Inherits:
Sequel::Database show all
Defined in:
lib/sequel_core/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::SQL_BEGIN, Sequel::Database::SQL_COMMIT, Sequel::Database::SQL_ROLLBACK

Constants included from Schema::SQL

Schema::SQL::AUTOINCREMENT, Schema::SQL::CASCADE, Schema::SQL::COMMA_SEPARATOR, Schema::SQL::NOT_NULL, Schema::SQL::NO_ACTION, Schema::SQL::NULL, Schema::SQL::PRIMARY_KEY, Schema::SQL::RESTRICT, Schema::SQL::SET_DEFAULT, Schema::SQL::SET_NULL, Schema::SQL::TYPES, Schema::SQL::UNDERSCORE, Schema::SQL::UNIQUE, Schema::SQL::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, connect, #create_or_replace_view, #create_table, #create_table!, #create_view, #disconnect, #drop_column, #drop_index, #drop_table, #drop_view, #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=, #initialize, #inspect, #log_info, #logger, #logger=, #multi_threaded?, #query, quote_identifiers=, #quote_identifiers=, #quote_identifiers?, #rename_column, #rename_table, #select, #serial_primary_key_options, #set_column_default, #set_column_type, single_threaded=, #single_threaded?, #synchronize, #table_exists?, #test_connection, #transaction, #typecast_value, upcase_identifiers=, #upcase_identifiers=, #upcase_identifiers?, #uri, #url

Methods included from Schema::SQL

#alter_table_sql, #alter_table_sql_list, #auto_increment_sql, #column_definition_sql, #column_list_sql, #column_references_sql, #constraint_definition_sql, #create_table_sql_list, #default_index_name, #drop_index_sql, #drop_table_sql, #filter_expr, #index_definition_sql, #index_list_sql_list, #literal, #on_delete_clause, #quote_identifier, #quote_schema_table, #rename_table_sql, #schema, #schema_utility_dataset

Constructor Details

This class inherits a constructor from Sequel::Database

Instance Method Details

#connect(server) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/sequel_core/adapters/dbi.rb', line 42

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 opts[sym].blank?}
  end
  ::DBI.connect(dbname, opts[:user], opts[:password])
end

#dataset(opts = nil) ⇒ Object



52
53
54
# File 'lib/sequel_core/adapters/dbi.rb', line 52

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

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



65
66
67
68
# File 'lib/sequel_core/adapters/dbi.rb', line 65

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

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



56
57
58
59
60
61
62
63
# File 'lib/sequel_core/adapters/dbi.rb', line 56

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