Module: JdbcSpec::HSQLDB

Defined in:
lib/jdbc_adapter/jdbc_hsqldb.rb

Defined Under Namespace

Modules: Column

Instance Method Summary collapse

Instance Method Details

#add_limit_offset!(sql, options) ⇒ Object

:nodoc:



124
125
126
127
128
129
130
131
132
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 124

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:



96
97
98
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 96

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:



100
101
102
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 100

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:



112
113
114
115
116
117
118
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 112

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



120
121
122
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 120

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

#modify_types(tp) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 56

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:



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 72

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



84
85
86
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 84

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

#quoted_falseObject



92
93
94
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 92

def quoted_false
  '0'
end

#quoted_trueObject



88
89
90
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 88

def quoted_true
  '1'
end

#rename_column(table_name, column_name, new_column_name) ⇒ Object

:nodoc:



104
105
106
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 104

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



108
109
110
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 108

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



140
141
142
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 140

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