# File lib/sequel/adapters/jdbc/hsqldb.rb, line 114 def primary_key_index_re PRIMARY_KEY_INDEX_RE end
module Sequel::JDBC::HSQLDB::DatabaseMethods
Instance methods for HSQLDB Database objects accessed via JDBC.
Constants
- DATABASE_ERROR_REGEXPS
- PRIMARY_KEY_INDEX_RE
Public Instance Methods
HSQLDB uses the :hsqldb database type.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 25 def database_type :hsqldb end
The version of the database, as an integer (e.g 2.2.5 -> 20205)
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 41 def db_version return @db_version if defined?(@db_version) v = get{DATABASE_VERSION(){}} @db_version = if v =~ /(\d+)\.(\d+)\.(\d+)/ $1.to_i * 10000 + $2.to_i * 100 + $3.to_i end end
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 29 def freeze db_version super end
HSQLDB uses an IDENTITY sequence as the default value for primary key columns.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 36 def serial_primary_key_options {:primary_key => true, :type => :integer, :identity=>true, :start_with=>1} end
HSQLDB supports DROP TABLE IF EXISTS
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 50 def supports_drop_table_if_exists? true end
Private Instance Methods
HSQLDB specific SQL for renaming columns, and changing column types and/or nullity.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 57 def alter_table_sql(table, op) case op[:op] when :add_column if op[:table] [super(table, op.merge(:table=>nil)), alter_table_sql(table, op.merge(:op=>:add_constraint, :type=>:foreign_key, :name=>op[:foreign_key_name], :columns=>[op[:name]], :table=>op[:table]))] else super end when :rename_column "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} RENAME TO #{quote_identifier(op[:new_name])}" when :set_column_type "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET DATA TYPE #{type_literal(op)}" when :set_column_null "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET #{op[:null] ? 'NULL' : 'NOT NULL'}" else super end end
HSQLDB requires parens around the SELECT, and the WITH DATA syntax.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 78 def create_table_as_sql(name, sql, options) "#{create_table_prefix_sql(name, options)} AS (#{sql}) WITH DATA" end
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 89 def database_error_regexps DATABASE_ERROR_REGEXPS end
IF EXISTS comes after table name on HSQLDB
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 94 def drop_table_sql(name, options) "DROP TABLE #{quote_schema_table(name)}#{' IF EXISTS' if options[:if_exists]}#{' CASCADE' if options[:cascade]}" end
IF EXISTS comes after view name on HSQLDB
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 99 def drop_view_sql(name, options) "DROP VIEW #{quote_schema_table(name)}#{' IF EXISTS' if options[:if_exists]}#{' CASCADE' if options[:cascade]}" end
Use IDENTITY() to get the last inserted id.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 104 def last_insert_id(conn, opts=OPTS) statement(conn) do |stmt| sql = 'CALL IDENTITY()' rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)} rs.next rs.getLong(1) end end
Primary key indexes appear to start with sys_idx_sys_pk_ on HSQLDB
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.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 121 def type_literal(column) if column[:identity] sql = "#{super} GENERATED BY DEFAULT AS IDENTITY" if sw = column[:start_with] sql += " (START WITH #{sw.to_i}" sql << " INCREMENT BY #{column[:increment_by].to_i}" if column[:increment_by] sql << ")" end sql else super end end
HSQLDB uses clob for text types.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 136 def uses_clob_for_text? true end
HSQLDB supports views with check option.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 141 def view_with_check_option_support :local end