# File lib/sequel/adapters/jdbc/hsqldb.rb 108 def primary_key_index_re 109 /\Asys_idx_sys_pk_/i 110 end
module Sequel::JDBC::HSQLDB::DatabaseMethods
Constants
- DATABASE_ERROR_REGEXPS
Public Instance Methods
database_type()
click to toggle source
# File lib/sequel/adapters/jdbc/hsqldb.rb 20 def database_type 21 :hsqldb 22 end
db_version()
click to toggle source
The version of the database, as an integer (e.g 2.2.5 -> 20205)
# File lib/sequel/adapters/jdbc/hsqldb.rb 36 def db_version 37 return @db_version if defined?(@db_version) 38 v = get(Sequel.function(:DATABASE_VERSION)) 39 @db_version = if v =~ /(\d+)\.(\d+)\.(\d+)/ 40 $1.to_i * 10000 + $2.to_i * 100 + $3.to_i 41 end 42 end
freeze()
click to toggle source
Calls superclass method
Sequel::JDBC::Transactions#freeze
# File lib/sequel/adapters/jdbc/hsqldb.rb 24 def freeze 25 db_version 26 super 27 end
serial_primary_key_options()
click to toggle source
HSQLDB
uses an IDENTITY sequence as the default value for primary key columns.
# File lib/sequel/adapters/jdbc/hsqldb.rb 31 def serial_primary_key_options 32 {:primary_key => true, :type => :integer, :identity=>true, :start_with=>1} 33 end
supports_drop_table_if_exists?()
click to toggle source
HSQLDB
supports DROP TABLE IF EXISTS
# File lib/sequel/adapters/jdbc/hsqldb.rb 45 def supports_drop_table_if_exists? 46 true 47 end
Private Instance Methods
alter_table_sql(table, op)
click to toggle source
Calls superclass method
# File lib/sequel/adapters/jdbc/hsqldb.rb 51 def alter_table_sql(table, op) 52 case op[:op] 53 when :add_column 54 if op[:table] 55 [super(table, op.merge(:table=>nil)), 56 alter_table_sql(table, op.merge(:op=>:add_constraint, :type=>:foreign_key, :name=>op[:foreign_key_constraint_name], :columns=>[op[:name]], :table=>op[:table]))] 57 else 58 super 59 end 60 when :rename_column 61 "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} RENAME TO #{quote_identifier(op[:new_name])}" 62 when :set_column_type 63 "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET DATA TYPE #{type_literal(op)}" 64 when :set_column_null 65 "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET #{op[:null] ? 'NULL' : 'NOT NULL'}" 66 else 67 super 68 end 69 end
create_table_as_sql(name, sql, options)
click to toggle source
HSQLDB
requires parens around the SELECT, and the WITH DATA syntax.
# File lib/sequel/adapters/jdbc/hsqldb.rb 72 def create_table_as_sql(name, sql, options) 73 "#{create_table_prefix_sql(name, options)} AS (#{sql}) WITH DATA" 74 end
database_error_regexps()
click to toggle source
# File lib/sequel/adapters/jdbc/hsqldb.rb 83 def database_error_regexps 84 DATABASE_ERROR_REGEXPS 85 end
drop_table_sql(name, options)
click to toggle source
IF EXISTS comes after table name on HSQLDB
# File lib/sequel/adapters/jdbc/hsqldb.rb 88 def drop_table_sql(name, options) 89 "DROP TABLE #{quote_schema_table(name)}#{' IF EXISTS' if options[:if_exists]}#{' CASCADE' if options[:cascade]}" 90 end
drop_view_sql(name, options)
click to toggle source
IF EXISTS comes after view name on HSQLDB
# File lib/sequel/adapters/jdbc/hsqldb.rb 93 def drop_view_sql(name, options) 94 "DROP VIEW #{quote_schema_table(name)}#{' IF EXISTS' if options[:if_exists]}#{' CASCADE' if options[:cascade]}" 95 end
last_insert_id(conn, opts=OPTS)
click to toggle source
Use IDENTITY() to get the last inserted id.
# File lib/sequel/adapters/jdbc/hsqldb.rb 98 def last_insert_id(conn, opts=OPTS) 99 statement(conn) do |stmt| 100 sql = 'CALL IDENTITY()' 101 rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)} 102 rs.next 103 rs.getLong(1) 104 end 105 end
primary_key_index_re()
click to toggle source
Primary key indexes appear to start with sys_idx_sys_pk_ on HSQLDB
type_literal(column)
click to toggle source
If an :identity option is present in the column, add the necessary IDENTITY SQL
. It's possible to use an IDENTITY type, but that defaults the sequence to start at 0 instead of 1, and we don't want that.
Calls superclass method
# File lib/sequel/adapters/jdbc/hsqldb.rb 115 def type_literal(column) 116 if column[:identity] 117 sql = "#{super} GENERATED BY DEFAULT AS IDENTITY" 118 if sw = column[:start_with] 119 sql += " (START WITH #{sw.to_i}" 120 sql << " INCREMENT BY #{column[:increment_by].to_i}" if column[:increment_by] 121 sql << ")" 122 end 123 sql 124 else 125 super 126 end 127 end
uses_clob_for_text?()
click to toggle source
HSQLDB
uses clob for text types.
# File lib/sequel/adapters/jdbc/hsqldb.rb 130 def uses_clob_for_text? 131 true 132 end
view_with_check_option_support()
click to toggle source
HSQLDB
supports views with check option.
# File lib/sequel/adapters/jdbc/hsqldb.rb 135 def view_with_check_option_support 136 :local 137 end