# File lib/sequel/adapters/jdbc/hsqldb.rb, line 78 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
database_type()
click to toggle source
HSQLDB uses the :hsqldb database type.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 15 def database_type :hsqldb 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, line 26 def db_version @db_version ||= begin v = get{DATABASE_VERSION(){}} if v =~ /(\d+)\.(\d+)\.(\d+)/ $1.to_i * 10000 + $2.to_i * 100 + $3.to_i end end 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, line 21 def serial_primary_key_options {:primary_key => true, :type => :integer, :identity=>true, :start_with=>1} end
Private Instance Methods
alter_table_sql(table, op)
click to toggle source
HSQLDB specific SQL for renaming columns, and changing column types and/or nullity.
Calls superclass method
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 38 def alter_table_sql(table, op) case op[:op] 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
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, line 52 def create_table_as_sql(name, sql, options) "#{create_table_prefix_sql(name, options)} AS (#{sql}) WITH DATA" end
database_error_regexps()
click to toggle source
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 63 def database_error_regexps DATABASE_ERROR_REGEXPS end
last_insert_id(conn, opts={})
click to toggle source
Use IDENTITY() to get the last inserted id.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 68 def last_insert_id(conn, opts={}) statement(conn) do |stmt| sql = 'CALL IDENTITY()' rs = log_yield(sql){stmt.executeQuery(sql)} rs.next rs.getInt(1) end 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, line 85 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
uses_clob_for_text?()
click to toggle source
HSQLDB uses clob for text types.
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 100 def uses_clob_for_text? true end