activerecord-jdbc-adapter 70.0.pre-java → 70.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/activerecord-jdbc-adapter.gemspec +1 -3
- data/lib/arel/visitors/compat.rb +5 -33
- data/lib/arel/visitors/h2.rb +1 -13
- data/lib/arel/visitors/hsqldb.rb +1 -21
- data/lib/arel/visitors/sql_server.rb +2 -103
- data/lib/arjdbc/abstract/core.rb +8 -9
- data/lib/arjdbc/abstract/database_statements.rb +8 -0
- data/lib/arjdbc/discover.rb +0 -67
- data/lib/arjdbc/jdbc/adapter.rb +1 -1
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/column.rb +1 -26
- data/lib/arjdbc/jdbc.rb +0 -7
- data/lib/arjdbc/mysql/adapter.rb +2 -1
- data/lib/arjdbc/oracle/adapter.rb +4 -23
- data/lib/arjdbc/postgresql/adapter.rb +152 -3
- data/lib/arjdbc/postgresql/oid_types.rb +155 -108
- data/lib/arjdbc/sqlite3/adapter.rb +54 -36
- data/lib/arjdbc/tasks/database_tasks.rb +0 -15
- data/lib/arjdbc/util/serialized_attributes.rb +0 -22
- data/lib/arjdbc/util/table_copier.rb +2 -1
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/02-test.rake +3 -18
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +5 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +5 -0
- metadata +5 -38
- data/lib/active_record/connection_adapters/as400_adapter.rb +0 -2
- data/lib/active_record/connection_adapters/db2_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/derby_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/informix_adapter.rb +0 -1
- data/lib/arel/visitors/db2.rb +0 -137
- data/lib/arel/visitors/derby.rb +0 -112
- data/lib/arel/visitors/firebird.rb +0 -79
- data/lib/arjdbc/db2/adapter.rb +0 -808
- data/lib/arjdbc/db2/as400.rb +0 -142
- data/lib/arjdbc/db2/column.rb +0 -131
- data/lib/arjdbc/db2/connection_methods.rb +0 -48
- data/lib/arjdbc/db2.rb +0 -4
- data/lib/arjdbc/derby/active_record_patch.rb +0 -13
- data/lib/arjdbc/derby/adapter.rb +0 -521
- data/lib/arjdbc/derby/connection_methods.rb +0 -20
- data/lib/arjdbc/derby/schema_creation.rb +0 -15
- data/lib/arjdbc/derby.rb +0 -3
- data/lib/arjdbc/firebird/adapter.rb +0 -413
- data/lib/arjdbc/firebird/connection_methods.rb +0 -23
- data/lib/arjdbc/firebird.rb +0 -4
- data/lib/arjdbc/informix/adapter.rb +0 -139
- data/lib/arjdbc/informix/connection_methods.rb +0 -9
- data/lib/arjdbc/sybase/adapter.rb +0 -47
- data/lib/arjdbc/sybase.rb +0 -2
- data/lib/arjdbc/tasks/db2_database_tasks.rb +0 -104
- data/lib/arjdbc/tasks/derby_database_tasks.rb +0 -95
- data/src/java/arjdbc/derby/DerbyModule.java +0 -178
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +0 -152
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +0 -174
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +0 -75
@@ -1,413 +0,0 @@
|
|
1
|
-
ArJdbc.load_java_part :Firebird
|
2
|
-
|
3
|
-
require 'arel/visitors/firebird'
|
4
|
-
|
5
|
-
module ArJdbc
|
6
|
-
module Firebird
|
7
|
-
|
8
|
-
# @private
|
9
|
-
def self.extended(adapter); initialize!; end
|
10
|
-
|
11
|
-
# @private
|
12
|
-
@@_initialized = nil
|
13
|
-
|
14
|
-
# @private
|
15
|
-
def self.initialize!
|
16
|
-
return if @@_initialized; @@_initialized = true
|
17
|
-
|
18
|
-
require 'arjdbc/util/serialized_attributes'
|
19
|
-
Util::SerializedAttributes.setup /blob/i
|
20
|
-
end
|
21
|
-
|
22
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
|
23
|
-
def self.jdbc_connection_class
|
24
|
-
::ActiveRecord::ConnectionAdapters::FirebirdJdbcConnection
|
25
|
-
end
|
26
|
-
|
27
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
|
28
|
-
def self.column_selector
|
29
|
-
[ /firebird/i, lambda { |cfg, column| column.extend(Column) } ]
|
30
|
-
end
|
31
|
-
|
32
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcColumn
|
33
|
-
module Column
|
34
|
-
|
35
|
-
def default_value(value)
|
36
|
-
return nil unless value
|
37
|
-
if value =~ /^\s*DEFAULT\s+(.*)\s*$/i
|
38
|
-
return $1 unless $1.upcase == 'NULL'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
|
44
|
-
def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::FirebirdColumn end
|
45
|
-
|
46
|
-
# @private
|
47
|
-
@@emulate_booleans = true
|
48
|
-
|
49
|
-
# Boolean emulation can be disabled using :
|
50
|
-
#
|
51
|
-
# ArJdbc::Firebird.emulate_booleans = false
|
52
|
-
#
|
53
|
-
def self.emulate_booleans?; @@emulate_booleans; end
|
54
|
-
# @deprecated Use {#emulate_booleans?} instead.
|
55
|
-
def self.emulate_booleans; @@emulate_booleans; end
|
56
|
-
# @see #emulate_booleans?
|
57
|
-
def self.emulate_booleans=(emulate); @@emulate_booleans = emulate; end
|
58
|
-
|
59
|
-
|
60
|
-
@@update_lob_values = true
|
61
|
-
|
62
|
-
# Updating records with LOB values (binary/text columns) in a separate
|
63
|
-
# statement can be disabled using :
|
64
|
-
#
|
65
|
-
# ArJdbc::Firebird.update_lob_values = false
|
66
|
-
def self.update_lob_values?; @@update_lob_values; end
|
67
|
-
# @see #update_lob_values?
|
68
|
-
def self.update_lob_values=(update); @@update_lob_values = update; end
|
69
|
-
|
70
|
-
# @see #update_lob_values?
|
71
|
-
def update_lob_values?; Firebird.update_lob_values?; end
|
72
|
-
|
73
|
-
# @see #quote
|
74
|
-
# @private
|
75
|
-
BLOB_VALUE_MARKER = "''"
|
76
|
-
|
77
|
-
ADAPTER_NAME = 'Firebird'.freeze
|
78
|
-
|
79
|
-
def adapter_name
|
80
|
-
ADAPTER_NAME
|
81
|
-
end
|
82
|
-
|
83
|
-
NATIVE_DATABASE_TYPES = {
|
84
|
-
:primary_key => "integer not null primary key",
|
85
|
-
:string => { :name => "varchar", :limit => 255 },
|
86
|
-
:text => { :name => "blob sub_type text" },
|
87
|
-
:integer => { :name => "integer" },
|
88
|
-
:float => { :name => "float" },
|
89
|
-
:datetime => { :name => "timestamp" },
|
90
|
-
:timestamp => { :name => "timestamp" },
|
91
|
-
:time => { :name => "time" },
|
92
|
-
:date => { :name => "date" },
|
93
|
-
:binary => { :name => "blob" },
|
94
|
-
:boolean => { :name => 'char', :limit => 1 },
|
95
|
-
:numeric => { :name => "numeric" },
|
96
|
-
:decimal => { :name => "decimal" },
|
97
|
-
:char => { :name => "char" },
|
98
|
-
}
|
99
|
-
|
100
|
-
def native_database_types
|
101
|
-
NATIVE_DATABASE_TYPES
|
102
|
-
end
|
103
|
-
|
104
|
-
def initialize_type_map(m)
|
105
|
-
register_class_with_limit m, %r(binary)i, ActiveRecord::Type::Binary
|
106
|
-
register_class_with_limit m, %r(text)i, ActiveRecord::Type::Text
|
107
|
-
|
108
|
-
register_class_with_limit m, %r(date(?:\(.*?\))?$)i, DateType
|
109
|
-
register_class_with_limit m, %r(time(?:\(.*?\))?$)i, ActiveRecord::Type::Time
|
110
|
-
|
111
|
-
register_class_with_limit m, %r(float)i, ActiveRecord::Type::Float
|
112
|
-
register_class_with_limit m, %r(int)i, ActiveRecord::Type::Integer
|
113
|
-
|
114
|
-
m.alias_type %r(blob)i, 'binary'
|
115
|
-
m.alias_type %r(clob)i, 'text'
|
116
|
-
m.alias_type %r(double)i, 'float'
|
117
|
-
|
118
|
-
m.register_type(%r(decimal)i) do |sql_type|
|
119
|
-
scale = extract_scale(sql_type)
|
120
|
-
precision = extract_precision(sql_type)
|
121
|
-
if scale == 0
|
122
|
-
ActiveRecord::Type::Integer.new(precision: precision)
|
123
|
-
else
|
124
|
-
ActiveRecord::Type::Decimal.new(precision: precision, scale: scale)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
m.alias_type %r(numeric)i, 'decimal'
|
128
|
-
|
129
|
-
register_class_with_limit m, %r(varchar)i, ActiveRecord::Type::String
|
130
|
-
|
131
|
-
m.register_type(%r(^char)i) do |sql_type|
|
132
|
-
precision = extract_precision(sql_type)
|
133
|
-
if Firebird.emulate_booleans? && precision == 1
|
134
|
-
ActiveRecord::Type::Boolean.new
|
135
|
-
else
|
136
|
-
ActiveRecord::Type::String.new(:precision => precision)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
register_class_with_limit m, %r(datetime)i, ActiveRecord::Type::DateTime
|
141
|
-
register_class_with_limit m, %r(timestamp)i, TimestampType
|
142
|
-
end if AR42
|
143
|
-
|
144
|
-
def clear_cache!
|
145
|
-
super
|
146
|
-
reload_type_map
|
147
|
-
end if AR42
|
148
|
-
|
149
|
-
# @private
|
150
|
-
class DateType < ActiveRecord::Type::Date
|
151
|
-
# NOTE: quote still gets called ...
|
152
|
-
#def type_cast_for_database(value)
|
153
|
-
# if value.acts_like?(:date)
|
154
|
-
# "'#{value.strftime("%Y-%m-%d")}'"
|
155
|
-
# else
|
156
|
-
# super
|
157
|
-
# end
|
158
|
-
#end
|
159
|
-
end if AR42
|
160
|
-
|
161
|
-
# @private
|
162
|
-
class TimestampType < ActiveRecord::Type::DateTime
|
163
|
-
def type; :timestamp end
|
164
|
-
end if AR42
|
165
|
-
|
166
|
-
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
|
167
|
-
case type
|
168
|
-
when :integer
|
169
|
-
case limit
|
170
|
-
when nil then 'integer'
|
171
|
-
when 1..2 then 'smallint'
|
172
|
-
when 3..4 then 'integer'
|
173
|
-
when 5..8 then 'bigint'
|
174
|
-
else raise(ActiveRecordError, "No integer type has byte size #{limit}. "<<
|
175
|
-
"Use a NUMERIC with PRECISION 0 instead.")
|
176
|
-
end
|
177
|
-
when :float
|
178
|
-
if limit.nil? || limit <= 4
|
179
|
-
'float'
|
180
|
-
else
|
181
|
-
'double precision'
|
182
|
-
end
|
183
|
-
else super
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
# Does this adapter support migrations?
|
188
|
-
def supports_migrations?
|
189
|
-
true
|
190
|
-
end
|
191
|
-
|
192
|
-
# Can this adapter determine the primary key for tables not attached
|
193
|
-
# to an Active Record class, such as join tables?
|
194
|
-
def supports_primary_key?
|
195
|
-
true
|
196
|
-
end
|
197
|
-
|
198
|
-
# Does this adapter support DDL rollbacks in transactions? That is, would
|
199
|
-
# CREATE TABLE or ALTER TABLE get rolled back by a transaction? PostgreSQL,
|
200
|
-
# SQL Server, and others support this. MySQL and others do not.
|
201
|
-
def supports_ddl_transactions?
|
202
|
-
false
|
203
|
-
end
|
204
|
-
|
205
|
-
# Does this adapter restrict the number of IDs you can use in a list.
|
206
|
-
# Oracle has a limit of 1000.
|
207
|
-
def ids_in_list_limit
|
208
|
-
1499
|
209
|
-
end
|
210
|
-
|
211
|
-
def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
|
212
|
-
execute(sql, name, binds)
|
213
|
-
id_value
|
214
|
-
end
|
215
|
-
|
216
|
-
def add_limit_offset!(sql, options)
|
217
|
-
if limit = options[:limit]
|
218
|
-
insert_limit_offset!(sql, limit, options[:offset])
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
# @private
|
223
|
-
SELECT_RE = /\A(\s*SELECT\s)/i
|
224
|
-
|
225
|
-
def insert_limit_offset!(sql, limit, offset)
|
226
|
-
lim_off = ''
|
227
|
-
lim_off << "FIRST #{limit}" if limit
|
228
|
-
lim_off << " SKIP #{offset}" if offset
|
229
|
-
lim_off.strip!
|
230
|
-
|
231
|
-
sql.sub!(SELECT_RE, "\\&#{lim_off} ") unless lim_off.empty?
|
232
|
-
end
|
233
|
-
|
234
|
-
# Should primary key values be selected from their corresponding
|
235
|
-
# sequence before the insert statement?
|
236
|
-
# @see #next_sequence_value
|
237
|
-
# @override
|
238
|
-
def prefetch_primary_key?(table_name = nil)
|
239
|
-
return true if table_name.nil?
|
240
|
-
primary_keys(table_name.to_s).size == 1
|
241
|
-
# columns(table_name).count { |column| column.primary } == 1
|
242
|
-
end
|
243
|
-
|
244
|
-
IDENTIFIER_LENGTH = 31 # usual DB meta-identifier: 31 chars maximum
|
245
|
-
|
246
|
-
def table_alias_length; IDENTIFIER_LENGTH; end
|
247
|
-
def table_name_length; IDENTIFIER_LENGTH; end
|
248
|
-
def index_name_length; IDENTIFIER_LENGTH; end
|
249
|
-
def column_name_length; IDENTIFIER_LENGTH; end
|
250
|
-
|
251
|
-
def default_sequence_name(table_name, column = nil)
|
252
|
-
len = IDENTIFIER_LENGTH - 4
|
253
|
-
table_name.to_s.gsub (/(^|\.)([\w$-]{1,#{len}})([\w$-]*)$/), '\1\2_seq'
|
254
|
-
end
|
255
|
-
|
256
|
-
# Set the sequence to the max value of the table's column.
|
257
|
-
def reset_sequence!(table, column, sequence = nil)
|
258
|
-
max_id = select_value("SELECT max(#{column}) FROM #{table}")
|
259
|
-
execute("ALTER SEQUENCE #{default_sequence_name(table, column)} RESTART WITH #{max_id}")
|
260
|
-
end
|
261
|
-
|
262
|
-
def next_sequence_value(sequence_name)
|
263
|
-
select_one("SELECT GEN_ID(#{sequence_name}, 1 ) FROM RDB$DATABASE;")["gen_id"]
|
264
|
-
end
|
265
|
-
|
266
|
-
def create_table(name, options = {})
|
267
|
-
super(name, options)
|
268
|
-
execute "CREATE GENERATOR #{default_sequence_name(name)}"
|
269
|
-
end
|
270
|
-
|
271
|
-
def rename_table(name, new_name)
|
272
|
-
execute "RENAME #{name} TO #{new_name}"
|
273
|
-
name_seq, new_name_seq = default_sequence_name(name), default_sequence_name(new_name)
|
274
|
-
execute_quietly "UPDATE RDB$GENERATORS SET RDB$GENERATOR_NAME='#{new_name_seq}' WHERE RDB$GENERATOR_NAME='#{name_seq}'"
|
275
|
-
end
|
276
|
-
|
277
|
-
def drop_table(name, options = {})
|
278
|
-
super(name)
|
279
|
-
execute_quietly "DROP GENERATOR #{default_sequence_name(name)}"
|
280
|
-
end
|
281
|
-
|
282
|
-
def change_column(table_name, column_name, type, options = {})
|
283
|
-
execute "ALTER TABLE #{table_name} ALTER #{column_name} TYPE #{type_to_sql(type, options[:limit])}"
|
284
|
-
end
|
285
|
-
|
286
|
-
def rename_column(table_name, column_name, new_column_name)
|
287
|
-
execute "ALTER TABLE #{table_name} ALTER #{column_name} TO #{new_column_name}"
|
288
|
-
end
|
289
|
-
|
290
|
-
def remove_index(table_name, options)
|
291
|
-
execute "DROP INDEX #{index_name(table_name, options)}"
|
292
|
-
end
|
293
|
-
|
294
|
-
# @override
|
295
|
-
def quote(value, column = nil)
|
296
|
-
return value.quoted_id if value.respond_to?(:quoted_id)
|
297
|
-
return value if sql_literal?(value)
|
298
|
-
|
299
|
-
type = column && column.type
|
300
|
-
|
301
|
-
# BLOBs are updated separately by an after_save trigger.
|
302
|
-
if type == :binary || type == :text
|
303
|
-
if update_lob_values?
|
304
|
-
return value.nil? ? "NULL" : BLOB_VALUE_MARKER
|
305
|
-
else
|
306
|
-
return "'#{quote_string(value)}'"
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
case value
|
311
|
-
when String, ActiveSupport::Multibyte::Chars
|
312
|
-
value = value.to_s
|
313
|
-
if type == :integer
|
314
|
-
value.to_i.to_s
|
315
|
-
elsif type == :float
|
316
|
-
value.to_f.to_s
|
317
|
-
else
|
318
|
-
"'#{quote_string(value)}'"
|
319
|
-
end
|
320
|
-
when NilClass then 'NULL'
|
321
|
-
when TrueClass then (type == :integer ? '1' : quoted_true)
|
322
|
-
when FalseClass then (type == :integer ? '0' : quoted_false)
|
323
|
-
when Float, Fixnum, Bignum then value.to_s
|
324
|
-
# BigDecimals need to be output in a non-normalized form and quoted.
|
325
|
-
when BigDecimal then value.to_s('F')
|
326
|
-
when Symbol then "'#{quote_string(value.to_s)}'"
|
327
|
-
else
|
328
|
-
if type == :time && value.acts_like?(:time)
|
329
|
-
return "'#{get_time(value).strftime("%H:%M:%S")}'"
|
330
|
-
end
|
331
|
-
if type == :date && value.acts_like?(:date)
|
332
|
-
return "'#{value.strftime("%Y-%m-%d")}'"
|
333
|
-
end
|
334
|
-
super
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
# @override
|
339
|
-
def quoted_date(value)
|
340
|
-
if value.acts_like?(:time) && value.respond_to?(:usec)
|
341
|
-
usec = sprintf "%04d", (value.usec / 100.0).round
|
342
|
-
value = ::ActiveRecord.default_timezone == :utc ? value.getutc : value.getlocal
|
343
|
-
"#{value.strftime("%Y-%m-%d %H:%M:%S")}.#{usec}"
|
344
|
-
else
|
345
|
-
super
|
346
|
-
end
|
347
|
-
end if ::ActiveRecord::VERSION::MAJOR >= 3
|
348
|
-
|
349
|
-
# @override
|
350
|
-
def quote_string(string)
|
351
|
-
string.gsub(/'/, "''")
|
352
|
-
end
|
353
|
-
|
354
|
-
# @override
|
355
|
-
def quoted_true
|
356
|
-
quote(1)
|
357
|
-
end
|
358
|
-
|
359
|
-
# @override
|
360
|
-
def quoted_false
|
361
|
-
quote(0)
|
362
|
-
end
|
363
|
-
|
364
|
-
# @override
|
365
|
-
def quote_table_name_for_assignment(table, attr)
|
366
|
-
quote_column_name(attr)
|
367
|
-
end if ::ActiveRecord::VERSION::MAJOR >= 4
|
368
|
-
|
369
|
-
# @override
|
370
|
-
def quote_column_name(column_name)
|
371
|
-
column_name = column_name.to_s
|
372
|
-
%Q("#{column_name =~ /[[:upper:]]/ ? column_name : column_name.upcase}")
|
373
|
-
end
|
374
|
-
|
375
|
-
end
|
376
|
-
FireBird = Firebird
|
377
|
-
end
|
378
|
-
|
379
|
-
require 'arjdbc/util/quoted_cache'
|
380
|
-
|
381
|
-
module ActiveRecord::ConnectionAdapters
|
382
|
-
|
383
|
-
remove_const(:FirebirdAdapter) if const_defined?(:FirebirdAdapter)
|
384
|
-
|
385
|
-
class FirebirdAdapter < JdbcAdapter
|
386
|
-
include ::ArJdbc::Firebird
|
387
|
-
include ::ArJdbc::Util::QuotedCache
|
388
|
-
|
389
|
-
# By default, the FirebirdAdapter will consider all columns of type
|
390
|
-
# <tt>char(1)</tt> as boolean. If you wish to disable this :
|
391
|
-
#
|
392
|
-
# ActiveRecord::ConnectionAdapters::FirebirdAdapter.emulate_booleans = false
|
393
|
-
#
|
394
|
-
def self.emulate_booleans?; ::ArJdbc::Firebird.emulate_booleans?; end
|
395
|
-
def self.emulate_booleans; ::ArJdbc::Firebird.emulate_booleans?; end
|
396
|
-
def self.emulate_booleans=(emulate); ::ArJdbc::Firebird.emulate_booleans = emulate; end
|
397
|
-
|
398
|
-
def initialize(*args)
|
399
|
-
::ArJdbc::Firebird.initialize!
|
400
|
-
super
|
401
|
-
end
|
402
|
-
|
403
|
-
def arel_visitor
|
404
|
-
Arel::Visitors::Firebird.new(self)
|
405
|
-
end
|
406
|
-
|
407
|
-
end
|
408
|
-
|
409
|
-
class FirebirdColumn < JdbcColumn
|
410
|
-
include ::ArJdbc::Firebird::Column
|
411
|
-
end
|
412
|
-
|
413
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
ArJdbc::ConnectionMethods.module_eval do
|
2
|
-
def firebird_connection(config)
|
3
|
-
config[:adapter_spec] ||= ::ArJdbc::Firebird
|
4
|
-
|
5
|
-
return jndi_connection(config) if jndi_config?(config)
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'jdbc/firebird'
|
9
|
-
::Jdbc::Firebird.load_driver(:require)
|
10
|
-
rescue LoadError # assuming driver.jar is on the class-path
|
11
|
-
end
|
12
|
-
|
13
|
-
config[:host] ||= 'localhost'
|
14
|
-
config[:port] ||= 3050
|
15
|
-
config[:url] ||= begin
|
16
|
-
"jdbc:firebirdsql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
|
17
|
-
end
|
18
|
-
config[:driver] ||= ::Jdbc::Firebird.driver_name
|
19
|
-
|
20
|
-
jdbc_connection(config)
|
21
|
-
end
|
22
|
-
# alias_method :jdbcfirebird_connection, :firebird_connection
|
23
|
-
end
|
data/lib/arjdbc/firebird.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'arjdbc/util/serialized_attributes'
|
2
|
-
|
3
|
-
module ArJdbc
|
4
|
-
module Informix
|
5
|
-
|
6
|
-
@@_lob_callback_added = nil
|
7
|
-
|
8
|
-
def self.extended(base)
|
9
|
-
unless @@_lob_callback_added
|
10
|
-
ActiveRecord::Base.class_eval do
|
11
|
-
def after_save_with_informix_lob
|
12
|
-
lob_columns = self.class.columns.select { |c| [:text, :binary].include?(c.type) }
|
13
|
-
lob_columns.each do |column|
|
14
|
-
value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column)
|
15
|
-
next if value.nil? || (value == '')
|
16
|
-
|
17
|
-
connection.write_large_object(
|
18
|
-
column.type == :binary, column.name,
|
19
|
-
self.class.table_name, self.class.primary_key,
|
20
|
-
quote_value(id), value
|
21
|
-
)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
ActiveRecord::Base.after_save :after_save_with_informix_lob
|
27
|
-
@@_lob_callback_added = true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
JdbcConnection = ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
|
32
|
-
|
33
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
|
34
|
-
def self.jdbc_connection_class
|
35
|
-
::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
|
36
|
-
end
|
37
|
-
|
38
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
|
39
|
-
def jdbc_column_class
|
40
|
-
::ActiveRecord::ConnectionAdapters::InformixColumn
|
41
|
-
end
|
42
|
-
|
43
|
-
def modify_types(types)
|
44
|
-
super(types)
|
45
|
-
types[:primary_key] = "SERIAL PRIMARY KEY"
|
46
|
-
types[:string] = { :name => "VARCHAR", :limit => 255 }
|
47
|
-
types[:integer] = { :name => "INTEGER" }
|
48
|
-
types[:float] = { :name => "FLOAT" }
|
49
|
-
types[:decimal] = { :name => "DECIMAL" }
|
50
|
-
types[:datetime] = { :name => "DATETIME YEAR TO FRACTION(5)" }
|
51
|
-
types[:timestamp] = { :name => "DATETIME YEAR TO FRACTION(5)" }
|
52
|
-
types[:time] = { :name => "DATETIME HOUR TO FRACTION(5)" }
|
53
|
-
types[:date] = { :name => "DATE" }
|
54
|
-
types[:binary] = { :name => "BYTE" }
|
55
|
-
types[:boolean] = { :name => "BOOLEAN" }
|
56
|
-
types
|
57
|
-
end
|
58
|
-
|
59
|
-
def prefetch_primary_key?(table_name = nil)
|
60
|
-
true
|
61
|
-
end
|
62
|
-
|
63
|
-
def supports_migrations?
|
64
|
-
true
|
65
|
-
end
|
66
|
-
|
67
|
-
def default_sequence_name(table, column)
|
68
|
-
"#{table}_seq"
|
69
|
-
end
|
70
|
-
|
71
|
-
def add_limit_offset!(sql, options)
|
72
|
-
if options[:limit]
|
73
|
-
limit = "FIRST #{options[:limit]}" # SKIP available only in IDS >= 10 :
|
74
|
-
offset = (db_major_version >= 10 && options[:offset] ? "SKIP #{options[:offset]}" : "")
|
75
|
-
sql.sub!(/^\s*?select /i, "SELECT #{offset} #{limit} ")
|
76
|
-
end
|
77
|
-
sql
|
78
|
-
end
|
79
|
-
|
80
|
-
def next_sequence_value(sequence_name)
|
81
|
-
select_one("SELECT #{sequence_name}.nextval id FROM systables WHERE tabid=1")['id']
|
82
|
-
end
|
83
|
-
|
84
|
-
# TODO: Add some smart quoting for newlines in string and text fields.
|
85
|
-
def quote_string(string)
|
86
|
-
string.gsub(/\'/, "''")
|
87
|
-
end
|
88
|
-
|
89
|
-
def quote(value, column = nil)
|
90
|
-
column_type = column && column.type
|
91
|
-
if column_type == :binary || column_type == :text
|
92
|
-
# LOBs are updated separately by an after_save trigger.
|
93
|
-
"NULL"
|
94
|
-
elsif column_type == :date
|
95
|
-
"'#{value.mon}/#{value.day}/#{value.year}'"
|
96
|
-
else
|
97
|
-
super
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def create_table(name, options = {})
|
102
|
-
super(name, options)
|
103
|
-
execute("CREATE SEQUENCE #{name}_seq")
|
104
|
-
end
|
105
|
-
|
106
|
-
def rename_table(name, new_name)
|
107
|
-
execute("RENAME TABLE #{name} TO #{new_name}")
|
108
|
-
execute("RENAME SEQUENCE #{name}_seq TO #{new_name}_seq")
|
109
|
-
end
|
110
|
-
|
111
|
-
def drop_table(name)
|
112
|
-
super(name)
|
113
|
-
execute("DROP SEQUENCE #{name}_seq")
|
114
|
-
end
|
115
|
-
|
116
|
-
def remove_index(table_name, options = {})
|
117
|
-
@connection.execute_update("DROP INDEX #{index_name(table_name, options)}")
|
118
|
-
end
|
119
|
-
|
120
|
-
def select(sql, *rest)
|
121
|
-
# Informix does not like "= NULL", "!= NULL", or "<> NULL".
|
122
|
-
super(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), *rest)
|
123
|
-
end
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
def db_major_version
|
128
|
-
@@db_major_version ||=
|
129
|
-
select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
|
130
|
-
end
|
131
|
-
|
132
|
-
end # module Informix
|
133
|
-
end # module ::ArJdbc
|
134
|
-
|
135
|
-
module ActiveRecord::ConnectionAdapters
|
136
|
-
class InformixAdapter < JdbcAdapter
|
137
|
-
include ::ArJdbc::Informix
|
138
|
-
end
|
139
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
ArJdbc::ConnectionMethods.module_eval do
|
2
|
-
def informix_connection(config)
|
3
|
-
config[:port] ||= 9088
|
4
|
-
config[:url] ||= "jdbc:informix-sqli://#{config[:host]}:#{config[:port]}/#{config[:database]}:INFORMIXSERVER=#{config[:servername]}"
|
5
|
-
config[:driver] = 'com.informix.jdbc.IfxDriver'
|
6
|
-
config[:adapter_spec] = ::ArJdbc::Informix
|
7
|
-
jdbc_connection(config)
|
8
|
-
end
|
9
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module ArJdbc
|
2
|
-
module Sybase
|
3
|
-
def add_limit_offset!(sql, options) # :nodoc:
|
4
|
-
@limit = options[:limit]
|
5
|
-
@offset = options[:offset]
|
6
|
-
if use_temp_table?
|
7
|
-
# Use temp table to hack offset with Sybase
|
8
|
-
sql.sub!(/ FROM /i, ' INTO #artemp FROM ')
|
9
|
-
elsif zero_limit?
|
10
|
-
# "SET ROWCOUNT 0" turns off limits, so we havesy
|
11
|
-
# to use a cheap trick.
|
12
|
-
if sql =~ /WHERE/i
|
13
|
-
sql.sub!(/WHERE/i, 'WHERE 1 = 2 AND ')
|
14
|
-
elsif sql =~ /ORDER\s+BY/i
|
15
|
-
sql.sub!(/ORDER\s+BY/i, 'WHERE 1 = 2 ORDER BY')
|
16
|
-
else
|
17
|
-
sql << 'WHERE 1 = 2'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# If limit is not set at all, we can ignore offset;
|
23
|
-
# if limit *is* set but offset is zero, use normal select
|
24
|
-
# with simple SET ROWCOUNT. Thus, only use the temp table
|
25
|
-
# if limit is set and offset > 0.
|
26
|
-
def use_temp_table?
|
27
|
-
!@limit.nil? && !@offset.nil? && @offset > 0
|
28
|
-
end
|
29
|
-
|
30
|
-
def zero_limit?
|
31
|
-
!@limit.nil? && @limit == 0
|
32
|
-
end
|
33
|
-
|
34
|
-
def modify_types(types) # :nodoc:
|
35
|
-
super(types)
|
36
|
-
types[:primary_key] = "NUMERIC(22,0) IDENTITY PRIMARY KEY"
|
37
|
-
types[:integer][:limit] = nil
|
38
|
-
types[:boolean] = {:name => "bit"}
|
39
|
-
types[:binary] = {:name => "image"}
|
40
|
-
types
|
41
|
-
end
|
42
|
-
|
43
|
-
def remove_index(table_name, options = {})
|
44
|
-
execute "DROP INDEX #{table_name}.#{index_name(table_name, options)}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/arjdbc/sybase.rb
DELETED