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 25
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 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
freeze() click to toggle source
Calls superclass method Sequel::JDBC::Transactions#freeze
# File lib/sequel/adapters/jdbc/hsqldb.rb, line 29
def freeze
  db_version
  super
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 36
def serial_primary_key_options
  {:primary_key => true, :type => :integer, :identity=>true, :start_with=>1}
end
supports_drop_table_if_exists?() click to toggle source

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

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 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
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 78
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 89
def database_error_regexps
  DATABASE_ERROR_REGEXPS
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, 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
drop_view_sql(name, options) click to toggle source

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
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, 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_index_re() click to toggle source

Primary key indexes appear to start with sys_idx_sys_pk_ on HSQLDB

# File lib/sequel/adapters/jdbc/hsqldb.rb, line 114
def primary_key_index_re
  PRIMARY_KEY_INDEX_RE
end
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 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
uses_clob_for_text?() click to toggle source

HSQLDB uses clob for text types.

# File lib/sequel/adapters/jdbc/hsqldb.rb, line 136
def uses_clob_for_text?
  true
end
view_with_check_option_support() click to toggle source

HSQLDB supports views with check option.

# File lib/sequel/adapters/jdbc/hsqldb.rb, line 141
def view_with_check_option_support
  :local
end