activerecord-jdbc-adapter-ficoh 1.3.21-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +35 -0
  3. data/.travis.yml +462 -0
  4. data/.yardopts +4 -0
  5. data/Appraisals +36 -0
  6. data/CONTRIBUTING.md +49 -0
  7. data/Gemfile +68 -0
  8. data/History.md +1191 -0
  9. data/LICENSE.txt +25 -0
  10. data/README.md +277 -0
  11. data/RUNNING_TESTS.md +88 -0
  12. data/Rakefile +298 -0
  13. data/Rakefile.jdbc +20 -0
  14. data/activerecord-jdbc-adapter.gemspec +63 -0
  15. data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
  16. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  17. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
  18. data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
  19. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
  20. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
  21. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
  22. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
  23. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
  24. data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
  25. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  26. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  27. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
  28. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
  29. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
  30. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
  31. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
  32. data/lib/activerecord-jdbc-adapter.rb +1 -0
  33. data/lib/arel/visitors/compat.rb +64 -0
  34. data/lib/arel/visitors/db2.rb +137 -0
  35. data/lib/arel/visitors/derby.rb +112 -0
  36. data/lib/arel/visitors/firebird.rb +79 -0
  37. data/lib/arel/visitors/h2.rb +25 -0
  38. data/lib/arel/visitors/hsqldb.rb +32 -0
  39. data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
  40. data/lib/arel/visitors/sql_server.rb +225 -0
  41. data/lib/arel/visitors/sql_server/ng42.rb +293 -0
  42. data/lib/arjdbc.rb +22 -0
  43. data/lib/arjdbc/db2.rb +4 -0
  44. data/lib/arjdbc/db2/adapter.rb +802 -0
  45. data/lib/arjdbc/db2/as400.rb +137 -0
  46. data/lib/arjdbc/db2/column.rb +177 -0
  47. data/lib/arjdbc/db2/connection_methods.rb +45 -0
  48. data/lib/arjdbc/derby.rb +3 -0
  49. data/lib/arjdbc/derby/active_record_patch.rb +13 -0
  50. data/lib/arjdbc/derby/adapter.rb +567 -0
  51. data/lib/arjdbc/derby/connection_methods.rb +16 -0
  52. data/lib/arjdbc/derby/schema_creation.rb +15 -0
  53. data/lib/arjdbc/discover.rb +104 -0
  54. data/lib/arjdbc/firebird.rb +4 -0
  55. data/lib/arjdbc/firebird/adapter.rb +468 -0
  56. data/lib/arjdbc/firebird/connection_methods.rb +20 -0
  57. data/lib/arjdbc/h2.rb +3 -0
  58. data/lib/arjdbc/h2/adapter.rb +335 -0
  59. data/lib/arjdbc/h2/connection_methods.rb +22 -0
  60. data/lib/arjdbc/hsqldb.rb +3 -0
  61. data/lib/arjdbc/hsqldb/adapter.rb +304 -0
  62. data/lib/arjdbc/hsqldb/connection_methods.rb +23 -0
  63. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  64. data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
  65. data/lib/arjdbc/informix.rb +5 -0
  66. data/lib/arjdbc/informix/adapter.rb +160 -0
  67. data/lib/arjdbc/informix/connection_methods.rb +9 -0
  68. data/lib/arjdbc/jdbc.rb +62 -0
  69. data/lib/arjdbc/jdbc/adapter.rb +997 -0
  70. data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
  71. data/lib/arjdbc/jdbc/arel_support.rb +149 -0
  72. data/lib/arjdbc/jdbc/base_ext.rb +34 -0
  73. data/lib/arjdbc/jdbc/callbacks.rb +52 -0
  74. data/lib/arjdbc/jdbc/column.rb +83 -0
  75. data/lib/arjdbc/jdbc/connection.rb +26 -0
  76. data/lib/arjdbc/jdbc/connection_methods.rb +59 -0
  77. data/lib/arjdbc/jdbc/driver.rb +44 -0
  78. data/lib/arjdbc/jdbc/error.rb +75 -0
  79. data/lib/arjdbc/jdbc/extension.rb +69 -0
  80. data/lib/arjdbc/jdbc/java.rb +13 -0
  81. data/lib/arjdbc/jdbc/type_cast.rb +154 -0
  82. data/lib/arjdbc/jdbc/type_converter.rb +142 -0
  83. data/lib/arjdbc/mssql.rb +7 -0
  84. data/lib/arjdbc/mssql/adapter.rb +822 -0
  85. data/lib/arjdbc/mssql/column.rb +207 -0
  86. data/lib/arjdbc/mssql/connection_methods.rb +72 -0
  87. data/lib/arjdbc/mssql/explain_support.rb +99 -0
  88. data/lib/arjdbc/mssql/limit_helpers.rb +231 -0
  89. data/lib/arjdbc/mssql/lock_methods.rb +77 -0
  90. data/lib/arjdbc/mssql/types.rb +343 -0
  91. data/lib/arjdbc/mssql/utils.rb +82 -0
  92. data/lib/arjdbc/mysql.rb +3 -0
  93. data/lib/arjdbc/mysql/adapter.rb +998 -0
  94. data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
  95. data/lib/arjdbc/mysql/column.rb +167 -0
  96. data/lib/arjdbc/mysql/connection_methods.rb +137 -0
  97. data/lib/arjdbc/mysql/explain_support.rb +82 -0
  98. data/lib/arjdbc/mysql/schema_creation.rb +58 -0
  99. data/lib/arjdbc/oracle.rb +4 -0
  100. data/lib/arjdbc/oracle/adapter.rb +968 -0
  101. data/lib/arjdbc/oracle/column.rb +136 -0
  102. data/lib/arjdbc/oracle/connection_methods.rb +21 -0
  103. data/lib/arjdbc/postgresql.rb +3 -0
  104. data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
  105. data/lib/arjdbc/postgresql/adapter.rb +1498 -0
  106. data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
  107. data/lib/arjdbc/postgresql/base/oid.rb +412 -0
  108. data/lib/arjdbc/postgresql/base/pgconn.rb +8 -0
  109. data/lib/arjdbc/postgresql/base/schema_definitions.rb +132 -0
  110. data/lib/arjdbc/postgresql/column.rb +640 -0
  111. data/lib/arjdbc/postgresql/connection_methods.rb +44 -0
  112. data/lib/arjdbc/postgresql/explain_support.rb +53 -0
  113. data/lib/arjdbc/postgresql/oid/bytea.rb +3 -0
  114. data/lib/arjdbc/postgresql/oid_types.rb +265 -0
  115. data/lib/arjdbc/postgresql/schema_creation.rb +60 -0
  116. data/lib/arjdbc/railtie.rb +11 -0
  117. data/lib/arjdbc/sqlite3.rb +3 -0
  118. data/lib/arjdbc/sqlite3/adapter.rb +654 -0
  119. data/lib/arjdbc/sqlite3/connection_methods.rb +36 -0
  120. data/lib/arjdbc/sqlite3/explain_support.rb +29 -0
  121. data/lib/arjdbc/sybase.rb +2 -0
  122. data/lib/arjdbc/sybase/adapter.rb +47 -0
  123. data/lib/arjdbc/tasks.rb +13 -0
  124. data/lib/arjdbc/tasks/database_tasks.rb +66 -0
  125. data/lib/arjdbc/tasks/databases.rake +91 -0
  126. data/lib/arjdbc/tasks/databases3.rake +239 -0
  127. data/lib/arjdbc/tasks/databases4.rake +39 -0
  128. data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
  129. data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
  130. data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
  131. data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
  132. data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
  133. data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
  134. data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
  135. data/lib/arjdbc/tasks/oracle_database_tasks.rb +65 -0
  136. data/lib/arjdbc/util/quoted_cache.rb +60 -0
  137. data/lib/arjdbc/util/serialized_attributes.rb +98 -0
  138. data/lib/arjdbc/util/table_copier.rb +108 -0
  139. data/lib/arjdbc/version.rb +8 -0
  140. data/lib/generators/jdbc/USAGE +9 -0
  141. data/lib/generators/jdbc/jdbc_generator.rb +17 -0
  142. data/pom.xml +285 -0
  143. data/rails_generators/jdbc_generator.rb +15 -0
  144. data/rails_generators/templates/config/initializers/jdbc.rb +10 -0
  145. data/rails_generators/templates/lib/tasks/jdbc.rake +11 -0
  146. data/rakelib/01-tomcat.rake +51 -0
  147. data/rakelib/02-test.rake +151 -0
  148. data/rakelib/bundler_ext.rb +11 -0
  149. data/rakelib/db.rake +58 -0
  150. data/rakelib/rails.rake +77 -0
  151. data/src/java/arjdbc/ArJdbcModule.java +288 -0
  152. data/src/java/arjdbc/db2/DB2Module.java +77 -0
  153. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +128 -0
  154. data/src/java/arjdbc/derby/DerbyModule.java +180 -0
  155. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +153 -0
  156. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
  157. data/src/java/arjdbc/h2/H2Module.java +50 -0
  158. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +86 -0
  159. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +74 -0
  160. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +76 -0
  161. data/src/java/arjdbc/jdbc/AdapterJavaService.java +43 -0
  162. data/src/java/arjdbc/jdbc/Callable.java +44 -0
  163. data/src/java/arjdbc/jdbc/ConnectionFactory.java +77 -0
  164. data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +156 -0
  165. data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
  166. data/src/java/arjdbc/jdbc/DriverWrapper.java +128 -0
  167. data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +32 -0
  168. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4541 -0
  169. data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
  170. data/src/java/arjdbc/jdbc/WithResultSet.java +37 -0
  171. data/src/java/arjdbc/mssql/MSSQLModule.java +91 -0
  172. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +193 -0
  173. data/src/java/arjdbc/mysql/MySQLModule.java +140 -0
  174. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +456 -0
  175. data/src/java/arjdbc/oracle/OracleModule.java +81 -0
  176. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +477 -0
  177. data/src/java/arjdbc/postgresql/ByteaUtils.java +171 -0
  178. data/src/java/arjdbc/postgresql/DriverImplementation.java +78 -0
  179. data/src/java/arjdbc/postgresql/PGDriverImplementation.java +535 -0
  180. data/src/java/arjdbc/postgresql/PostgreSQLModule.java +189 -0
  181. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +489 -0
  182. data/src/java/arjdbc/sqlite3/SQLite3Module.java +93 -0
  183. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +405 -0
  184. data/src/java/arjdbc/util/CallResultSet.java +826 -0
  185. data/src/java/arjdbc/util/DateTimeUtils.java +517 -0
  186. data/src/java/arjdbc/util/NumberUtils.java +50 -0
  187. data/src/java/arjdbc/util/ObjectSupport.java +65 -0
  188. data/src/java/arjdbc/util/QuotingUtils.java +139 -0
  189. data/src/java/arjdbc/util/StringCache.java +60 -0
  190. data/src/java/arjdbc/util/StringHelper.java +155 -0
  191. metadata +288 -0
@@ -0,0 +1,16 @@
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ def derby_connection(config)
3
+ config[:adapter_spec] ||= ::ArJdbc::Derby
4
+ config[:adapter_class] = ActiveRecord::ConnectionAdapters::DerbyAdapter unless config.key?(:adapter_class)
5
+
6
+ return jndi_connection(config) if jndi_config?(config)
7
+
8
+ ArJdbc.load_driver(:Derby) unless config[:load_driver] == false
9
+ config[:driver] ||= 'org.apache.derby.jdbc.EmbeddedDriver'
10
+ # `database: memory:dbName` for an in memory Derby DB
11
+ config[:url] ||= "jdbc:derby:#{config[:database]};create=true"
12
+
13
+ embedded_driver(config)
14
+ end
15
+ alias_method :jdbcderby_connection, :derby_connection
16
+ end
@@ -0,0 +1,15 @@
1
+ module ArJdbc
2
+ module Derby
3
+ # @private
4
+ class SchemaCreation < ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation
5
+
6
+ private
7
+
8
+ end
9
+ end
10
+
11
+ def schema_creation
12
+ SchemaCreation.new self
13
+ end
14
+
15
+ end if ::ActiveRecord::ConnectionAdapters::AbstractAdapter.const_defined? :SchemaCreation
@@ -0,0 +1,104 @@
1
+ # this file is discovered by the extension mechanism
2
+ # @see {ArJdbc#discover_extensions}
3
+
4
+ module ArJdbc
5
+
6
+ require 'arjdbc/jdbc/adapter_require'
7
+
8
+ # Adapters built-in to AR :
9
+
10
+ require 'arjdbc/mysql' if ENV_JAVA['arjdbc.mysql.eager_load'].eql? 'true'
11
+ require 'arjdbc/postgresql' if ENV_JAVA['arjdbc.postgresql.eager_load'].eql? 'true'
12
+ require 'arjdbc/sqlite3' if ENV_JAVA['arjdbc.sqlite3.eager_load'].eql? 'true'
13
+
14
+ extension :MySQL do |name|
15
+ require('arjdbc/mysql') || true if name =~ /mysql/i
16
+ end
17
+
18
+ extension :PostgreSQL do |name|
19
+ require('arjdbc/postgresql') || true if name =~ /postgre/i
20
+ end
21
+
22
+ extension :SQLite3 do |name|
23
+ require('arjdbc/sqlite3') || true if name =~ /sqlite/i
24
+ end
25
+
26
+ # Other supported adapters :
27
+
28
+ extension :Derby do |name, config|
29
+ if name =~ /derby/i
30
+ require 'arjdbc/derby'
31
+
32
+ if config && config[:username].nil? # set the database schema name (:username) :
33
+ begin
34
+ ArJdbc.with_meta_data_from_data_source_if_any(config) do
35
+ |meta_data| config[:username] = meta_data.getUserName
36
+ end
37
+ rescue => e
38
+ ArJdbc.warn("failed to set :username from (Derby) database meda-data: #{e}")
39
+ end
40
+ end
41
+
42
+ true
43
+ end
44
+ end
45
+
46
+ extension :H2 do |name|
47
+ require('arjdbc/h2') || true if name =~ /\.h2\./i
48
+ end
49
+
50
+ extension :HSQLDB do |name|
51
+ require('arjdbc/hsqldb') || true if name =~ /hsqldb/i
52
+ end
53
+
54
+ extension :MSSQL do |name|
55
+ require('arjdbc/mssql') || true if name =~ /sqlserver|tds|Microsoft SQL/i
56
+ end
57
+
58
+ extension :DB2 do |name, config|
59
+ if name =~ /db2/i && name !~ /as\/?400/i && config[:url] !~ /^jdbc:derby:net:/
60
+ require 'arjdbc/db2'
61
+ true
62
+ end
63
+ end
64
+
65
+ extension :AS400 do |name, config|
66
+ # The native JDBC driver always returns "DB2 UDB for AS/400"
67
+ if name =~ /as\/?400/i
68
+ require 'arjdbc/db2'
69
+ require 'arjdbc/db2/as400'
70
+ true
71
+ end
72
+ end
73
+
74
+ extension :Oracle do |name|
75
+ if name =~ /oracle/i
76
+ require 'arjdbc/oracle'
77
+ true
78
+ end
79
+ end
80
+
81
+ # NOTE: following ones are likely getting deprecated :
82
+
83
+ extension :FireBird do |name|
84
+ if name =~ /firebird/i
85
+ require 'arjdbc/firebird'
86
+ true
87
+ end
88
+ end
89
+
90
+ extension :Sybase do |name|
91
+ if name =~ /sybase|tds/i
92
+ require 'arjdbc/sybase'
93
+ true
94
+ end
95
+ end
96
+
97
+ extension :Informix do |name|
98
+ if name =~ /informix/i
99
+ require 'arjdbc/informix'
100
+ true
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,4 @@
1
+ require 'arjdbc'
2
+ require 'arjdbc/firebird/adapter'
3
+ require 'arjdbc/firebird/connection_methods'
4
+ ArJdbc.warn_unsupported_adapter 'firebird', [4, 2] # warns on AR >= 4.2
@@ -0,0 +1,468 @@
1
+ ArJdbc.load_java_part :Firebird
2
+
3
+ module ArJdbc
4
+ module Firebird
5
+
6
+ # @private
7
+ def self.extended(adapter); initialize!; end
8
+
9
+ # @private
10
+ @@_initialized = nil
11
+
12
+ # @private
13
+ def self.initialize!
14
+ return if @@_initialized; @@_initialized = true
15
+
16
+ require 'arjdbc/util/serialized_attributes'
17
+ Util::SerializedAttributes.setup /blob/i
18
+ end
19
+
20
+ # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
21
+ def self.jdbc_connection_class
22
+ ::ActiveRecord::ConnectionAdapters::FirebirdJdbcConnection
23
+ end
24
+
25
+ # @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
26
+ def self.column_selector
27
+ [ /firebird/i, lambda { |cfg, column| column.extend(ColumnMethods) } ]
28
+ end
29
+
30
+ def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::FirebirdAdapter::Column end
31
+
32
+ # @private
33
+ # @see ActiveRecord::ConnectionAdapters::JdbcColumn
34
+ module ColumnMethods
35
+
36
+ def default_value(value)
37
+ return nil unless value
38
+ if value =~ /^\s*DEFAULT\s+(.*)\s*$/i
39
+ return $1 unless $1.upcase == 'NULL'
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def simplified_type(field_type)
46
+ case field_type
47
+ when /timestamp/i then :datetime
48
+ when /^smallint/i then :integer
49
+ when /^bigint|int/i then :integer
50
+ when /^double/i then :float # double precision
51
+ when /^decimal/i then
52
+ extract_scale(field_type) == 0 ? :integer : :decimal
53
+ when /^char\(1\)$/i then Firebird.emulate_booleans? ? :boolean : :string
54
+ when /^char/i then :string
55
+ when /^blob\ssub_type\s(\d)/i
56
+ return :binary if $1 == '0'
57
+ return :text if $1 == '1'
58
+ else
59
+ super
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ # @see ArJdbc::ArelHelper::ClassMethods#arel_visitor_type
66
+ def self.arel_visitor_type(config = nil)
67
+ require 'arel/visitors/firebird'; ::Arel::Visitors::Firebird
68
+ end
69
+
70
+ # @deprecated no longer used
71
+ def self.arel2_visitors(config = nil)
72
+ { 'firebird' => arel_visitor_type, 'firebirdsql' => arel_visitor_type }
73
+ end
74
+
75
+ # @private
76
+ @@emulate_booleans = true
77
+
78
+ # Boolean emulation can be disabled using :
79
+ #
80
+ # ArJdbc::Firebird.emulate_booleans = false
81
+ #
82
+ def self.emulate_booleans?; @@emulate_booleans; end
83
+ # @deprecated Use {#emulate_booleans?} instead.
84
+ def self.emulate_booleans; @@emulate_booleans; end
85
+ # @see #emulate_booleans?
86
+ def self.emulate_booleans=(emulate); @@emulate_booleans = emulate; end
87
+
88
+
89
+ @@update_lob_values = true
90
+
91
+ # Updating records with LOB values (binary/text columns) in a separate
92
+ # statement can be disabled using :
93
+ #
94
+ # ArJdbc::Firebird.update_lob_values = false
95
+ def self.update_lob_values?; @@update_lob_values; end
96
+ # @see #update_lob_values?
97
+ def self.update_lob_values=(update); @@update_lob_values = update; end
98
+
99
+ # @see #update_lob_values?
100
+ def update_lob_values?; Firebird.update_lob_values?; end
101
+
102
+ # @see #quote
103
+ # @private
104
+ BLOB_VALUE_MARKER = "''"
105
+
106
+ ADAPTER_NAME = 'Firebird'.freeze
107
+
108
+ def adapter_name
109
+ ADAPTER_NAME
110
+ end
111
+
112
+ NATIVE_DATABASE_TYPES = {
113
+ :primary_key => "integer not null primary key",
114
+ :string => { :name => "varchar", :limit => 255 },
115
+ :text => { :name => "blob sub_type text" },
116
+ :integer => { :name => "integer" },
117
+ :float => { :name => "float" },
118
+ :datetime => { :name => "timestamp" },
119
+ :timestamp => { :name => "timestamp" },
120
+ :time => { :name => "time" },
121
+ :date => { :name => "date" },
122
+ :binary => { :name => "blob" },
123
+ :boolean => { :name => 'char', :limit => 1 },
124
+ :numeric => { :name => "numeric" },
125
+ :decimal => { :name => "decimal" },
126
+ :char => { :name => "char" },
127
+ }
128
+
129
+ def native_database_types
130
+ NATIVE_DATABASE_TYPES
131
+ end
132
+
133
+ def initialize_type_map(m)
134
+ register_class_with_limit m, %r(binary)i, ActiveRecord::Type::Binary
135
+ register_class_with_limit m, %r(text)i, ActiveRecord::Type::Text
136
+
137
+ register_class_with_limit m, %r(date(?:\(.*?\))?$)i, DateType
138
+ register_class_with_limit m, %r(time(?:\(.*?\))?$)i, ActiveRecord::Type::Time
139
+
140
+ register_class_with_limit m, %r(float)i, ActiveRecord::Type::Float
141
+ register_class_with_limit m, %r(int)i, ActiveRecord::Type::Integer
142
+
143
+ m.alias_type %r(blob)i, 'binary'
144
+ m.alias_type %r(clob)i, 'text'
145
+ m.alias_type %r(double)i, 'float'
146
+
147
+ m.register_type(%r(decimal)i) do |sql_type|
148
+ scale = extract_scale(sql_type)
149
+ precision = extract_precision(sql_type)
150
+ if scale == 0
151
+ ActiveRecord::Type::Integer.new(precision: precision)
152
+ else
153
+ ActiveRecord::Type::Decimal.new(precision: precision, scale: scale)
154
+ end
155
+ end
156
+ m.alias_type %r(numeric)i, 'decimal'
157
+
158
+ register_class_with_limit m, %r(varchar)i, ActiveRecord::Type::String
159
+
160
+ m.register_type(%r(^char)i) do |sql_type|
161
+ precision = extract_precision(sql_type)
162
+ if Firebird.emulate_booleans? && precision == 1
163
+ ActiveRecord::Type::Boolean.new
164
+ else
165
+ ActiveRecord::Type::String.new(:precision => precision)
166
+ end
167
+ end
168
+
169
+ register_class_with_limit m, %r(datetime)i, ActiveRecord::Type::DateTime
170
+ register_class_with_limit m, %r(timestamp)i, TimestampType
171
+ end if AR42
172
+
173
+ def clear_cache!
174
+ super
175
+ reload_type_map
176
+ end if AR42
177
+
178
+ # @private
179
+ class DateType < ActiveRecord::Type::Date
180
+ # NOTE: quote still gets called ...
181
+ #def type_cast_for_database(value)
182
+ # if value.acts_like?(:date)
183
+ # "'#{value.strftime("%Y-%m-%d")}'"
184
+ # else
185
+ # super
186
+ # end
187
+ #end
188
+ end if AR42
189
+
190
+ # @private
191
+ class TimestampType < ActiveRecord::Type::DateTime
192
+ def type; :timestamp end
193
+ end if AR42
194
+
195
+ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
196
+ case type
197
+ when :integer
198
+ case limit
199
+ when nil then 'integer'
200
+ when 1..2 then 'smallint'
201
+ when 3..4 then 'integer'
202
+ when 5..8 then 'bigint'
203
+ else raise(ActiveRecordError, "No integer type has byte size #{limit}. "<<
204
+ "Use a NUMERIC with PRECISION 0 instead.")
205
+ end
206
+ when :float
207
+ if limit.nil? || limit <= 4
208
+ 'float'
209
+ else
210
+ 'double precision'
211
+ end
212
+ else super
213
+ end
214
+ end
215
+
216
+ # Does this adapter support migrations?
217
+ def supports_migrations?
218
+ true
219
+ end
220
+
221
+ # Can this adapter determine the primary key for tables not attached
222
+ # to an Active Record class, such as join tables?
223
+ def supports_primary_key?
224
+ true
225
+ end
226
+
227
+ # Does this adapter support using DISTINCT within COUNT?
228
+ def supports_count_distinct?
229
+ true
230
+ end
231
+
232
+ # Does this adapter support DDL rollbacks in transactions? That is, would
233
+ # CREATE TABLE or ALTER TABLE get rolled back by a transaction? PostgreSQL,
234
+ # SQL Server, and others support this. MySQL and others do not.
235
+ def supports_ddl_transactions?
236
+ false
237
+ end
238
+
239
+ # Does this adapter restrict the number of IDs you can use in a list.
240
+ # Oracle has a limit of 1000.
241
+ def ids_in_list_limit
242
+ 1499
243
+ end
244
+
245
+ def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
246
+ execute(sql, name, binds)
247
+ id_value
248
+ end
249
+
250
+ def add_limit_offset!(sql, options)
251
+ if limit = options[:limit]
252
+ insert_limit_offset!(sql, limit, options[:offset])
253
+ end
254
+ end
255
+
256
+ # @private
257
+ SELECT_RE = /\A(\s*SELECT\s)/i
258
+
259
+ def insert_limit_offset!(sql, limit, offset)
260
+ lim_off = ''
261
+ lim_off << "FIRST #{limit}" if limit
262
+ lim_off << " SKIP #{offset}" if offset
263
+ lim_off.strip!
264
+
265
+ sql.sub!(SELECT_RE, "\\&#{lim_off} ") unless lim_off.empty?
266
+ end
267
+
268
+ # Should primary key values be selected from their corresponding
269
+ # sequence before the insert statement?
270
+ # @see #next_sequence_value
271
+ # @override
272
+ def prefetch_primary_key?(table_name = nil)
273
+ return true if table_name.nil?
274
+ primary_keys(table_name.to_s).size == 1
275
+ # columns(table_name).count { |column| column.primary } == 1
276
+ end
277
+
278
+ IDENTIFIER_LENGTH = 31 # usual DB meta-identifier: 31 chars maximum
279
+
280
+ def table_alias_length; IDENTIFIER_LENGTH; end
281
+ def table_name_length; IDENTIFIER_LENGTH; end
282
+ def index_name_length; IDENTIFIER_LENGTH; end
283
+ def column_name_length; IDENTIFIER_LENGTH; end
284
+
285
+ def default_sequence_name(table_name, column = nil)
286
+ len = IDENTIFIER_LENGTH - 4
287
+ table_name.to_s.gsub (/(^|\.)([\w$-]{1,#{len}})([\w$-]*)$/), '\1\2_seq'
288
+ end
289
+
290
+ # Set the sequence to the max value of the table's column.
291
+ def reset_sequence!(table, column, sequence = nil)
292
+ max_id = select_value("SELECT max(#{column}) FROM #{table}")
293
+ execute("ALTER SEQUENCE #{default_sequence_name(table, column)} RESTART WITH #{max_id}")
294
+ end
295
+
296
+ def next_sequence_value(sequence_name)
297
+ select_one("SELECT GEN_ID(#{sequence_name}, 1 ) FROM RDB$DATABASE;")["gen_id"]
298
+ end
299
+
300
+ def create_table(name, options = {})
301
+ super(name, options)
302
+ execute "CREATE GENERATOR #{default_sequence_name(name)}"
303
+ end
304
+
305
+ def rename_table(name, new_name)
306
+ execute "RENAME #{name} TO #{new_name}"
307
+ name_seq, new_name_seq = default_sequence_name(name), default_sequence_name(new_name)
308
+ execute_quietly "UPDATE RDB$GENERATORS SET RDB$GENERATOR_NAME='#{new_name_seq}' WHERE RDB$GENERATOR_NAME='#{name_seq}'"
309
+ end
310
+
311
+ def drop_table(name, options = {})
312
+ super(name)
313
+ execute_quietly "DROP GENERATOR #{default_sequence_name(name)}"
314
+ end
315
+
316
+ def change_column(table_name, column_name, type, options = {})
317
+ execute "ALTER TABLE #{table_name} ALTER #{column_name} TYPE #{type_to_sql(type, options[:limit])}"
318
+ end
319
+
320
+ def rename_column(table_name, column_name, new_column_name)
321
+ execute "ALTER TABLE #{table_name} ALTER #{column_name} TO #{new_column_name}"
322
+ end
323
+
324
+ def remove_index(table_name, options)
325
+ execute "DROP INDEX #{index_name(table_name, options)}"
326
+ end
327
+
328
+ # @override
329
+ def quote(value, column = nil)
330
+ return value.quoted_id if value.respond_to?(:quoted_id)
331
+ return value if sql_literal?(value)
332
+
333
+ type = column && column.type
334
+
335
+ # BLOBs are updated separately by an after_save trigger.
336
+ if type == :binary || type == :text
337
+ if update_lob_values?
338
+ return value.nil? ? "NULL" : BLOB_VALUE_MARKER
339
+ else
340
+ return "'#{quote_string(value)}'"
341
+ end
342
+ end
343
+
344
+ case value
345
+ when String, ActiveSupport::Multibyte::Chars
346
+ value = value.to_s
347
+ if type == :integer
348
+ value.to_i.to_s
349
+ elsif type == :float
350
+ value.to_f.to_s
351
+ else
352
+ "'#{quote_string(value)}'"
353
+ end
354
+ when NilClass then 'NULL'
355
+ when TrueClass then (type == :integer ? '1' : quoted_true)
356
+ when FalseClass then (type == :integer ? '0' : quoted_false)
357
+ when Float, Fixnum, Bignum then value.to_s
358
+ # BigDecimals need to be output in a non-normalized form and quoted.
359
+ when BigDecimal then value.to_s('F')
360
+ when Symbol then "'#{quote_string(value.to_s)}'"
361
+ else
362
+ if type == :time && value.acts_like?(:time)
363
+ return "'#{get_time(value).strftime("%H:%M:%S")}'"
364
+ end
365
+ if type == :date && value.acts_like?(:date)
366
+ return "'#{value.strftime("%Y-%m-%d")}'"
367
+ end
368
+ super
369
+ end
370
+ end
371
+
372
+ # @override
373
+ def quoted_date(value)
374
+ if value.acts_like?(:time) && value.respond_to?(:usec)
375
+ usec = sprintf "%04d", (value.usec / 100.0).round
376
+ value = ::ActiveRecord::Base.default_timezone == :utc ? value.getutc : value.getlocal
377
+ "#{value.strftime("%Y-%m-%d %H:%M:%S")}.#{usec}"
378
+ else
379
+ super
380
+ end
381
+ end if ::ActiveRecord::VERSION::MAJOR >= 3
382
+
383
+ # @override
384
+ def quote_string(string)
385
+ string.gsub(/'/, "''")
386
+ end
387
+
388
+ # @override
389
+ def quoted_true
390
+ quote(1)
391
+ end
392
+
393
+ # @override
394
+ def quoted_false
395
+ quote(0)
396
+ end
397
+
398
+ # @override
399
+ def quote_table_name_for_assignment(table, attr)
400
+ quote_column_name(attr)
401
+ end if ::ActiveRecord::VERSION::MAJOR >= 4
402
+
403
+ # @override
404
+ def quote_column_name(column_name)
405
+ column_name = column_name.to_s
406
+ %Q("#{column_name =~ /[[:upper:]]/ ? column_name : column_name.upcase}")
407
+ end
408
+
409
+ def self.const_missing(name)
410
+ if name.to_sym == :Column
411
+ ArJdbc.deprecate("#{self.name}::Column will change to refer to the actual column class, please use ColumnMethods instead", :once)
412
+ return ColumnMethods
413
+ end
414
+ super
415
+ end
416
+
417
+ end
418
+ FireBird = Firebird
419
+ end
420
+
421
+ module ActiveRecord::ConnectionAdapters
422
+ remove_const(:FirebirdAdapter) if const_defined?(:FirebirdAdapter)
423
+ class FirebirdAdapter < JdbcAdapter
424
+ include ::ArJdbc::Firebird
425
+
426
+ class Column < JdbcColumn
427
+ include ::ArJdbc::Firebird::ColumnMethods
428
+ end
429
+ end
430
+ end
431
+
432
+ require 'arjdbc/util/quoted_cache'
433
+
434
+ module ActiveRecord::ConnectionAdapters
435
+
436
+ remove_const(:FirebirdAdapter) if const_defined?(:FirebirdAdapter)
437
+
438
+ class FirebirdAdapter < JdbcAdapter
439
+ include ::ArJdbc::Firebird
440
+ include ::ArJdbc::Util::QuotedCache
441
+
442
+ # By default, the FirebirdAdapter will consider all columns of type
443
+ # <tt>char(1)</tt> as boolean. If you wish to disable this :
444
+ #
445
+ # ActiveRecord::ConnectionAdapters::FirebirdAdapter.emulate_booleans = false
446
+ #
447
+ def self.emulate_booleans?; ::ArJdbc::Firebird.emulate_booleans?; end
448
+ def self.emulate_booleans; ::ArJdbc::Firebird.emulate_booleans?; end # oracle-enhanced
449
+ def self.emulate_booleans=(emulate); ::ArJdbc::Firebird.emulate_booleans = emulate; end
450
+
451
+ def initialize(*args)
452
+ ::ArJdbc::Firebird.initialize!
453
+ super
454
+ end
455
+
456
+ end
457
+
458
+ class Column < JdbcColumn
459
+ include ::ArJdbc::Firebird::ColumnMethods
460
+ end
461
+
462
+ end
463
+
464
+ #module ArJdbc
465
+ # module Firebird
466
+ # Column = ::ActiveRecord::ConnectionAdapters::FirebirdColumn
467
+ # end
468
+ #end