module ArJdbc::HSQLDB
Constants
- ADAPTER_NAME
- NATIVE_DATABASE_TYPES
- SchemaCreation
@private
Public Class Methods
arel_visitor_type(config = nil)
click to toggle source
@see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
# File lib/arjdbc/hsqldb/adapter.rb, line 68 def self.arel_visitor_type(config = nil) require 'arel/visitors/hsqldb'; ::Arel::Visitors::HSQLDB end
column_selector()
click to toggle source
@see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
# File lib/arjdbc/hsqldb/adapter.rb, line 10 def self.column_selector [ /hsqldb/i, lambda { |config, column| column.extend(Column) } ] end
Public Instance Methods
adapter_name()
click to toggle source
# File lib/arjdbc/hsqldb/adapter.rb, line 74 def adapter_name ADAPTER_NAME end
add_column(table_name, column_name, type, options = {})
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 166 def add_column(table_name, column_name, type, options = {}) add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}" add_column_options!(add_column_sql, options) execute(add_column_sql) end
add_limit_offset!(sql, options)
click to toggle source
@note Only used with (non-AREL) ActiveRecord *2.3*. @see Arel::Visitors::HSQLDB#limit_offset
# File lib/arjdbc/hsqldb/adapter.rb, line 216 def add_limit_offset!(sql, options) if sql =~ /^select/i offset = options[:offset] || 0 if limit = options[:limit] sql.replace "SELECT LIMIT #{offset} #{limit} #{sql[7..-1]}" elsif offset > 0 sql.replace "SELECT LIMIT #{offset} 0 #{sql[7..-1]}" end end end
change_column(table_name, column_name, type, options = {})
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 173 def change_column(table_name, column_name, type, options = {}) execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} #{type_to_sql(type, options[:limit])}" end
create_database(name = nil, options = {})
click to toggle source
@private
# File lib/arjdbc/hsqldb/adapter.rb, line 280 def create_database(name = nil, options = {}); end
drop_database(name = nil)
click to toggle source
@private
# File lib/arjdbc/hsqldb/adapter.rb, line 283 def drop_database(name = nil) execute('DROP SCHEMA PUBLIC CASCADE') end
empty_insert_statement_value()
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 228 def empty_insert_statement_value # on HSQLDB only work with tables that have a default value for each # and every column ... you'll need to avoid `Model.create!` on 4.0 'DEFAULT VALUES' end
last_insert_id()
click to toggle source
# File lib/arjdbc/hsqldb/adapter.rb, line 202 def last_insert_id identity = select_value("CALL IDENTITY()") Integer(identity.nil? ? 0 : identity) end
native_database_types()
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 107 def native_database_types NATIVE_DATABASE_TYPES end
quote(value, column = nil)
click to toggle source
@override
Calls superclass method
# File lib/arjdbc/hsqldb/adapter.rb, line 112 def quote(value, column = nil) return value.quoted_id if value.respond_to?(:quoted_id) return value if sql_literal?(value) case value when String column_type = column && column.type if column_type == :binary "X'#{value.unpack("H*")[0]}'" elsif column_type == :integer || column.respond_to?(:primary) && column.primary && column.klass != String value.to_i.to_s else "'#{quote_string(value)}'" end when Time column_type = column && column.type if column_type == :time "'#{value.strftime("%H:%M:%S")}'" #elsif column_type == :timestamp # || column_type == :datetime #value = ::ActiveRecord::Base.default_timezone == :utc ? value.getutc : value.getlocal #"'#{value.strftime("%Y-%m-%d %H:%M:%S")}.#{sprintf("%06d", value.usec)}'" else super end else super end end
quote_column_name(name)
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 156 def quote_column_name(name) name = name.to_s if name =~ /[-]/ %Q{"#{name.upcase}"} else name end end
quoted_date(value)
click to toggle source
Quote date/time values for use in SQL input. Includes microseconds if the value is a Time responding to usec. @override
Calls superclass method
# File lib/arjdbc/hsqldb/adapter.rb, line 145 def quoted_date(value) if value.acts_like?(:time) && value.respond_to?(:usec) usec = sprintf("%06d", value.usec) value = ::ActiveRecord::Base.default_timezone == :utc ? value.getutc : value.getlocal "#{value.strftime("%Y-%m-%d %H:%M:%S")}.#{usec}" else super end end
recreate_database(name = nil, options = {})
click to toggle source
@private
# File lib/arjdbc/hsqldb/adapter.rb, line 274 def recreate_database(name = nil, options = {}) drop_database(name) create_database(name, options) end
remove_index(table_name, options = {})
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 241 def remove_index(table_name, options = {}) execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}" end
rename_table(name, new_name)
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 193 def rename_table(name, new_name) execute "ALTER TABLE #{name} RENAME TO #{new_name}" end
schema_creation()
click to toggle source
# File lib/arjdbc/hsqldb/schema_creation.rb, line 6 def schema_creation SchemaCreation.new self end
shutdown()
click to toggle source
# File lib/arjdbc/hsqldb/adapter.rb, line 269 def shutdown execute 'SHUTDOWN' end
structure_dump()
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 252 def structure_dump execute('SCRIPT').map do |result| # [ { 'command' => SQL }, { 'command' ... }, ... ] case sql = result.first[1] # ['command'] when /CREATE USER SA PASSWORD DIGEST .*?/i then nil when /CREATE SCHEMA PUBLIC AUTHORIZATION DBA/i then nil when /GRANT DBA TO SA/i then nil else sql end end.compact.join("\n\n") end
structure_load(dump)
click to toggle source
@see structure_dump
# File lib/arjdbc/hsqldb/adapter.rb, line 265 def structure_load(dump) dump.each_line("\n\n") { |ddl| execute(ddl) } end
supports_foreign_keys?()
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 249 def supports_foreign_keys?; true end
supports_views?()
click to toggle source
@override
# File lib/arjdbc/hsqldb/adapter.rb, line 246 def supports_views?; true end
tables()
click to toggle source
We filter out HSQLDB's system tables (named “SYSTEM.*”). @override
# File lib/arjdbc/hsqldb/adapter.rb, line 236 def tables @connection.tables.select { |row| row.to_s !~ /^system_/i } end
truncate(table_name, name = nil)
click to toggle source
@note AR API since 4.2
# File lib/arjdbc/hsqldb/adapter.rb, line 198 def truncate(table_name, name = nil) execute "TRUNCATE TABLE #{quote_table_name(table_name)}", name end
type_to_sql(type, limit = nil, precision = nil, scale = nil)
click to toggle source
@override
Calls superclass method
# File lib/arjdbc/hsqldb/adapter.rb, line 187 def type_to_sql(type, limit = nil, precision = nil, scale = nil) return super if defined?(::Jdbc::H2) || type.to_s != 'integer' || limit == nil type end
Private Instance Methods
_execute(sql, name = nil)
click to toggle source
@private
Calls superclass method
# File lib/arjdbc/hsqldb/adapter.rb, line 208 def _execute(sql, name = nil) result = super self.class.insert?(sql) ? last_insert_id : result end