# File lib/sequel/adapters/jdbc/h2.rb 153 def primary_key_index_re 154 /\Aprimary_key/i 155 end
module Sequel::JDBC::H2::DatabaseMethods
Constants
- DATABASE_ERROR_REGEXPS
Public Instance Methods
commit_prepared_transaction(transaction_id, opts=OPTS)
click to toggle source
# File lib/sequel/adapters/jdbc/h2.rb 17 def commit_prepared_transaction(transaction_id, opts=OPTS) 18 run("COMMIT TRANSACTION #{transaction_id}", opts) 19 end
database_type()
click to toggle source
# File lib/sequel/adapters/jdbc/h2.rb 21 def database_type 22 :h2 23 end
freeze()
click to toggle source
Calls superclass method
# File lib/sequel/adapters/jdbc/h2.rb 25 def freeze 26 h2_version 27 super 28 end
h2_version()
click to toggle source
# File lib/sequel/adapters/jdbc/h2.rb 30 def h2_version 31 @h2_version ||= get(Sequel.function(:H2VERSION)) 32 end
rollback_prepared_transaction(transaction_id, opts=OPTS)
click to toggle source
# File lib/sequel/adapters/jdbc/h2.rb 34 def rollback_prepared_transaction(transaction_id, opts=OPTS) 35 run("ROLLBACK TRANSACTION #{transaction_id}", opts) 36 end
serial_primary_key_options()
click to toggle source
H2
uses an IDENTITY type for primary keys
# File lib/sequel/adapters/jdbc/h2.rb 39 def serial_primary_key_options 40 {:primary_key => true, :type => :identity, :identity=>true} 41 end
supports_create_table_if_not_exists?()
click to toggle source
H2
supports CREATE TABLE IF NOT EXISTS syntax
# File lib/sequel/adapters/jdbc/h2.rb 44 def supports_create_table_if_not_exists? 45 true 46 end
supports_prepared_transactions?()
click to toggle source
H2
supports prepared transactions
# File lib/sequel/adapters/jdbc/h2.rb 49 def supports_prepared_transactions? 50 true 51 end
supports_savepoints?()
click to toggle source
H2
supports savepoints
# File lib/sequel/adapters/jdbc/h2.rb 54 def supports_savepoints? 55 true 56 end
Private Instance Methods
alter_table_sql(table, op)
click to toggle source
Calls superclass method
# File lib/sequel/adapters/jdbc/h2.rb 75 def alter_table_sql(table, op) 76 case op[:op] 77 when :add_column 78 if (pk = op.delete(:primary_key)) || (ref = op.delete(:table)) 79 if pk 80 op[:null] = false 81 end 82 83 sqls = [super(table, op)] 84 85 if pk && (h2_version >= '1.4' || op[:type] != :identity) 86 # H2 needs to add a primary key column as a constraint in this case 87 sqls << "ALTER TABLE #{quote_schema_table(table)} ADD PRIMARY KEY (#{quote_identifier(op[:name])})" 88 end 89 90 if ref 91 op[:table] = ref 92 constraint_name = op[:foreign_key_constraint_name] 93 sqls << "ALTER TABLE #{quote_schema_table(table)} ADD#{" CONSTRAINT #{quote_identifier(constraint_name)}" if constraint_name} FOREIGN KEY (#{quote_identifier(op[:name])}) #{column_references_sql(op)}" 94 end 95 96 sqls 97 else 98 super(table, op) 99 end 100 when :rename_column 101 "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} RENAME TO #{quote_identifier(op[:new_name])}" 102 when :set_column_null 103 "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET#{' NOT' unless op[:null]} NULL" 104 when :set_column_type 105 if sch = schema(table) 106 if cs = sch.each{|k, v| break v if k == op[:name]; nil} 107 cs = cs.dup 108 cs[:default] = cs[:ruby_default] 109 op = cs.merge!(op) 110 end 111 end 112 sql = "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} #{type_literal(op)}".dup 113 column_definition_order.each{|m| send(:"column_definition_#{m}_sql", sql, op)} 114 sql 115 when :drop_constraint 116 if op[:type] == :primary_key 117 "ALTER TABLE #{quote_schema_table(table)} DROP PRIMARY KEY" 118 else 119 super(table, op) 120 end 121 else 122 super(table, op) 123 end 124 end
can_add_primary_key_constraint_on_nullable_columns?()
click to toggle source
H2
does not allow adding primary key constraints to NULLable columns.
# File lib/sequel/adapters/jdbc/h2.rb 61 def can_add_primary_key_constraint_on_nullable_columns? 62 false 63 end
commit_transaction(conn, opts=OPTS)
click to toggle source
If the :prepare option is given and we aren't in a savepoint, prepare the transaction for a two-phase commit.
Calls superclass method
# File lib/sequel/adapters/jdbc/h2.rb 67 def commit_transaction(conn, opts=OPTS) 68 if (s = opts[:prepare]) && savepoint_level(conn) <= 1 69 log_connection_execute(conn, "PREPARE COMMIT #{s}") 70 else 71 super 72 end 73 end
connection_pool_default_options()
click to toggle source
Default to a single connection for a memory database.
Calls superclass method
# File lib/sequel/adapters/jdbc/h2.rb 127 def connection_pool_default_options 128 o = super 129 uri == 'jdbc:h2:mem:' ? o.merge(:max_connections=>1) : o 130 end
database_error_regexps()
click to toggle source
# File lib/sequel/adapters/jdbc/h2.rb 139 def database_error_regexps 140 DATABASE_ERROR_REGEXPS 141 end
last_insert_id(conn, opts=OPTS)
click to toggle source
Use IDENTITY() to get the last inserted id.
# File lib/sequel/adapters/jdbc/h2.rb 144 def last_insert_id(conn, opts=OPTS) 145 statement(conn) do |stmt| 146 sql = 'SELECT IDENTITY();' 147 rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)} 148 rs.next 149 rs.getLong(1) 150 end 151 end
primary_key_index_re()
click to toggle source
supports_named_column_constraints?()
click to toggle source
H2
does not support named column constraints.
# File lib/sequel/adapters/jdbc/h2.rb 158 def supports_named_column_constraints? 159 false 160 end
type_literal_generic_bignum_symbol(column)
click to toggle source
Use BIGINT IDENTITY for identity columns that use :Bignum type
Calls superclass method
# File lib/sequel/adapters/jdbc/h2.rb 163 def type_literal_generic_bignum_symbol(column) 164 column[:identity] ? 'BIGINT IDENTITY' : super 165 end