activerecord-jdbc-adapter 5.0.pre1 → 50.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord-jdbc-adapter might be problematic. Click here for more details.

Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.travis.yml +15 -416
  4. data/Gemfile +35 -37
  5. data/README.md +23 -118
  6. data/RUNNING_TESTS.md +31 -26
  7. data/Rakefile +2 -3
  8. data/lib/arjdbc/abstract/connection_management.rb +21 -0
  9. data/lib/arjdbc/abstract/core.rb +62 -0
  10. data/lib/arjdbc/abstract/database_statements.rb +46 -0
  11. data/lib/arjdbc/abstract/statement_cache.rb +58 -0
  12. data/lib/arjdbc/abstract/transaction_support.rb +86 -0
  13. data/lib/arjdbc/derby/adapter.rb +6 -1
  14. data/lib/arjdbc/discover.rb +0 -7
  15. data/lib/arjdbc/firebird/adapter.rb +2 -2
  16. data/lib/arjdbc/jdbc.rb +2 -2
  17. data/lib/arjdbc/jdbc/adapter.rb +10 -252
  18. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  19. data/lib/arjdbc/jdbc/connection.rb +6 -0
  20. data/lib/arjdbc/mysql/adapter.rb +82 -946
  21. data/lib/arjdbc/mysql/connection_methods.rb +4 -2
  22. data/lib/arjdbc/postgresql/adapter.rb +270 -970
  23. data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
  24. data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
  25. data/lib/arjdbc/postgresql/base/pgconn.rb +8 -5
  26. data/lib/arjdbc/postgresql/column.rb +10 -599
  27. data/lib/arjdbc/postgresql/connection_methods.rb +9 -0
  28. data/lib/arjdbc/postgresql/name.rb +24 -0
  29. data/lib/arjdbc/postgresql/oid_types.rb +28 -109
  30. data/lib/arjdbc/sqlite3/adapter.rb +18 -42
  31. data/lib/arjdbc/tasks/database_tasks.rb +1 -3
  32. data/lib/arjdbc/tasks/db2_database_tasks.rb +2 -2
  33. data/lib/arjdbc/version.rb +1 -1
  34. data/pom.xml +3 -3
  35. data/rakelib/02-test.rake +0 -12
  36. data/rakelib/compile.rake +1 -1
  37. data/rakelib/db.rake +7 -5
  38. data/rakelib/rails.rake +67 -64
  39. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +1 -17
  40. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +518 -1260
  41. data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
  42. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +53 -134
  43. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -240
  44. data/src/java/arjdbc/sqlite3/SQLite3Module.java +0 -20
  45. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +85 -10
  46. metadata +16 -29
  47. data/Appraisals +0 -41
  48. data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
  49. data/lib/arjdbc/common_jdbc_methods.rb +0 -89
  50. data/lib/arjdbc/mysql/bulk_change_table.rb +0 -150
  51. data/lib/arjdbc/mysql/column.rb +0 -162
  52. data/lib/arjdbc/mysql/explain_support.rb +0 -82
  53. data/lib/arjdbc/mysql/schema_creation.rb +0 -58
  54. data/lib/arjdbc/oracle.rb +0 -4
  55. data/lib/arjdbc/oracle/adapter.rb +0 -952
  56. data/lib/arjdbc/oracle/column.rb +0 -126
  57. data/lib/arjdbc/oracle/connection_methods.rb +0 -21
  58. data/lib/arjdbc/postgresql/base/oid.rb +0 -412
  59. data/lib/arjdbc/postgresql/base/schema_definitions.rb +0 -131
  60. data/lib/arjdbc/postgresql/explain_support.rb +0 -53
  61. data/lib/arjdbc/postgresql/oid/bytea.rb +0 -2
  62. data/lib/arjdbc/postgresql/schema_creation.rb +0 -60
  63. data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +0 -297
  64. data/lib/arjdbc/tasks/oracle_database_tasks.rb +0 -65
  65. data/src/java/arjdbc/oracle/OracleModule.java +0 -75
  66. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +0 -465
@@ -42,7 +42,16 @@ ArJdbc::ConnectionMethods.module_eval do
42
42
  properties['tcpKeepAlive'] ||= config[:keepalives] if config.key?(:keepalives)
43
43
  properties['kerberosServerName'] ||= config[:krbsrvname] if config[:krbsrvname]
44
44
 
45
+ # If prepared statements are off, lets make sure they are really *off*
46
+ properties['prepareThreshold'] = 0 unless config[:prepared_statements]
47
+
45
48
  jdbc_connection(config)
49
+ rescue ActiveRecord::JDBCError => e
50
+ if e.message.include?('does not exist')
51
+ raise ActiveRecord::NoDatabaseError, e.message
52
+ else
53
+ raise
54
+ end
46
55
  end
47
56
  alias_method :jdbcpostgresql_connection, :postgresql_connection
48
57
  end
@@ -0,0 +1,24 @@
1
+ # This patches the Name class so that it doesn't use pg gem specific quoting
2
+ module ActiveRecord
3
+ module ConnectionAdapters
4
+ module PostgreSQL
5
+ class Name
6
+
7
+ def quoted
8
+ if schema
9
+ "#{quote_identifier(schema)}#{SEPARATOR}#{quote_identifier(identifier)}"
10
+ else
11
+ quote_identifier(identifier)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def quote_identifier(name)
18
+ %("#{name.to_s.gsub("\"", "\"\"")}")
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,13 +3,7 @@ require 'thread'
3
3
  module ArJdbc
4
4
  module PostgreSQL
5
5
 
6
- if AR42
7
- require 'active_record/connection_adapters/postgresql/oid'
8
- require 'arjdbc/postgresql/oid/bytea.rb'
9
- else
10
- require 'arjdbc/postgresql/base/oid'
11
- end
12
-
6
+ require 'active_record/connection_adapters/postgresql/oid'
13
7
  require 'arjdbc/postgresql/base/pgconn'
14
8
 
15
9
  def self.unescape_bytea(escaped)
@@ -22,6 +16,13 @@ module ArJdbc
22
16
  # @private
23
17
  module OIDTypes
24
18
 
19
+ # Support arrays/ranges for defining attributes that don't exist in the db
20
+ Type.add_modifier({ array: true }, OID::Array, adapter: :postgresql)
21
+ Type.add_modifier({ range: true }, OID::Range, adapter: :postgresql)
22
+ Type.register(:enum, OID::Enum, adapter: :postgresql)
23
+ Type.register(:point, OID::Rails51Point, adapter: :postgresql)
24
+ Type.register(:legacy_point, OID::Point, adapter: :postgresql)
25
+
25
26
  # @override
26
27
  def enable_extension(name)
27
28
  result = super(name)
@@ -47,14 +48,7 @@ module ArJdbc
47
48
  def lookup_cast_type(sql_type)
48
49
  oid = execute("SELECT #{quote(sql_type)}::regtype::oid", "SCHEMA")
49
50
  super oid.first['oid'].to_i
50
- end if AR42
51
-
52
- def get_oid_type(oid, fmod, column_name)
53
- type_map.fetch(oid, fmod) {
54
- warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String."
55
- type_map[oid] = OID::Identity.new
56
- }
57
- end unless AR42
51
+ end
58
52
 
59
53
  def get_oid_type(oid, fmod, column_name, sql_type = '')
60
54
  if !type_map.key?(oid)
@@ -67,40 +61,10 @@ module ArJdbc
67
61
  type_map.register_type(oid, cast_type)
68
62
  end
69
63
  }
70
- end if AR42
71
-
72
- @@type_map_cache = {}
73
- @@type_map_cache_lock = Mutex.new
74
-
75
- if AR42
76
- TypeMap = ActiveRecord::Type::HashLookupTypeMap
77
- else
78
- TypeMap = OID::TypeMap
79
- end
80
-
81
- # @see #type_map
82
- # @private
83
- TypeMap.class_eval do
84
- def dup
85
- dup = super # make sure @mapping is not shared
86
- dup.instance_variable_set(:@mapping, @mapping.dup)
87
- dup
88
- end
89
64
  end
90
65
 
91
66
  def type_map
92
- # NOTE: our type_map is lazy (on AR < 4.2)
93
- # ... since it's only used for `adapter.accessor`
94
- @type_map ||= begin
95
- if type_map = @@type_map_cache[ type_cache_key ]
96
- type_map.dup
97
- else
98
- type_map = TypeMap.new
99
- initialize_type_map(type_map)
100
- cache_type_map(type_map)
101
- type_map
102
- end
103
- end
67
+ @type_map
104
68
  end
105
69
 
106
70
  def reload_type_map
@@ -112,57 +76,6 @@ module ArJdbc
112
76
 
113
77
  private
114
78
 
115
- def cache_type_map(type_map)
116
- @@type_map_cache_lock.synchronize do
117
- @@type_map_cache[ type_cache_key ] = type_map
118
- end
119
- end
120
-
121
- def type_cache_key
122
- config.hash + ( 7 * extensions.hash )
123
- end
124
-
125
- def add_oid(row, records_by_oid, type_map)
126
- return type_map if type_map.key? row['type_elem'].to_i
127
-
128
- if OID.registered_type? typname = row['typname']
129
- # this composite type is explicitly registered
130
- vector = OID::NAMES[ typname ]
131
- else
132
- # use the default for composite types
133
- unless type_map.key? typelem = row['typelem'].to_i
134
- add_oid records_by_oid[ row['typelem'] ], records_by_oid, type_map
135
- end
136
-
137
- vector = OID::Vector.new row['typdelim'], type_map[typelem]
138
- end
139
-
140
- type_map[ row['oid'].to_i ] = vector
141
- type_map
142
- end
143
-
144
- def initialize_type_map(type_map)
145
- result = execute('SELECT oid, typname, typelem, typdelim, typinput FROM pg_type', 'SCHEMA')
146
- leaves, nodes = result.partition { |row| row['typelem'].to_s == '0' }
147
- # populate the leaf nodes
148
- leaves.find_all { |row| OID.registered_type? row['typname'] }.each do |row|
149
- type_map[ row['oid'].to_i ] = OID::NAMES[ row['typname'] ]
150
- end
151
-
152
- records_by_oid = result.group_by { |row| row['oid'] }
153
-
154
- arrays, nodes = nodes.partition { |row| row['typinput'] == 'array_in' }
155
-
156
- # populate composite types
157
- nodes.each { |row| add_oid row, records_by_oid, type_map }
158
-
159
- # populate array types
160
- arrays.find_all { |row| type_map.key? row['typelem'].to_i }.each do |row|
161
- array = OID::Array.new type_map[ row['typelem'].to_i ]
162
- type_map[ row['oid'].to_i ] = array
163
- end
164
- end unless AR42
165
-
166
79
  def initialize_type_map(m)
167
80
  register_class_with_limit m, 'int2', Type::Integer
168
81
  register_class_with_limit m, 'int4', Type::Integer
@@ -192,19 +105,25 @@ module ArJdbc
192
105
  m.register_type 'inet', OID::Inet.new
193
106
  m.register_type 'uuid', OID::Uuid.new
194
107
  m.register_type 'xml', OID::Xml.new
195
- m.register_type 'tsvector', OID::SpecializedString.new(:tsvector)
196
- m.register_type 'macaddr', OID::SpecializedString.new(:macaddr)
108
+ m.register_type 'box', OID::SpecializedString.new(:box)
109
+ m.register_type 'circle', OID::SpecializedString.new(:circle)
197
110
  m.register_type 'citext', OID::SpecializedString.new(:citext)
111
+ m.register_type 'line', OID::SpecializedString.new(:line)
112
+ m.register_type 'lseg', OID::SpecializedString.new(:lseg)
198
113
  m.register_type 'ltree', OID::SpecializedString.new(:ltree)
114
+ m.register_type 'macaddr', OID::SpecializedString.new(:macaddr)
115
+ m.register_type 'path', OID::SpecializedString.new(:path)
116
+ m.register_type 'polygon', OID::SpecializedString.new(:polygon)
117
+ m.register_type 'tsvector', OID::SpecializedString.new(:tsvector)
199
118
 
200
- # FIXME: why are we keeping these types as strings?
201
- m.alias_type 'interval', 'varchar'
202
- m.alias_type 'path', 'varchar'
203
- m.alias_type 'line', 'varchar'
204
- m.alias_type 'polygon', 'varchar'
205
- m.alias_type 'circle', 'varchar'
206
- m.alias_type 'lseg', 'varchar'
207
- m.alias_type 'box', 'varchar'
119
+ # This is how Rails 5.1 handles it. In 5.0 SpecializedString doesn't take a precision option
120
+ # 5.0 actually leaves it as a regular String but we need it specialized
121
+ # to support prepared statements
122
+ # m.register_type 'interval' do |_, _, sql_type|
123
+ # precision = extract_precision(sql_type)
124
+ # OID::SpecializedString.new(:interval, precision: precision)
125
+ # end
126
+ m.register_type 'interval', OID::SpecializedString.new(:interval)
208
127
 
209
128
  m.register_type 'timestamp' do |_, _, sql_type|
210
129
  precision = extract_precision(sql_type)
@@ -232,7 +151,7 @@ module ArJdbc
232
151
  end
233
152
 
234
153
  load_additional_types(m)
235
- end if AR42
154
+ end
236
155
 
237
156
  def load_additional_types(type_map, oids = nil)
238
157
  if supports_ranges?
@@ -261,7 +180,7 @@ module ArJdbc
261
180
 
262
181
  records = execute(query, 'SCHEMA')
263
182
  initializer.run(records)
264
- end if AR42
183
+ end
265
184
 
266
185
  end
267
186
  end
@@ -1,6 +1,9 @@
1
1
  ArJdbc.load_java_part :SQLite3
2
2
 
3
- require "arjdbc/common_jdbc_methods"
3
+ require "arjdbc/abstract/core"
4
+ require "arjdbc/abstract/database_statements"
5
+ require 'arjdbc/abstract/statement_cache'
6
+ require "arjdbc/abstract/transaction_support"
4
7
  require "active_record/connection_adapters/statement_pool"
5
8
  require "active_record/connection_adapters/abstract/database_statements"
6
9
  require "active_record/connection_adapters/sqlite3/explain_pretty_printer"
@@ -10,7 +13,10 @@ require "active_record/connection_adapters/sqlite3/schema_creation"
10
13
  module ArJdbc
11
14
  # All the code in this module is a copy of ConnectionAdapters::SQLite3Adapter from active_record 5.
12
15
  # The constants at the front of this file are to allow the rest of the file to remain with no modifications
13
- # from its original source.
16
+ # from its original source. If you hack on this file try not to modify this module and instead try and
17
+ # put those overrides in SQL3Adapter below. We try and keep a copy of the Rails this adapter supports
18
+ # with the current goal of being able to diff changes easily over time and to also eventually remove
19
+ # this module from ARJDBC altogether.
14
20
  module SQLite3
15
21
  # DIFFERENCE: Some common constant names to reduce differences in rest of this module from AR5 version
16
22
  ConnectionAdapters = ::ActiveRecord::ConnectionAdapters
@@ -54,7 +60,8 @@ module ArJdbc
54
60
  Arel::Visitors::SQLite.new(self)
55
61
  end
56
62
 
57
- def initialize(connection, logger, connection_options, config)
63
+ # Difference we remove connection_options because we are not using it.
64
+ def initialize(connection, logger, config)
58
65
  super(connection, logger, config)
59
66
 
60
67
  @active = nil
@@ -639,52 +646,21 @@ module ActiveRecord::ConnectionAdapters
639
646
  # ActiveRecord::ConnectionAdapters::SQLite3Adapter. Once we can do that we can remove the
640
647
  # module SQLite3 above and remove a majority of this file.
641
648
  class SQLite3Adapter < AbstractAdapter
642
- include ArJdbc::CommonJdbcMethods
649
+ include ArJdbc::Abstract::Core
643
650
  include ArJdbc::SQLite3
651
+ include ArJdbc::Abstract::DatabaseStatements
652
+ include ArJdbc::Abstract::StatementCache
653
+ include ArJdbc::Abstract::TransactionSupport
654
+
655
+ def begin_isolated_db_transaction(isolation)
656
+ raise ActiveRecord::TransactionIsolationError, 'adapter does not support setting transaction isolation'
657
+ end
644
658
 
645
659
  # FIXME: Add @connection.encoding then remove this method
646
660
  def encoding
647
661
  select_value 'PRAGMA encoding'
648
662
  end
649
663
 
650
- def exec_query(sql, name = nil, binds = [], prepare: false)
651
- use_prepared = prepare || !without_prepared_statement?(binds)
652
-
653
- if use_prepared
654
- type_casted_binds = prepare_binds_for_jdbc(binds)
655
- log(sql, name, binds) { @connection.execute_prepared(sql, type_casted_binds) }
656
- else
657
- log(sql, name) { @connection.execute(sql) }
658
- end
659
- end
660
-
661
- def exec_update(sql, name = nil, binds = [])
662
- use_prepared = !without_prepared_statement?(binds)
663
-
664
- if use_prepared
665
- type_casted_binds = prepare_binds_for_jdbc(binds)
666
- log(sql, name, binds) { @connection.execute_prepared_update(sql, type_casted_binds) }
667
- else
668
- log(sql, name) { @connection.execute_update(sql, nil) }
669
- end
670
- end
671
- alias :exec_delete :exec_update
672
-
673
- # Sqlite3 JDBC types in prepared statements seem to report blob as varchar (12).
674
- # So to work around this we will pass attribute type in with the value so we can
675
- # then remap to appropriate type in JDBC without needing to ask JDBC what type
676
- # it should be using. No one likes a stinking liar...
677
- def prepare_binds_for_jdbc(binds)
678
- binds.map do |attribute|
679
- [attribute.type.type, type_cast(attribute.value_for_database)]
680
- end
681
- end
682
-
683
- # last two values passed but not used so I cannot alias to exec_query
684
- def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
685
- exec_update(sql, name, binds)
686
- end
687
-
688
664
  def indexes(table_name, name = nil) #:nodoc:
689
665
  # on JDBC 3.7 we'll simply do super since it can not handle "PRAGMA index_info"
690
666
  return @connection.indexes(table_name, name) if sqlite_version < '3.8' # super
@@ -32,11 +32,9 @@ module ArJdbc
32
32
  require 'arjdbc/tasks/h2_database_tasks'
33
33
  require 'arjdbc/tasks/hsqldb_database_tasks'
34
34
  require 'arjdbc/tasks/mssql_database_tasks'
35
- require 'arjdbc/tasks/oracle_database_tasks'
36
35
 
37
36
  # re-invent built-in (but deprecated on 4.0) tasks :
38
37
  register_tasks(/sqlserver/, MSSQLDatabaseTasks)
39
- register_tasks(/(oci|oracle)/, OracleDatabaseTasks)
40
38
  register_tasks(/mssql/, MSSQLDatabaseTasks) # (built-in) alias
41
39
  # tasks for custom (JDBC) adapters :
42
40
  register_tasks(/db2/, DB2DatabaseTasks)
@@ -51,4 +49,4 @@ module ArJdbc
51
49
  # - while on 2.3/3.x we keep the AR built-in task behavior
52
50
 
53
51
  end
54
- end
52
+ end
@@ -82,9 +82,9 @@ module ArJdbc
82
82
  ensure
83
83
  pk_rs.close
84
84
  end
85
- primary_keys.each do |name, cols|
85
+ primary_keys.each do |constraint_name, cols|
86
86
  dump << "ALTER TABLE #{connection.quote_table_name(table_name)}\n"
87
- dump << " ADD CONSTRAINT #{name}\n"
87
+ dump << " ADD CONSTRAINT #{constraint_name}\n"
88
88
  dump << " PRIMARY KEY (#{cols.join(', ')});\n\n"
89
89
  end
90
90
  end
@@ -1,5 +1,5 @@
1
1
  module ArJdbc
2
- VERSION = "5.0.pre1"
2
+ VERSION = "50.0"
3
3
  # @deprecated
4
4
  module Version
5
5
  # @private 1.2.x compatibility
data/pom.xml CHANGED
@@ -12,7 +12,7 @@
12
12
  <url>http://github.com/jruby/activerecord-jdbc-adapter/wiki</url>
13
13
 
14
14
  <properties>
15
- <jruby.version>1.6.8</jruby.version>
15
+ <jruby.version>9.1.6.0</jruby.version>
16
16
  </properties>
17
17
 
18
18
  <issueManagement>
@@ -103,8 +103,8 @@
103
103
  <artifactId>maven-compiler-plugin</artifactId>
104
104
  <version>2.5.1</version>
105
105
  <configuration>
106
- <source>1.6</source>
107
- <target>1.6</target>
106
+ <source>1.7</source>
107
+ <target>1.7</target>
108
108
  </configuration>
109
109
  </plugin>
110
110
  </plugins>
@@ -17,15 +17,6 @@ task 'test_postgresql_with_hint' do
17
17
  end
18
18
  end
19
19
 
20
- task 'test_appraisal_hint' do
21
- next if File.exists?('.disable-appraisal-hint')
22
- unless (ENV['BUNDLE_GEMFILE'] || '') =~ /gemfiles\/.*?\.gemfile/
23
- appraisals = []; Appraisal::File.each { |file| appraisals << file.name }
24
- puts "HINT: specify AR version with `rake appraisal:{version} test_{adapter}'" +
25
- " where version=(#{appraisals.join('|')}) (`touch .disable-appraisal-hint' to disable)"
26
- end
27
- end
28
-
29
20
  Rake::TestTask.class_eval { attr_reader :test_files }
30
21
 
31
22
  def test_task_for(adapter, options = {})
@@ -34,9 +25,6 @@ def test_task_for(adapter, options = {})
34
25
  adapter = adapter.to_s.downcase
35
26
  driver = adapter if ( driver = options[:driver] ).nil?
36
27
  prereqs = options[:prereqs] || []
37
- unless prereqs.frozen?
38
- prereqs = [ prereqs ].flatten; prereqs << 'test_appraisal_hint'
39
- end
40
28
  name = options[:name] || "test_#{adapter}"
41
29
  test_task = Rake::TestTask.new(name => prereqs) do |test_task|
42
30
  files = options[:files] || begin
@@ -11,7 +11,7 @@ begin
11
11
  file jar_file => FileList['src/java/**/*.java', 'pkg/classes'] do
12
12
  rm_rf FileList["#{classes}/**/*"]
13
13
  ant.javac :srcdir => "src/java", :destdir => "pkg/classes",
14
- :source => "1.6", :target => "1.6", :debug => true, :deprecation => true,
14
+ :source => "7", :target => "7", :debug => true, :deprecation => true,
15
15
  :classpath => "${java.class.path}:${sun.boot.class.path}:#{driver_jars.join(':')}",
16
16
  :includeantRuntime => false
17
17
 
@@ -6,6 +6,7 @@ namespace :db do
6
6
  task :mysql do
7
7
  fail "could not create test database: mysql executable not found" unless mysql = which('mysql')
8
8
  load 'test/db/mysql_config.rb' # rescue nil
9
+ puts MYSQL_CONFIG.inspect if $VERBOSE
9
10
  script = sql_script <<-SQL, 'mysql'
10
11
  DROP DATABASE IF EXISTS `#{MYSQL_CONFIG[:database]}`;
11
12
  CREATE USER #{MYSQL_CONFIG[:username]}@localhost;
@@ -15,13 +16,13 @@ GRANT ALL PRIVILEGES ON `test\_%`.* TO #{MYSQL_CONFIG[:username]}@localhost;
15
16
  SET PASSWORD FOR #{MYSQL_CONFIG[:username]}@localhost = PASSWORD('#{MYSQL_CONFIG[:password]}');
16
17
  SQL
17
18
  params = { '-u' => 'root' }
18
- if ENV['DATABASE_YML']
19
- require 'yaml'
20
- password = YAML.load(File.new(ENV['DATABASE_YML']))["production"]["password"]
21
- params['--password'] = password
19
+ if ENV['DATABASE_YML']; require 'yaml'
20
+ params['-p'] = YAML.load(File.new(ENV['DATABASE_YML']))["production"]["password"]
22
21
  end
22
+ params['-u'] = ENV['MY_USER'] if ENV['MY_USER']
23
+ params['-p'] = ENV['MY_PASSWORD'] if ENV['MY_PASSWORD']
23
24
  puts "Creating MySQL (test) database: #{MYSQL_CONFIG[:database]}"
24
- sh "cat #{script.path} | #{mysql} -f #{params.to_a.join(' ')}", :verbose => $VERBOSE # so password is not echoed
25
+ sh "cat #{script.path} | #{mysql} -f #{params.map {|k, v| "#{k}#{v}"}.join(' ')}", :verbose => $VERBOSE # so password is not echoed
25
26
  end
26
27
 
27
28
  desc "Creates the test database for PostgreSQL"
@@ -29,6 +30,7 @@ SQL
29
30
  fail 'could not create test database: psql executable not found' unless psql = which('psql')
30
31
  fail 'could not create test database: missing "postgres" role' unless PostgresHelper.postgres_role?
31
32
  load 'test/db/postgres_config.rb' # rescue nil
33
+ puts POSTGRES_CONFIG.inspect if $VERBOSE
32
34
  script = sql_script <<-SQL, 'psql'
33
35
  DROP DATABASE IF EXISTS #{POSTGRES_CONFIG[:database]};
34
36
  DROP USER IF EXISTS #{POSTGRES_CONFIG[:username]};