activerecord-rdb-adapter 0.9.4 → 0.9.6.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/extconf.rb +93 -93
- data/fb.c +3072 -3072
- data/fb_extensions.rb +21 -21
- data/lib/active_model/type/integer.rb +67 -67
- data/lib/active_record/connection_adapters/rdb/database_limits.rb +35 -35
- data/lib/active_record/connection_adapters/rdb/database_statements.rb +186 -183
- data/lib/active_record/connection_adapters/rdb/quoting.rb +152 -152
- data/lib/active_record/connection_adapters/rdb/schema_creation.rb +52 -52
- data/lib/active_record/connection_adapters/rdb/schema_dumper.rb +23 -23
- data/lib/active_record/connection_adapters/rdb/schema_statements.rb +431 -431
- data/lib/active_record/connection_adapters/rdb/table_definition.rb +28 -28
- data/lib/active_record/connection_adapters/rdb_adapter.rb +160 -163
- data/lib/active_record/connection_adapters/rdb_column.rb +69 -69
- data/lib/active_record/rdb_base.rb +34 -34
- data/lib/active_record/tasks/rdb_database_tasks.rb +78 -78
- data/lib/activerecord-rdb-adapter.rb +10 -10
- data/lib/arel/visitors/rdb_visitor.rb +135 -135
- metadata +5 -6
@@ -1,28 +1,28 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
module Rdb
|
4
|
-
module ColumnMethods # :nodoc:
|
5
|
-
|
6
|
-
attr_accessor :needs_sequence
|
7
|
-
|
8
|
-
def primary_key(name, type = :primary_key, **options)
|
9
|
-
self.needs_sequence = true
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition # :nodoc:
|
16
|
-
include ColumnMethods
|
17
|
-
|
18
|
-
def new_column_definition(name, type, **options)
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Table < ActiveRecord::ConnectionAdapters::Table # :nodoc:
|
24
|
-
include ColumnMethods
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module Rdb
|
4
|
+
module ColumnMethods # :nodoc:
|
5
|
+
|
6
|
+
attr_accessor :needs_sequence
|
7
|
+
|
8
|
+
def primary_key(name, type = :primary_key, **options)
|
9
|
+
self.needs_sequence = true
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition # :nodoc:
|
16
|
+
include ColumnMethods
|
17
|
+
|
18
|
+
def new_column_definition(name, type, **options)
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Table < ActiveRecord::ConnectionAdapters::Table # :nodoc:
|
24
|
+
include ColumnMethods
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,163 +1,160 @@
|
|
1
|
-
require 'fb'
|
2
|
-
require 'base64'
|
3
|
-
require 'arel'
|
4
|
-
require 'arel/visitors/rdb_visitor'
|
5
|
-
|
6
|
-
require 'active_record'
|
7
|
-
require 'active_record/base'
|
8
|
-
require 'active_record/connection_adapters/abstract_adapter'
|
9
|
-
require 'active_record/connection_adapters/rdb/database_statements'
|
10
|
-
require 'active_record/connection_adapters/rdb/database_limits'
|
11
|
-
require 'active_record/connection_adapters/rdb/schema_creation'
|
12
|
-
require 'active_record/connection_adapters/rdb/schema_dumper'
|
13
|
-
require 'active_record/connection_adapters/rdb/schema_statements'
|
14
|
-
require 'active_record/connection_adapters/rdb/quoting'
|
15
|
-
require 'active_record/connection_adapters/rdb/table_definition'
|
16
|
-
require 'active_record/connection_adapters/rdb_column'
|
17
|
-
require 'active_record/rdb_base'
|
18
|
-
|
19
|
-
module ActiveRecord
|
20
|
-
module ConnectionAdapters
|
21
|
-
class RdbAdapter < AbstractAdapter # :nodoc:
|
22
|
-
include Rdb::DatabaseLimits
|
23
|
-
include Rdb::DatabaseStatements
|
24
|
-
include Rdb::Quoting
|
25
|
-
include Rdb::SchemaStatements
|
26
|
-
|
27
|
-
@@default_transaction_isolation = :read_committed
|
28
|
-
cattr_accessor :default_transaction_isolation
|
29
|
-
|
30
|
-
ADAPTER_NAME = 'rdb'.freeze
|
31
|
-
|
32
|
-
def initialize(connection, logger = nil, config = {})
|
33
|
-
super(connection, logger, config)
|
34
|
-
# Our Responsibility
|
35
|
-
@config = config
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
1
|
+
require 'fb'
|
2
|
+
require 'base64'
|
3
|
+
require 'arel'
|
4
|
+
require 'arel/visitors/rdb_visitor'
|
5
|
+
|
6
|
+
require 'active_record'
|
7
|
+
require 'active_record/base'
|
8
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
9
|
+
require 'active_record/connection_adapters/rdb/database_statements'
|
10
|
+
require 'active_record/connection_adapters/rdb/database_limits'
|
11
|
+
require 'active_record/connection_adapters/rdb/schema_creation'
|
12
|
+
require 'active_record/connection_adapters/rdb/schema_dumper'
|
13
|
+
require 'active_record/connection_adapters/rdb/schema_statements'
|
14
|
+
require 'active_record/connection_adapters/rdb/quoting'
|
15
|
+
require 'active_record/connection_adapters/rdb/table_definition'
|
16
|
+
require 'active_record/connection_adapters/rdb_column'
|
17
|
+
require 'active_record/rdb_base'
|
18
|
+
|
19
|
+
module ActiveRecord
|
20
|
+
module ConnectionAdapters
|
21
|
+
class RdbAdapter < AbstractAdapter # :nodoc:
|
22
|
+
include Rdb::DatabaseLimits
|
23
|
+
include Rdb::DatabaseStatements
|
24
|
+
include Rdb::Quoting
|
25
|
+
include Rdb::SchemaStatements
|
26
|
+
|
27
|
+
@@default_transaction_isolation = :read_committed
|
28
|
+
cattr_accessor :default_transaction_isolation
|
29
|
+
|
30
|
+
ADAPTER_NAME = 'rdb'.freeze
|
31
|
+
|
32
|
+
def initialize(connection, logger = nil, config = {})
|
33
|
+
super(connection, logger, config)
|
34
|
+
# Our Responsibility
|
35
|
+
@config = config
|
36
|
+
end
|
37
|
+
|
38
|
+
def arel_visitor
|
39
|
+
Arel::Visitors::Rdb.new self
|
40
|
+
end
|
41
|
+
|
42
|
+
def valid_type?(type)
|
43
|
+
!native_database_types[type].nil? || !native_database_types[type.type].nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def adapter_name
|
47
|
+
ADAPTER_NAME
|
48
|
+
end
|
49
|
+
|
50
|
+
def schema_creation
|
51
|
+
Rdb::SchemaCreation.new self
|
52
|
+
end
|
53
|
+
|
54
|
+
def supports_migrations?
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
def supports_primary_key?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def supports_count_distinct?
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
def supports_ddl_transactions?
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
def supports_transaction_isolation?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def supports_savepoints?
|
75
|
+
true
|
76
|
+
end
|
77
|
+
|
78
|
+
def prefetch_primary_key?(_table_name = nil)
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def ids_in_list_limit
|
83
|
+
1499
|
84
|
+
end
|
85
|
+
|
86
|
+
def supports_multi_insert?
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
90
|
+
def active?
|
91
|
+
return false unless @connection.open?
|
92
|
+
|
93
|
+
@connection.query('SELECT 1 FROM RDB$DATABASE')
|
94
|
+
true
|
95
|
+
rescue StandardError
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
99
|
+
def reconnect!
|
100
|
+
disconnect!
|
101
|
+
@connection = ::Fb::Database.connect(@config)
|
102
|
+
end
|
103
|
+
|
104
|
+
def disconnect!
|
105
|
+
super
|
106
|
+
begin
|
107
|
+
@connection.close
|
108
|
+
rescue StandardError
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def reset!
|
114
|
+
reconnect!
|
115
|
+
end
|
116
|
+
|
117
|
+
def requires_reloading?
|
118
|
+
false
|
119
|
+
end
|
120
|
+
|
121
|
+
def create_savepoint(name = current_savepoint_name)
|
122
|
+
execute("SAVEPOINT #{name}")
|
123
|
+
end
|
124
|
+
|
125
|
+
def rollback_to_savepoint(name = current_savepoint_name)
|
126
|
+
execute("ROLLBACK TO SAVEPOINT #{name}")
|
127
|
+
end
|
128
|
+
|
129
|
+
def release_savepoint(name = current_savepoint_name)
|
130
|
+
execute("RELEASE SAVEPOINT #{name}")
|
131
|
+
end
|
132
|
+
|
133
|
+
protected
|
134
|
+
|
135
|
+
def initialize_type_map(map)
|
136
|
+
super
|
137
|
+
map.register_type(/timestamp/i, Type::DateTime.new)
|
138
|
+
map.alias_type(/blob sub_type text/i, 'text')
|
139
|
+
end
|
140
|
+
|
141
|
+
def translate_exception(e, message)
|
142
|
+
case e.message
|
143
|
+
when /violation of FOREIGN KEY constraint/
|
144
|
+
ActiveRecord::InvalidForeignKey.new(message)
|
145
|
+
when /violation of PRIMARY or UNIQUE KEY constraint/, /attempt to store duplicate value/
|
146
|
+
ActiveRecord::RecordNotUnique.new(message)
|
147
|
+
when /This operation is not defined for system tables/
|
148
|
+
ActiveRecord::ActiveRecordError.new(message)
|
149
|
+
when /Column does not belong to referenced table/,
|
150
|
+
/Unsuccessful execution caused by system error that does not preclude successful execution of subsequent statements/,
|
151
|
+
/The cursor identified in the UPDATE or DELETE statement is not positioned on a row/,
|
152
|
+
/Overflow occurred during data type conversion/
|
153
|
+
ActiveRecord::StatementInvalid.new(message)
|
154
|
+
else
|
155
|
+
super
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -1,69 +1,69 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
class RdbColumn < Column # :nodoc:
|
4
|
-
class << self
|
5
|
-
def sql_type_for(field)
|
6
|
-
sql_type = field[:sql_type]
|
7
|
-
sub_type = field[:sql_subtype]
|
8
|
-
|
9
|
-
sql_type << case sql_type
|
10
|
-
when /(numeric|decimal)/i
|
11
|
-
"(#{field[:precision]},#{field[:scale].abs})"
|
12
|
-
when /(int|float|double|char|varchar|bigint)/i
|
13
|
-
"(#{field[:length]})"
|
14
|
-
else
|
15
|
-
''
|
16
|
-
end
|
17
|
-
|
18
|
-
sql_type << ' sub_type text' if /blob/i.match?(sql_type) && sub_type == 1
|
19
|
-
sql_type
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
attr_reader :sub_type, :domain
|
24
|
-
|
25
|
-
def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, rdb_options = {})
|
26
|
-
@domain, @sub_type = rdb_options.values_at(:domain, :sub_type)
|
27
|
-
name = name.dup
|
28
|
-
name.downcase!
|
29
|
-
super(name, parse_default(default), sql_type_metadata, null, table_name)
|
30
|
-
end
|
31
|
-
|
32
|
-
def sql_type
|
33
|
-
@sql_type_metadata[:sql_type]
|
34
|
-
end
|
35
|
-
|
36
|
-
def type
|
37
|
-
@sql_type_metadata[:type]
|
38
|
-
end
|
39
|
-
|
40
|
-
def precision
|
41
|
-
@sql_type_metadata[:precision]
|
42
|
-
end
|
43
|
-
|
44
|
-
def scale
|
45
|
-
@sql_type_metadata[:scale]
|
46
|
-
end
|
47
|
-
|
48
|
-
def limit
|
49
|
-
@sql_type_metadata[:limit]
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def parse_default(default)
|
55
|
-
return if default.nil? || /null/i.match?(default)
|
56
|
-
d = default.dup
|
57
|
-
d.gsub!(/^\s*DEFAULT\s+/i, '')
|
58
|
-
d.gsub!(/(^'|'$)/, '')
|
59
|
-
d
|
60
|
-
end
|
61
|
-
|
62
|
-
def simplified_type(field_type)
|
63
|
-
return :datetime if /timestamp/i.match?(field_type)
|
64
|
-
return :text if /blob sub_type text/i.match?(field_type)
|
65
|
-
super
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class RdbColumn < Column # :nodoc:
|
4
|
+
class << self
|
5
|
+
def sql_type_for(field)
|
6
|
+
sql_type = field[:sql_type]
|
7
|
+
sub_type = field[:sql_subtype]
|
8
|
+
|
9
|
+
sql_type << case sql_type
|
10
|
+
when /(numeric|decimal)/i
|
11
|
+
"(#{field[:precision]},#{field[:scale].abs})"
|
12
|
+
when /(int|float|double|char|varchar|bigint)/i
|
13
|
+
"(#{field[:length]})"
|
14
|
+
else
|
15
|
+
''
|
16
|
+
end
|
17
|
+
|
18
|
+
sql_type << ' sub_type text' if /blob/i.match?(sql_type) && sub_type == 1
|
19
|
+
sql_type
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :sub_type, :domain
|
24
|
+
|
25
|
+
def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, rdb_options = {})
|
26
|
+
@domain, @sub_type = rdb_options.values_at(:domain, :sub_type)
|
27
|
+
name = name.dup
|
28
|
+
name.downcase!
|
29
|
+
super(name, parse_default(default), sql_type_metadata, null, table_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sql_type
|
33
|
+
@sql_type_metadata[:sql_type]
|
34
|
+
end
|
35
|
+
|
36
|
+
def type
|
37
|
+
@sql_type_metadata[:type]
|
38
|
+
end
|
39
|
+
|
40
|
+
def precision
|
41
|
+
@sql_type_metadata[:precision]
|
42
|
+
end
|
43
|
+
|
44
|
+
def scale
|
45
|
+
@sql_type_metadata[:scale]
|
46
|
+
end
|
47
|
+
|
48
|
+
def limit
|
49
|
+
@sql_type_metadata[:limit]
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def parse_default(default)
|
55
|
+
return if default.nil? || /null/i.match?(default)
|
56
|
+
d = default.dup
|
57
|
+
d.gsub!(/^\s*DEFAULT\s+/i, '')
|
58
|
+
d.gsub!(/(^'|'$)/, '')
|
59
|
+
d
|
60
|
+
end
|
61
|
+
|
62
|
+
def simplified_type(field_type)
|
63
|
+
return :datetime if /timestamp/i.match?(field_type)
|
64
|
+
return :text if /blob sub_type text/i.match?(field_type)
|
65
|
+
super
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionHandling # :nodoc:
|
3
|
-
def rdb_connection(config)
|
4
|
-
require 'fb'
|
5
|
-
config = rdb_connection_config(config)
|
6
|
-
db = ::Fb::Database.new(config)
|
7
|
-
@database = db
|
8
|
-
begin
|
9
|
-
connection = db.connect
|
10
|
-
rescue StandardError
|
11
|
-
unless config[:create]
|
12
|
-
require 'pp'
|
13
|
-
pp config
|
14
|
-
raise ConnectionNotEstablished, 'No Firebird connections established.'
|
15
|
-
end
|
16
|
-
connection = db.create.connect
|
17
|
-
end
|
18
|
-
ConnectionAdapters::RdbAdapter.new(connection, logger, config)
|
19
|
-
end
|
20
|
-
|
21
|
-
def rdb_connection_config(config)
|
22
|
-
config = config.symbolize_keys.dup.reverse_merge(downcase_names: true)
|
23
|
-
port = config[:port] || 3050
|
24
|
-
raise ArgumentError, 'No database specified. Missing argument: database.' unless config[:database]
|
25
|
-
config[:database] = File.expand_path(config[:database], defined?(Rails) && Rails.root) if config[:host].nil? || /localhost/i.match?(config[:host])
|
26
|
-
config[:database] = "#{config[:host]}/#{port}:#{config[:database]}" if config[:host]
|
27
|
-
# config[:charset] = config[:charset].gsub(/-/, '') if config[:charset]
|
28
|
-
# config[:encoding] = config[:encoding].gsub(/-/, '') if config[:encoding]
|
29
|
-
config[:page_size] = 8192 unless config[:page_size]
|
30
|
-
config[:readonly_selects] = true unless config[:readonly_selects].present?
|
31
|
-
config
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionHandling # :nodoc:
|
3
|
+
def rdb_connection(config)
|
4
|
+
require 'fb'
|
5
|
+
config = rdb_connection_config(config)
|
6
|
+
db = ::Fb::Database.new(config)
|
7
|
+
@database = db
|
8
|
+
begin
|
9
|
+
connection = db.connect
|
10
|
+
rescue StandardError
|
11
|
+
unless config[:create]
|
12
|
+
require 'pp'
|
13
|
+
pp config
|
14
|
+
raise ConnectionNotEstablished, 'No Firebird connections established.'
|
15
|
+
end
|
16
|
+
connection = db.create.connect
|
17
|
+
end
|
18
|
+
ConnectionAdapters::RdbAdapter.new(connection, logger, config)
|
19
|
+
end
|
20
|
+
|
21
|
+
def rdb_connection_config(config)
|
22
|
+
config = config.symbolize_keys.dup.reverse_merge(downcase_names: true)
|
23
|
+
port = config[:port] || 3050
|
24
|
+
raise ArgumentError, 'No database specified. Missing argument: database.' unless config[:database]
|
25
|
+
config[:database] = File.expand_path(config[:database], defined?(Rails) && Rails.root) if config[:host].nil? || /localhost/i.match?(config[:host])
|
26
|
+
config[:database] = "#{config[:host]}/#{port}:#{config[:database]}" if config[:host]
|
27
|
+
# config[:charset] = config[:charset].gsub(/-/, '') if config[:charset]
|
28
|
+
# config[:encoding] = config[:encoding].gsub(/-/, '') if config[:encoding]
|
29
|
+
config[:page_size] = 8192 unless config[:page_size]
|
30
|
+
config[:readonly_selects] = true unless config[:readonly_selects].present?
|
31
|
+
config
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|