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,150 @@
1
+ module ArJdbc
2
+ module MySQL
3
+ module BulkChangeTable
4
+
5
+ # @private
6
+ AR41 = ::ActiveRecord::VERSION::STRING >= '4.1'
7
+
8
+ # @private
9
+ #ActiveRecordError = ActiveRecord::ActiveRecordError
10
+
11
+ # @private
12
+ ChangeColumnDefinition = ::ActiveRecord::ConnectionAdapters::ChangeColumnDefinition if AR41
13
+
14
+ # @override
15
+ def supports_bulk_alter?; true end
16
+
17
+ def bulk_change_table(table_name, operations)
18
+ sqls = operations.map do |command, args|
19
+ table, arguments = args.shift, args
20
+ method = :"#{command}_sql"
21
+
22
+ if respond_to?(method, true)
23
+ send(method, table, *arguments)
24
+ else
25
+ raise "Unknown method called : #{method}(#{arguments.inspect})"
26
+ end
27
+ end
28
+ sqls.flatten!
29
+
30
+ execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls.join(", ")}")
31
+ end
32
+
33
+ protected
34
+
35
+ def add_column_sql(table_name, column_name, type, options = {})
36
+ add_column_sql = "ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
37
+ add_column_options!(add_column_sql, options)
38
+ add_column_position!(add_column_sql, options)
39
+ add_column_sql
40
+ end unless AR41
41
+
42
+ def add_column_sql(table_name, column_name, type, options = {})
43
+ td = create_table_definition table_name, options[:temporary], options[:options]
44
+ cd = td.new_column_definition(column_name, type, options)
45
+ schema_creation.visit_AddColumn cd
46
+ end if AR41
47
+
48
+ def change_column_sql(table_name, column_name, type, options = {})
49
+ column = column_for(table_name, column_name)
50
+
51
+ unless options_include_default?(options)
52
+ options[:default] = column.default
53
+ end
54
+
55
+ unless options.has_key?(:null)
56
+ options[:null] = column.null
57
+ end
58
+
59
+ change_column_sql = "CHANGE #{quote_column_name(column_name)} #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
60
+ add_column_options!(change_column_sql, options)
61
+ add_column_position!(change_column_sql, options)
62
+ change_column_sql
63
+ end unless AR41
64
+
65
+ def change_column_sql(table_name, column_name, type, options = {})
66
+ column = column_for(table_name, column_name)
67
+
68
+ unless options_include_default?(options)
69
+ options[:default] = column.default
70
+ end
71
+
72
+ unless options.has_key?(:null)
73
+ options[:null] = column.null
74
+ end
75
+
76
+ options[:name] = column.name
77
+ schema_creation.accept ChangeColumnDefinition.new column, type, options
78
+ end if AR41
79
+
80
+ def rename_column_sql(table_name, column_name, new_column_name)
81
+ options = {}
82
+
83
+ if column = columns(table_name).find { |c| c.name == column_name.to_s }
84
+ options[:default] = column.default
85
+ options[:null] = column.null
86
+ options[:auto_increment] = (column.extra == "auto_increment")
87
+ else
88
+ raise ActiveRecordError, "No such column: #{table_name}.#{column_name}"
89
+ end
90
+
91
+ current_type = select_one("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE '#{column_name}'", 'SCHEMA')["Type"]
92
+ rename_column_sql = "CHANGE #{quote_column_name(column_name)} #{quote_column_name(new_column_name)} #{current_type}"
93
+ add_column_options!(rename_column_sql, options)
94
+ rename_column_sql
95
+ end unless AR41
96
+
97
+ def rename_column_sql(table_name, column_name, new_column_name)
98
+ options = { :name => new_column_name }
99
+
100
+ if column = columns(table_name).find { |c| c.name == column_name.to_s }
101
+ options[:default] = column.default
102
+ options[:null] = column.null
103
+ options[:auto_increment] = (column.extra == "auto_increment")
104
+ else
105
+ raise ActiveRecordError, "No such column: #{table_name}.#{column_name}"
106
+ end
107
+
108
+ current_type = select_one("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE '#{column_name}'", 'SCHEMA')["Type"]
109
+ schema_creation.accept ChangeColumnDefinition.new column, current_type, options
110
+ end if AR41
111
+
112
+ def remove_column_sql(table_name, column_name, type = nil, options = nil)
113
+ "DROP #{quote_column_name(column_name)}"
114
+ end
115
+
116
+ def remove_columns_sql(table_name, *column_names)
117
+ column_names.map { |column_name| remove_column_sql(table_name, column_name) }
118
+ end
119
+
120
+ def add_index_sql(table_name, column_name, options = {})
121
+ index_name, index_type, index_columns = add_index_options(table_name, column_name, options)
122
+ "ADD #{index_type} INDEX #{index_name} (#{index_columns})"
123
+ end
124
+
125
+ def remove_index_sql(table_name, options = {})
126
+ index_name = index_name_for_remove(table_name, options)
127
+ "DROP INDEX #{index_name}"
128
+ end
129
+
130
+ def add_timestamps_sql(table_name, options = {})
131
+ [add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)]
132
+ end
133
+
134
+ def remove_timestamps_sql(table_name, options = nil)
135
+ [remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)]
136
+ end
137
+
138
+ private
139
+
140
+ def add_column_position!(sql, options)
141
+ if options[:first]
142
+ sql << " FIRST"
143
+ elsif options[:after]
144
+ sql << " AFTER #{quote_column_name(options[:after])}"
145
+ end
146
+ end
147
+
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,167 @@
1
+ module ArJdbc
2
+ module MySQL
3
+
4
+ # @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
5
+ def self.column_selector
6
+ [ /mysql/i, lambda { |config, column| column.extend(ColumnMethods) } ]
7
+ end
8
+
9
+ # Column behavior based on (abstract) MySQL adapter in Rails.
10
+ # @see ActiveRecord::ConnectionAdapters::JdbcColumn
11
+ module ColumnMethods
12
+
13
+ attr_reader :collation, :strict, :extra
14
+
15
+ def initialize(name, default, sql_type = nil, null = true, collation = nil, strict = false, extra = '')
16
+ if name.is_a?(Hash)
17
+ super # first arg: config
18
+ else
19
+ @strict = strict; @collation = collation; @extra = extra
20
+ super(name, default, sql_type, null)
21
+ # base 4.1: (name, default, sql_type = nil, null = true)
22
+ end
23
+ end unless AR42
24
+
25
+ def initialize(name, default, cast_type, sql_type = nil, null = true, collation = nil, strict = false, extra = '')
26
+ if name.is_a?(Hash)
27
+ super # first arg: config
28
+ else
29
+ @strict = strict; @collation = collation; @extra = extra
30
+ super(name, default, cast_type, sql_type, null)
31
+ # base 4.2: (name, default, cast_type, sql_type = nil, null = true)
32
+ #assert_valid_default(default) done with #extract_default
33
+ #@default = null || ( strict ? nil : '' ) if blob_or_text_column?
34
+ end
35
+ end if AR42
36
+
37
+ def extract_default(default)
38
+ if blob_or_text_column?
39
+ return null || strict ? nil : '' if default.blank?
40
+ raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}"
41
+ elsif missing_default_forged_as_empty_string?(default)
42
+ nil
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def has_default?
49
+ return false if blob_or_text_column? #mysql forbids defaults on blob and text columns
50
+ super
51
+ end
52
+
53
+ def blob_or_text_column?
54
+ sql_type.index('blob') || type == :text
55
+ end
56
+
57
+ def case_sensitive?
58
+ collation && !collation.match(/_ci$/)
59
+ end
60
+
61
+ def ==(other)
62
+ collation == other.collation &&
63
+ strict == other.strict &&
64
+ extra == other.extra &&
65
+ super
66
+ end if AR42
67
+
68
+ def simplified_type(field_type)
69
+ if adapter && adapter.emulate_booleans?
70
+ return :boolean if field_type.downcase.index('tinyint(1)')
71
+ end
72
+
73
+ case field_type
74
+ when /enum/i, /set/i then :string
75
+ when /year/i then :integer
76
+ # :tinyint : {:name=>"tinyint", :limit=>3}
77
+ # :"tinyint unsigned" : {:name=>"tinyint unsigned", :limit=>3}
78
+ # :bigint : {:name=>"bigint", :limit=>19}
79
+ # :"bigint unsigned" : {:name=>"bigint unsigned", :limit=>20}
80
+ # :integer : {:name=>"integer", :limit=>10}
81
+ # :"integer unsigned" : {:name=>"integer unsigned", :limit=>10}
82
+ # :int : {:name=>"int", :limit=>10}
83
+ # :"int unsigned" : {:name=>"int unsigned", :limit=>10}
84
+ # :mediumint : {:name=>"mediumint", :limit=>7}
85
+ # :"mediumint unsigned" : {:name=>"mediumint unsigned", :limit=>8}
86
+ # :smallint : {:name=>"smallint", :limit=>5}
87
+ # :"smallint unsigned" : {:name=>"smallint unsigned", :limit=>5}
88
+ when /int/i then :integer
89
+ when /double/i then :float # double precision (alias)
90
+ when 'bool' then :boolean
91
+ when 'char' then :string
92
+ # :mediumtext => {:name=>"mediumtext", :limit=>16777215}
93
+ # :longtext => {:name=>"longtext", :limit=>2147483647}
94
+ # :text => {:name=>"text"}
95
+ # :tinytext => {:name=>"tinytext", :limit=>255}
96
+ when /text/i then :text
97
+ when 'long varchar' then :text
98
+ # :"long varbinary" => {:name=>"long varbinary", :limit=>16777215}
99
+ # :varbinary => {:name=>"varbinary", :limit=>255}
100
+ when /binary/i then :binary
101
+ # :mediumblob => {:name=>"mediumblob", :limit=>16777215}
102
+ # :longblob => {:name=>"longblob", :limit=>2147483647}
103
+ # :blob => {:name=>"blob", :limit=>65535}
104
+ # :tinyblob => {:name=>"tinyblob", :limit=>255}
105
+ when /blob/i then :binary
106
+ when /^bit/i then :binary
107
+ else
108
+ super
109
+ end
110
+ end
111
+
112
+ def extract_limit(sql_type)
113
+ case sql_type
114
+ when /blob|text/i
115
+ case sql_type
116
+ when /tiny/i
117
+ 255
118
+ when /medium/i
119
+ 16777215
120
+ when /long/i
121
+ 2147483647 # mysql only allows 2^31-1, not 2^32-1, somewhat inconsistently with the tiny/medium/normal cases
122
+ else
123
+ super # we could return 65535 here, but we leave it undecorated by default
124
+ end
125
+ when /^bigint/i; 8
126
+ when /^int/i; 4
127
+ when /^mediumint/i; 3
128
+ when /^smallint/i; 2
129
+ when /^tinyint/i; 1
130
+ when /^enum\((.+)\)/i # 255
131
+ $1.split(',').map{ |enum| enum.strip.length - 2 }.max
132
+ when /^(bool|date|float|int|time)/i
133
+ nil
134
+ else
135
+ super
136
+ end
137
+ end unless AR42 # on AR 4.2 limit is delegated to cast_type.limit
138
+
139
+ private
140
+
141
+ # MySQL misreports NOT NULL column default when none is given.
142
+ # We can't detect this for columns which may have a legitimate ''
143
+ # default (string) but we can for others (integer, datetime, boolean,
144
+ # and the rest).
145
+ #
146
+ # Test whether the column has default '', is not null, and is not
147
+ # a type allowing default ''.
148
+ def missing_default_forged_as_empty_string?(default)
149
+ type != :string && ! null && default == ''
150
+ end
151
+
152
+ def attributes_for_hash; super + [collation, strict, extra] end
153
+
154
+ def adapter; end
155
+
156
+ end
157
+
158
+ # def self.const_missing(name)
159
+ # if name.to_sym == :Column
160
+ # ArJdbc.deprecate("#{self.name}::Column will change to refer to the actual column class, please use ColumnMethods instead", :once)
161
+ # return ColumnMethods
162
+ # end
163
+ # super
164
+ # end
165
+
166
+ end
167
+ end
@@ -0,0 +1,137 @@
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ def mysql_connection(config)
3
+ config[:adapter_spec] ||= ::ArJdbc::MySQL
4
+ config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter unless config.key?(:adapter_class)
5
+
6
+ return jndi_connection(config) if jndi_config?(config)
7
+
8
+ driver = config[:driver] ||= 'com.mysql.jdbc.NonRegisteringDriver'
9
+ mysql_driver = driver.start_with?('com.mysql.')
10
+ ArJdbc.load_driver(:MySQL) if mysql_driver && config[:load_driver] != false
11
+
12
+ config[:username] = 'root' unless config.key?(:username)
13
+ # jdbc:mysql://[host][,failoverhost...][:port]/[database]
14
+ # - if the host name is not specified, it defaults to 127.0.0.1
15
+ # - if the port is not specified, it defaults to 3306
16
+ # - alternate fail-over syntax: [host:port],[host:port]/[database]
17
+ unless config[:url]
18
+ host = config[:host]; host = host.join(',') if host.respond_to?(:join)
19
+ url = "jdbc:mysql://#{host}"
20
+ url << ":#{config[:port]}" if config[:port]
21
+ url << "/#{config[:database]}"
22
+ config[:url] = url
23
+ end
24
+
25
+ mariadb_driver = ! mysql_driver && driver.start_with?('org.mariadb.')
26
+
27
+ properties = ( config[:properties] ||= {} )
28
+ if mysql_driver
29
+ properties['zeroDateTimeBehavior'] ||= 'convertToNull'
30
+ properties['jdbcCompliantTruncation'] ||= 'false'
31
+ # NOTE: this is "better" than passing what users are used to set on MRI
32
+ # e.g. 'utf8mb4' will fail cause the driver will check for a Java charset
33
+ # ... it's smart enough to detect utf8mb4 from server variables :
34
+ # "character_set_client" && "character_set_connection" (thus UTF-8)
35
+ if encoding = config[:encoding]
36
+ properties['characterEncoding'] = convert_mysql_encoding(encoding) || encoding
37
+ # driver also executes: "SET NAMES " + (useutf8mb4 ? "utf8mb4" : "utf8")
38
+ config[:encoding] = nil # thus no need to do it on configure_connection
39
+ end
40
+ # properties['useUnicode'] is true by default
41
+ if ! ( reconnect = config[:reconnect] ).nil?
42
+ properties['autoReconnect'] ||= reconnect.to_s
43
+ # properties['maxReconnects'] ||= '3'
44
+ # with reconnect fail-over sets connection read-only (by default)
45
+ # properties['failOverReadOnly'] ||= 'false'
46
+ end
47
+ end
48
+ if config[:sslkey] || sslcert = config[:sslcert] # || config[:use_ssl]
49
+ properties['useSSL'] ||= true # supported by MariaDB as well
50
+ if mysql_driver
51
+ properties['requireSSL'] ||= true if mysql_driver
52
+ properties['clientCertificateKeyStoreUrl'] ||= begin
53
+ java.io.File.new(sslcert).to_url.to_s
54
+ end if sslcert
55
+ if sslca = config[:sslca]
56
+ properties['trustCertificateKeyStoreUrl'] ||= begin
57
+ java.io.File.new(sslca).to_url.to_s
58
+ end
59
+ else
60
+ properties['verifyServerCertificate'] ||= false if mysql_driver
61
+ end
62
+ end
63
+ if mariadb_driver
64
+ properties['verifyServerCertificate'] ||= false
65
+ end
66
+ end
67
+ if socket = config[:socket]
68
+ properties['localSocket'] ||= socket if mariadb_driver
69
+ end
70
+
71
+ jdbc_connection(config)
72
+ end
73
+ alias_method :jdbcmysql_connection, :mysql_connection
74
+ alias_method :mysql2_connection, :mysql_connection
75
+
76
+ def mariadb_connection(config)
77
+ config[:adapter_spec] ||= ::ArJdbc::MySQL
78
+ config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter unless config.key?(:adapter_class)
79
+
80
+ return jndi_connection(config) if jndi_config?(config)
81
+
82
+ ArJdbc.load_driver(:MariaDB) unless config[:load_driver] == false
83
+ config[:driver] ||= 'org.mariadb.jdbc.Driver'
84
+
85
+ mysql_connection(config)
86
+ end
87
+ alias_method :jdbcmariadb_connection, :mariadb_connection
88
+
89
+ private
90
+
91
+ @@mysql_encodings = nil
92
+
93
+ def convert_mysql_encoding(encoding) # from mysql2's ruby_enc_to_mysql
94
+ ( @@mysql_encodings ||= {
95
+ "big5" => "Big5",
96
+ "dec8" => nil,
97
+ "cp850" => "CP850",
98
+ "hp8" => nil,
99
+ "koi8r" => "KOI8-R",
100
+ "latin1" => "ISO-8859-1",
101
+ "latin2" => "ISO-8859-2",
102
+ "swe7" => nil,
103
+ "ascii" => "US-ASCII",
104
+ #"ujis" => "eucJP-ms",
105
+ #"sjis" => "Shift_JIS",
106
+ "hebrew" => "ISO-8859-8",
107
+ #"tis620" => "TIS-620",
108
+ #"euckr" => "EUC-KR",
109
+ #"koi8u" => "KOI8-R",
110
+ #"gb2312" => "GB2312",
111
+ "greek" => "ISO-8859-7",
112
+ "cp1250" => "Windows-1250",
113
+ #"gbk" => "GBK",
114
+ "latin5" => "ISO-8859-9",
115
+ "armscii8" => nil,
116
+ "utf8" => "UTF-8",
117
+ "ucs2" => "UTF-16BE",
118
+ "cp866" => "IBM866",
119
+ "keybcs2" => nil,
120
+ #"macce" => "macCentEuro",
121
+ #"macroman" => "macRoman",
122
+ "cp852" => "CP852",
123
+ "latin7" => "ISO-8859-13",
124
+ "utf8mb4" => "UTF-8",
125
+ "cp1251" => "Windows-1251",
126
+ "utf16" => "UTF-16",
127
+ "cp1256" => "Windows-1256",
128
+ "cp1257" => "Windows-1257",
129
+ "utf32" => "UTF-32",
130
+ "binary" => "ASCII-8BIT",
131
+ "geostd8" => nil,
132
+ #"cp932" => "Windows-31J",
133
+ #"eucjpms" => "eucJP-ms"
134
+ } )[ encoding ]
135
+ end
136
+
137
+ end