Module: JdbcSpec::FireBird

Defined in:
lib/jdbc_adapter/jdbc_firebird.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adapter_matcher(name) ⇒ Object



3
4
5
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 3

def self.adapter_matcher(name, *)
  name =~ /firebird/i ? self : false
end

Instance Method Details

#add_limit_offset!(sql, options) ⇒ Object

:nodoc:



19
20
21
22
23
24
25
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 19

def add_limit_offset!(sql, options) # :nodoc:
  if options[:limit]
    limit_string = "FIRST #{options[:limit]}"
    limit_string << " SKIP #{options[:offset]}" if options[:offset]
    sql.sub!(/\A(\s*SELECT\s)/i, '\&' + limit_string + ' ')
  end
end

#change_column(table_name, column_name, type, options = {}) ⇒ Object

:nodoc:



54
55
56
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 54

def change_column(table_name, column_name, type, options = {}) #:nodoc:
  execute "ALTER TABLE #{table_name} ALTER  #{column_name} TYPE #{type_to_sql(type, options[:limit])}"
end

#create_table(name, options = {}) ⇒ Object

:nodoc:



39
40
41
42
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 39

def create_table(name, options = {}) #:nodoc:
  super(name, options)
  execute "CREATE GENERATOR #{name}_seq"
end

#default_sequence_name(table_name, primary_key) ⇒ Object

:nodoc:



31
32
33
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 31

def default_sequence_name(table_name, primary_key) # :nodoc:
  "#{table_name}_seq"
end

#drop_table(name, options = {}) ⇒ Object

:nodoc:



49
50
51
52
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 49

def drop_table(name, options = {}) #:nodoc:
  super(name)
  execute "DROP GENERATOR #{name}_seq" rescue nil
end

#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object

:nodoc:



14
15
16
17
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 14

def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) # :nodoc:
  execute(sql, name)
  id_value
end

#modify_types(tp) ⇒ Object



7
8
9
10
11
12
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 7

def modify_types(tp)
  tp[:primary_key] = 'INTEGER NOT NULL PRIMARY KEY'
  tp[:string][:limit] = 252
  tp[:integer][:limit] = nil
  tp
end

#next_sequence_value(sequence_name) ⇒ Object



35
36
37
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 35

def next_sequence_value(sequence_name)
  select_one("SELECT GEN_ID(#{sequence_name}, 1 ) FROM RDB$DATABASE;")["gen_id"]
end

#prefetch_primary_key?(table_name = nil) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 27

def prefetch_primary_key?(table_name = nil)
  true
end

#quote(value, column = nil) ⇒ Object

:nodoc:



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 66

def quote(value, column = nil) # :nodoc:
  return value.quoted_id if value.respond_to?(:quoted_id)
  
  if [Time, DateTime].include?(value.class)
    "CAST('#{value.strftime("%Y-%m-%d %H:%M:%S")}' AS TIMESTAMP)"
  else
    if column && column.type == :primary_key
      return value.to_s
    end
    super
  end
end

#quote_column_name(column_name) ⇒ Object

:nodoc:



83
84
85
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 83

def quote_column_name(column_name) # :nodoc:
  %Q("#{ar_to_fb_case(column_name)}")
end

#quote_string(string) ⇒ Object

:nodoc:



79
80
81
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 79

def quote_string(string) # :nodoc:
  string.gsub(/'/, "''")
end

#quoted_falseObject

:nodoc:



91
92
93
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 91

def quoted_false # :nodoc:
  quote(0)
end

#quoted_trueObject

:nodoc:



87
88
89
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 87

def quoted_true # :nodoc:
  quote(1)
end

#remove_index(table_name, options) ⇒ Object

:nodoc:



62
63
64
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 62

def remove_index(table_name, options) #:nodoc:
  execute "DROP INDEX #{index_name(table_name, options)}"
end

#rename_column(table_name, column_name, new_column_name) ⇒ Object



58
59
60
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 58

def rename_column(table_name, column_name, new_column_name)
  execute "ALTER TABLE #{table_name} ALTER  #{column_name} TO #{new_column_name}"
end

#rename_table(name, new_name) ⇒ Object

:nodoc:



44
45
46
47
# File 'lib/jdbc_adapter/jdbc_firebird.rb', line 44

def rename_table(name, new_name) #:nodoc:
  execute "RENAME #{name} TO #{new_name}"
  execute "UPDATE RDB$GENERATORS SET RDB$GENERATOR_NAME='#{new_name}_seq' WHERE RDB$GENERATOR_NAME='#{name}_seq'" rescue nil
end