Module: JdbcSpec::HSQLDB

Defined in:
lib/jdbc_adapter/jdbc_hsqldb.rb

Defined Under Namespace

Modules: Column

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adapter_selectorObject



21
22
23
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 21

def self.adapter_selector
  [/hsqldb|\.h2\./i, lambda {|cfg,adapt| adapt.extend(::JdbcSpec::HSQLDB)}]
end

.column_selectorObject



17
18
19
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 17

def self.column_selector
  [/hsqldb|\.h2\./i, lambda {|cfg,col| col.extend(::JdbcSpec::HSQLDB::Column)}]
end

Instance Method Details

#add_limit_offset!(sql, options) ⇒ Object

:nodoc:



146
147
148
149
150
151
152
153
154
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 146

def add_limit_offset!(sql, options) #:nodoc:
  offset = options[:offset] || 0
  bef = sql[7..-1]
  if limit = options[:limit]
    sql.replace "select limit #{offset} #{limit} #{bef}"
  elsif offset > 0
    sql.replace "select limit #{offset} 0 #{bef}"
  end
end

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

:nodoc:



118
119
120
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 118

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

#change_column_default(table_name, column_name, default) ⇒ Object

:nodoc:



122
123
124
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 122

def change_column_default(table_name, column_name, default) #:nodoc:
  execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET DEFAULT #{quote(default)}"
end

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

:nodoc:



134
135
136
137
138
139
140
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 134

def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
  log_no_bench(sql,name) do
    @connection.execute_update(sql)
  end
  table = sql.split(" ", 4)[2]
  id_value || last_insert_id(table, nil)
end

#last_insert_id(table, sequence_name) ⇒ Object



142
143
144
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 142

def last_insert_id(table, sequence_name)
  Integer(select_value("SELECT IDENTITY() FROM #{table}"))
end

#modify_types(tp) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 78

def modify_types(tp)
  tp[:primary_key] = "INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) PRIMARY KEY"
  tp[:integer][:limit] = nil
  tp[:boolean][:limit] = nil
  # set text and float limits so we don't see odd scales tacked on
  # in migrations
  tp[:text][:limit] = nil
  tp[:float][:limit] = 17
  tp[:string][:limit] = 255
  tp[:datetime] = { :name => "DATETIME" }
  tp[:timestamp] = { :name => "DATETIME" }
  tp[:time] = { :name => "DATETIME" }
  tp[:date] = { :name => "DATETIME" }
  tp
end

#quote(value, column = nil) ⇒ Object

:nodoc:



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 94

def quote(value, column = nil) # :nodoc:
  case value
  when String
    if column && column.type == :binary
      "'#{quote_string(value).unpack("C*").collect {|v| v.to_s(16)}.join}'"
    else
      "'#{quote_string(value)}'"
    end
  else super
  end
end

#quote_string(str) ⇒ Object



106
107
108
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 106

def quote_string(str)
  str.gsub(/'/, "''")
end

#quoted_falseObject



114
115
116
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 114

def quoted_false
  '0'
end

#quoted_trueObject



110
111
112
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 110

def quoted_true
  '1'
end

#rename_column(table_name, column_name, new_column_name) ⇒ Object

:nodoc:



126
127
128
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 126

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

#rename_table(name, new_name) ⇒ Object



130
131
132
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 130

def rename_table(name, new_name)
  execute "ALTER TABLE #{name} RENAME TO #{new_name}"
end

#tablesObject

override to filter out system tables that otherwise end up in db/schema.rb during migrations. JdbcConnection#tables now takes an optional block filter so we can screen out rows corresponding to system tables. HSQLDB names its system tables SYSTEM.*, but H2 seems to name them without any kind of convention



162
163
164
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 162

def tables
  @connection.tables.select {|row| row.to_s !~ /^system_/i }
end