Module: ArJdbc::H2
- Includes:
- HSQLDB
- Defined in:
- lib/arjdbc/h2/adapter.rb
Defined Under Namespace
Modules: Column
Constant Summary
collapse
- ADAPTER_NAME =
'H2'
- NATIVE_DATABASE_TYPES =
{
:primary_key => "integer GENERATED BY DEFAULT AS IDENTITY(START WITH 0) PRIMARY KEY",
:boolean => { :name => "boolean" },
:tinyint => { :name => "tinyint", :limit => 1 },
:smallint => { :name => "smallint", :limit => 2 },
:bigint => { :name => "bigint", :limit => 8 },
:integer => { :name => "int", :limit => 4 },
:decimal => { :name => "decimal" },
:float => { :name => "float", :limit => 8 },
:double => { :name => "double", :limit => 8 },
:real => { :name => "real", :limit => 4 },
:date => { :name => "date" },
:time => { :name => "time" },
:timestamp => { :name => "timestamp" },
:binary => { :name => "binary" },
:string => { :name => "varchar", :limit => 255 },
:char => { :name => "char" },
:blob => { :name => "blob" },
:text => { :name => "clob" },
:clob => { :name => "clob" },
:uuid => { :name => "uuid" },
:other => { :name => "other" }, :array => { :name => "array" }, :varchar_casesensitive => { :name => 'VARCHAR_CASESENSITIVE' },
:varchar_ignorecase => { :name => 'VARCHAR_IGNORECASE' },
}
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from HSQLDB
#add_column, #add_limit_offset!, #change_column_default, #create_database, #drop_database, #last_insert_id, #quote_column_name, #recreate_database, #remove_index, #rename_column, #rename_table
Class Method Details
.arel2_visitors(config) ⇒ Object
.column_selector ⇒ Object
11
12
13
|
# File 'lib/arjdbc/h2/adapter.rb', line 11
def self.column_selector
[ /\.h2\./i, lambda { |cfg, column| column.extend(::ArJdbc::H2::Column) } ]
end
|
.jdbc_connection_class ⇒ Object
Instance Method Details
#adapter_name ⇒ Object
71
72
73
|
# File 'lib/arjdbc/h2/adapter.rb', line 71
def adapter_name ADAPTER_NAME
end
|
#change_column(table_name, column_name, type, options = {}) ⇒ Object
158
159
160
161
162
|
# File 'lib/arjdbc/h2/adapter.rb', line 158
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
|
#columns(table_name, name = nil) ⇒ Object
154
155
156
|
# File 'lib/arjdbc/h2/adapter.rb', line 154
def columns(table_name, name = nil)
@connection.columns_internal(table_name.to_s, name, h2_schema)
end
|
#current_schema ⇒ Object
164
165
166
|
# File 'lib/arjdbc/h2/adapter.rb', line 164
def current_schema
execute('CALL SCHEMA()')[0].values[0]
end
|
#explain(arel, binds = []) ⇒ Object
185
186
187
188
189
|
# File 'lib/arjdbc/h2/adapter.rb', line 185
def explain(arel, binds = [])
sql = "EXPLAIN #{to_sql(arel, binds)}"
raw_result = execute(sql, "EXPLAIN", binds)
raw_result[0].values.join("\n") end
|
#h2_adapter ⇒ Object
84
85
86
|
# File 'lib/arjdbc/h2/adapter.rb', line 84
def h2_adapter true
end
|
#modify_types(types) ⇒ Object
119
120
121
|
# File 'lib/arjdbc/h2/adapter.rb', line 119
def modify_types(types)
types
end
|
#native_database_types ⇒ Object
115
116
117
|
# File 'lib/arjdbc/h2/adapter.rb', line 115
def native_database_types
NATIVE_DATABASE_TYPES.dup
end
|
#quote(value, column = nil) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/arjdbc/h2/adapter.rb', line 168
def quote(value, column = nil) case value
when String
if value.empty?
"''"
else
super
end
else
super
end
end
|
#supports_explain? ⇒ Boolean
183
|
# File 'lib/arjdbc/h2/adapter.rb', line 183
def supports_explain?; true; end
|
#tables ⇒ Object
150
151
152
|
# File 'lib/arjdbc/h2/adapter.rb', line 150
def tables
@connection.tables(nil, h2_schema)
end
|
#type_to_sql(type, limit = nil, precision = nil, scale = nil) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/arjdbc/h2/adapter.rb', line 123
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
|