Class | Sequel::Firebird::Database
In: | lib/sequel/adapters/firebird.rb
Parent: | Sequel::Database

### Methods

connect create_table create_trigger dataset drop_sequence execute new primary_key primary_key_for_table restart_sequence sequences tables transaction

### Constants

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

### Public Class methods

new(*args)

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

[Source]

        # File lib/sequel/adapters/firebird.rb, line 16
    16:       def initialize(*args)
    17:         super
    18:         @primary_keys = {}
    19:         @primary_key_sequences = {}
    20:       end

### Public Instance methods

connect(server)

[Source]

        # File lib/sequel/adapters/firebird.rb, line 22
    22:       def connect(server)
    23:         opts = server_opts(server)
    24:
    25:         db = Fb::Database.new(
    26:           :database => "#{opts[:host]}:#{opts[:database]}",
    27:           :username => opts[:user],
    28:           :password => opts[:password])
    29:         conn = db.connect
    30:         conn.downcase_names = true
    31:         conn
    32:       end

create_table(name, options={}, &block)

Creates a table with the columns given in the provided block:

      DB.create_table :posts do
        primary_key :id, :serial
        column :title, :text
        column :content, :text
        index :title
      end

See Schema::Generator. Firebird gets an override because of the mess of creating a generator for auto-incrementing primary keys.

[Source]

        # File lib/sequel/adapters/firebird.rb, line 46
    46:       def create_table(name, options={}, &block)
    47:         options = {:generator=>options} if options.is_a?(Schema::Generator)
    48:         generator = options[:generator] || Schema::Generator.new(self, &block)
    49:         drop_statement, create_statements = create_table_sql_list(name, generator, options)
    50:         (execute_ddl(drop_statement) rescue nil) if drop_statement
    51:         (create_statements + index_sql_list(name, generator.indexes)).each{|sql| execute_ddl(sql)}
    52:       end

create_trigger(*args)

[Source]

        # File lib/sequel/adapters/firebird.rb, line 54
    54:       def create_trigger(*args)
    55:         self << create_trigger_sql(*args)
    56:       end

dataset(opts = nil)

[Source]

        # File lib/sequel/adapters/firebird.rb, line 58
    58:       def dataset(opts = nil)
    59:         Firebird::Dataset.new(self, opts)
    60:       end

drop_sequence(name)

[Source]

        # File lib/sequel/adapters/firebird.rb, line 62
    62:       def drop_sequence(name)
    63:         self << drop_sequence_sql(name)
    64:       end

execute(sql, opts={}) {|r| ...}

[Source]

        # File lib/sequel/adapters/firebird.rb, line 66
    66:       def execute(sql, opts={})
    67:         log_info(sql)
    68:         begin
    69:           synchronize(opts[:server]) do |conn|
    70:             r = conn.execute(sql)
    71:             yield(r) if block_given?
    72:             r
    73:           end
    74:         rescue => e
    75:           log_info(e.message)
    76:           raise_error(e, :classes=>[Fb::Error])
    77:         end
    78:       end

primary_key(table, server=nil)

Return primary key for the given table.

[Source]

        # File lib/sequel/adapters/firebird.rb, line 81
    81:       def primary_key(table, server=nil)
    82:         synchronize(server){|conn| primary_key_for_table(conn, table)}
    83:       end

primary_key_for_table(conn, table)

Returns primary key for the given table. This information is cached, and if the primary key for a table is changed, the @primary_keys instance variable should be reset manually.

[Source]

        # File lib/sequel/adapters/firebird.rb, line 88
    88:       def primary_key_for_table(conn, table)
    89:         @primary_keys[quote_identifier(table)] ||= conn.table_primary_key(quote_identifier(table))
    90:       end

restart_sequence(*args)

[Source]

        # File lib/sequel/adapters/firebird.rb, line 92
    92:       def restart_sequence(*args)
    93:         self << restart_sequence_sql(*args)
    94:       end

sequences(opts={}) {|ds| ...}

[Source]

        # File lib/sequel/adapters/firebird.rb, line 96
    96:       def sequences(opts={})
    97:         ds = self["rdb$generators""rdb$generators"].server(opts[:server]).filter("rdb$system_flag""rdb$system_flag" => 0).select("rdb$generator_name""rdb$generator_name")
    98:         block_given? ? yield(ds) : ds.map{|r| ds.send(:output_identifier, r["rdb$generator_name""rdb$generator_name"])}
    99:       end

tables(opts={}) {|ds| ...}

[Source]

         # File lib/sequel/adapters/firebird.rb, line 101
    101:       def tables(opts={})
    102:         ds = self["rdb$relations""rdb$relations"].server(opts[:server]).filter("rdb$view_blr""rdb$view_blr" => nil, Sequel::SQL::Function.new(:COALESCE, "rdb$system_flag""rdb$system_flag", 0) => 0).select("rdb$relation_name""rdb$relation_name")
    103:         block_given? ? yield(ds) : ds.map{|r| ds.send(:output_identifier, r["rdb$relation_name""rdb$relation_name"])}
    104:       end

transaction(opts={}) {|conn| ...}

[Source]

         # File lib/sequel/adapters/firebird.rb, line 106
    106:       def transaction(opts={})
    107:         synchronize(opts[:server]) do |conn|
    108:           return yield(conn) if @transactions.include?(Thread.current)
    109:           log_info("Transaction.begin")
    110:           conn.transaction
    111:           begin
    112:             @transactions << Thread.current
    113:             yield(conn)
    114:           rescue ::Exception => e
    115:             log_info("Transaction.rollback")
    116:             conn.rollback
    117:             transaction_error(e, Fb::Error)
    118:           ensure
    119:             unless e
    120:               log_info("Transaction.commit")
    121:               conn.commit
    122:             end
    123:             @transactions.delete(Thread.current)
    124:           end
    125:         end
    126:       end

[Validate]