Class: Sequel::Firebird::Database

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

Constant Summary collapse

AUTO_INCREMENT =
''.freeze
TEMPORARY =
'GLOBAL TEMPORARY '.freeze

Constants inherited from Database

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

Instance Attribute Summary

Attributes inherited from Database

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

Instance Method Summary collapse

Methods inherited from 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_dui, #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, #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(*args) ⇒ Database

Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.



15
16
17
18
19
# File 'lib/sequel/adapters/firebird.rb', line 15

def initialize(*args)
  super
  @primary_keys = {}
  @primary_key_sequences = {}
end

Instance Method Details

#connect(server) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sequel/adapters/firebird.rb', line 21

def connect(server)
  opts = server_opts(server)

  db = Fb::Database.new(
    :database => "#{opts[:host]}:#{opts[:database]}",
    :username => opts[:user],
    :password => opts[:password])
  conn = db.connect
  conn.downcase_names = true
  conn
end

#create_trigger(*args) ⇒ Object



33
34
35
# File 'lib/sequel/adapters/firebird.rb', line 33

def create_trigger(*args)
  self << create_trigger_sql(*args)
end

#dataset(opts = nil) ⇒ Object



37
38
39
# File 'lib/sequel/adapters/firebird.rb', line 37

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

#drop_sequence(name) ⇒ Object



41
42
43
# File 'lib/sequel/adapters/firebird.rb', line 41

def drop_sequence(name)
  self << drop_sequence_sql(name)
end

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



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sequel/adapters/firebird.rb', line 45

def execute(sql, opts={})
  log_info(sql)
  begin
    synchronize(opts[:server]) do |conn|
      r = conn.execute(sql)
      yield(r) if block_given?
      r
    end
  rescue => e
    log_info(e.message)
    raise_error(e, :classes=>[Fb::Error])
  end
end

#primary_key(table, server = nil) ⇒ Object

Return primary key for the given table.



60
61
62
# File 'lib/sequel/adapters/firebird.rb', line 60

def primary_key(table, server=nil)
  synchronize(server){|conn| primary_key_for_table(conn, table)}
end

#primary_key_for_table(conn, table) ⇒ Object

Returns primary key for the given table. This information is cached, and if the primary key for a table is changed, the



67
68
69
# File 'lib/sequel/adapters/firebird.rb', line 67

def primary_key_for_table(conn, table)
  @primary_keys[quote_identifier(table)] ||= conn.table_primary_key(quote_identifier(table))
end

#restart_sequence(*args) ⇒ Object



71
72
73
# File 'lib/sequel/adapters/firebird.rb', line 71

def restart_sequence(*args)
  self << restart_sequence_sql(*args)
end

#sequences(opts = {}) ⇒ Object



75
76
77
78
# File 'lib/sequel/adapters/firebird.rb', line 75

def sequences(opts={})
  ds = self[:"rdb$generators"].server(opts[:server]).filter(:"rdb$system_flag" => 0).select(:"rdb$generator_name")
  block_given? ? yield(ds) : ds.map{|r| ds.send(:output_identifier, r[:"rdb$generator_name"])}
end

#tables(opts = {}) ⇒ Object



80
81
82
83
# File 'lib/sequel/adapters/firebird.rb', line 80

def tables(opts={})
  ds = self[:"rdb$relations"].server(opts[:server]).filter(:"rdb$view_blr" => nil, Sequel::SQL::Function.new(:COALESCE, :"rdb$system_flag", 0) => 0).select(:"rdb$relation_name")
  block_given? ? yield(ds) : ds.map{|r| ds.send(:output_identifier, r[:"rdb$relation_name"])}
end