@see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
# File lib/arjdbc/h2/adapter.rb, line 76 def self.arel_visitor_type(config = nil) require 'arel/visitors/h2'; ::Arel::Visitors::H2 end
@see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
# File lib/arjdbc/h2/adapter.rb, line 14 def self.column_selector [ /\.h2\./, lambda { |config, column| column.extend(Column) } ] end
@see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
# File lib/arjdbc/h2/adapter.rb, line 9 def self.jdbc_connection_class ::ActiveRecord::ConnectionAdapters::H2JdbcConnection end
@override
# File lib/arjdbc/h2/adapter.rb, line 83 def adapter_name ADAPTER_NAME end
@override
# File lib/arjdbc/h2/adapter.rb, line 175 def change_column(table_name, column_name, type, options = {}) execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} #{type_to_sql(type, options[:limit])}" change_column_default(table_name, column_name, options[:default]) if options_include_default?(options) change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null) end
@override
# File lib/arjdbc/h2/adapter.rb, line 170 def columns(table_name, name = nil) @connection.columns_internal(table_name.to_s, nil, h2_schema) end
@private
# File lib/arjdbc/h2/adapter.rb, line 238 def create_database(name = nil, options = {}); end
# File lib/arjdbc/h2/adapter.rb, line 181 def current_schema execute('CALL SCHEMA()')[0].values[0] end
@private
# File lib/arjdbc/h2/adapter.rb, line 246 def database_path(base_only = false) db_path = jdbc_connection(true).getSession.getDataHandler.getDatabasePath return db_path if base_only if File.exist?(mv_path = "#{db_path}.mv.db") return mv_path else "#{db_path}.h2.db" end end
@private
# File lib/arjdbc/h2/adapter.rb, line 241 def drop_database(name = nil) execute('DROP ALL OBJECTS') end
@override
# File lib/arjdbc/h2/adapter.rb, line 160 def empty_insert_statement_value "VALUES ()" end
@override
# File lib/arjdbc/h2/adapter.rb, line 205 def explain(arel, binds = []) sql = "EXPLAIN #{to_sql(arel, binds)}" raw_result = exec_query_raw(sql, "EXPLAIN", binds) raw_result[0].values.join("\n") # [ "SELECT \n ..." ].to_s end
@deprecated no longer used. only here for backwards compatibility with 1.2
# File lib/arjdbc/h2/adapter.rb, line 88 def h2_adapter true end
@override
# File lib/arjdbc/h2/adapter.rb, line 257 def jdbc_connection(unwrap = nil) java_connection = raw_connection.connection return java_connection unless unwrap if java_connection.java_class.name == 'org.h2.jdbc.JdbcConnection' return java_connection end connection_class = java.sql.Connection.java_class if java_connection.wrapper_for?(connection_class) java_connection.unwrap(connection_class) # java.sql.Wrapper.unwrap elsif java_connection.respond_to?(:connection) # e.g. org.apache.tomcat.jdbc.pool.PooledConnection java_connection.connection # getConnection else java_connection end end
@override
# File lib/arjdbc/h2/adapter.rb, line 127 def native_database_types NATIVE_DATABASE_TYPES end
@override
# File lib/arjdbc/h2/adapter.rb, line 186 def quote(value, column = nil) case value when String if value.empty? "''" else super end else super end end
@private
# File lib/arjdbc/h2/adapter.rb, line 232 def recreate_database(name = nil, options = {}) drop_database(name) create_database(name, options) end
# File lib/arjdbc/h2/adapter.rb, line 227 def shutdown execute 'SHUTDOWN COMPACT' end
@override
# File lib/arjdbc/h2/adapter.rb, line 212 def structure_dump execute('SCRIPT SIMPLE').map do |result| # [ { 'script' => SQL }, { 'script' ... }, ... ] case sql = result.first[1] # ['script'] when /CREATE USER IF NOT EXISTS SA/ then nil else sql end end.compact.join("\n\n") end
@see structure_dump
# File lib/arjdbc/h2/adapter.rb, line 223 def structure_load(dump) dump.each_line("\n\n") { |ddl| execute(ddl) } end
@override
# File lib/arjdbc/h2/adapter.rb, line 202 def supports_explain?; true; end
@override
# File lib/arjdbc/h2/adapter.rb, line 165 def tables @connection.tables(nil, h2_schema) end
@override
# File lib/arjdbc/h2/adapter.rb, line 132 def type_to_sql(type, limit = nil, precision = nil, scale = nil) case type.to_sym when :integer case limit when 1; 'tinyint' when 2; 'smallint' when nil, 3, 4; 'int' when 5..8; 'bigint' else raise(ActiveRecordError, "No integer type has byte size #{limit}") end when :float case limit when 1..4; 'real' when 5..8; 'double' else raise(ActiveRecordError, "No float type has byte size #{limit}") end when :binary if limit && limit < 2 * 1024 * 1024 'binary' else 'blob' end else super end end
Generated with the Darkfish Rdoc Generator 2.