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
22 def database_type
23   :hsqldb
24 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
38 def db_version
39   return @db_version if defined?(@db_version)
40   v = get(Sequel.function(:DATABASE_VERSION))
41   @db_version = if v =~ /(\d+)\.(\d+)\.(\d+)/
42     $1.to_i * 10000 + $2.to_i * 100 + $3.to_i
43   end
44 end
freeze() click to toggle source
Calls superclass method Sequel::JDBC::Transactions#freeze
   # File lib/sequel/adapters/jdbc/hsqldb.rb
26 def freeze
27   db_version
28   super
29 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
33 def serial_primary_key_options
34   {:primary_key => true, :type => :integer, :identity=>true, :start_with=>1}
35 end
supports_drop_table_if_exists?() click to toggle source

HSQLDB supports DROP TABLE IF EXISTS

   # File lib/sequel/adapters/jdbc/hsqldb.rb
47 def supports_drop_table_if_exists?
48   true
49 end

Private Instance Methods

alter_table_sql(table, op) click to toggle source
Calls superclass method
   # File lib/sequel/adapters/jdbc/hsqldb.rb
53 def alter_table_sql(table, op)
54   case op[:op]
55   when :add_column
56     if op[:table]
57       [super(table, op.merge(:table=>nil)),
58        alter_table_sql(table, op.merge(:op=>:add_constraint, :type=>:foreign_key, :name=>op[:foreign_key_constraint_name], :columns=>[op[:name]], :table=>op[:table]))]
59     else
60       super
61     end
62   when :rename_column
63     "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} RENAME TO #{quote_identifier(op[:new_name])}"
64   when :set_column_type
65     "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET DATA TYPE #{type_literal(op)}"
66   when :set_column_null
67     "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET #{op[:null] ? 'NULL' : 'NOT NULL'}"
68   else
69     super
70   end
71 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
74 def create_table_as_sql(name, sql, options)
75   "#{create_table_prefix_sql(name, options)} AS (#{sql}) WITH DATA"
76 end
database_error_regexps() click to toggle source
   # File lib/sequel/adapters/jdbc/hsqldb.rb
85 def database_error_regexps
86   DATABASE_ERROR_REGEXPS
87 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
90 def drop_table_sql(name, options)
91   "DROP TABLE #{quote_schema_table(name)}#{' IF EXISTS' if options[:if_exists]}#{' CASCADE' if options[:cascade]}"
92 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
95 def drop_view_sql(name, options)
96   "DROP VIEW #{quote_schema_table(name)}#{' IF EXISTS' if options[:if_exists]}#{' CASCADE' if options[:cascade]}"
97 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
100 def last_insert_id(conn, opts=OPTS)
101   statement(conn) do |stmt|
102     sql = 'CALL IDENTITY()'
103     rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)}
104     rs.next
105     rs.getLong(1)
106   end
107 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
110 def primary_key_index_re
111   /\Asys_idx_sys_pk_/i
112 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
117 def type_literal(column)
118   if column[:identity]
119     sql = "#{super} GENERATED BY DEFAULT AS IDENTITY"
120     if sw = column[:start_with]
121       sql += " (START WITH #{sw.to_i}"
122       sql << " INCREMENT BY #{column[:increment_by].to_i}" if column[:increment_by]
123       sql << ")"
124     end
125     sql
126   else
127     super
128   end
129 end
uses_clob_for_text?() click to toggle source

HSQLDB uses clob for text types.

    # File lib/sequel/adapters/jdbc/hsqldb.rb
132 def uses_clob_for_text?
133   true
134 end
view_with_check_option_support() click to toggle source

HSQLDB supports views with check option.

    # File lib/sequel/adapters/jdbc/hsqldb.rb
137 def view_with_check_option_support
138   :local
139 end