activerecord-jdbc-adapter 1.2.5 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +5 -1
  3. data/Appraisals +5 -5
  4. data/Gemfile +9 -1
  5. data/Gemfile.lock +44 -10
  6. data/History.txt +126 -2
  7. data/README.md +246 -0
  8. data/Rakefile +34 -25
  9. data/activerecord-jdbc-adapter.gemspec +1 -1
  10. data/gemfiles/rails23.gemfile +5 -3
  11. data/gemfiles/rails23.gemfile.lock +26 -18
  12. data/gemfiles/rails30.gemfile +4 -2
  13. data/gemfiles/rails30.gemfile.lock +16 -8
  14. data/gemfiles/rails31.gemfile +4 -2
  15. data/gemfiles/rails31.gemfile.lock +16 -9
  16. data/gemfiles/rails32.gemfile +4 -2
  17. data/gemfiles/rails32.gemfile.lock +15 -8
  18. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  19. data/lib/arel/visitors/sql_server.rb +3 -0
  20. data/lib/arjdbc.rb +3 -5
  21. data/lib/arjdbc/db2.rb +1 -0
  22. data/lib/arjdbc/db2/adapter.rb +302 -196
  23. data/lib/arjdbc/db2/connection_methods.rb +18 -0
  24. data/lib/arjdbc/derby/active_record_patch.rb +12 -0
  25. data/lib/arjdbc/derby/adapter.rb +180 -158
  26. data/lib/arjdbc/derby/connection_methods.rb +5 -1
  27. data/lib/arjdbc/firebird/adapter.rb +27 -19
  28. data/lib/arjdbc/h2/adapter.rb +162 -7
  29. data/lib/arjdbc/h2/connection_methods.rb +5 -1
  30. data/lib/arjdbc/hsqldb.rb +1 -1
  31. data/lib/arjdbc/hsqldb/adapter.rb +96 -61
  32. data/lib/arjdbc/hsqldb/connection_methods.rb +5 -1
  33. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  34. data/lib/arjdbc/informix/adapter.rb +56 -55
  35. data/lib/arjdbc/jdbc/adapter.rb +173 -86
  36. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  37. data/lib/arjdbc/jdbc/column.rb +28 -23
  38. data/lib/arjdbc/jdbc/connection.rb +10 -6
  39. data/lib/arjdbc/jdbc/driver.rb +13 -5
  40. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +21 -0
  41. data/lib/arjdbc/mssql.rb +1 -1
  42. data/lib/arjdbc/mssql/adapter.rb +51 -53
  43. data/lib/arjdbc/mssql/connection_methods.rb +8 -1
  44. data/lib/arjdbc/mysql.rb +1 -1
  45. data/lib/arjdbc/mysql/adapter.rb +186 -150
  46. data/lib/arjdbc/mysql/connection_methods.rb +9 -9
  47. data/lib/arjdbc/mysql/explain_support.rb +85 -0
  48. data/lib/arjdbc/oracle.rb +1 -1
  49. data/lib/arjdbc/oracle/adapter.rb +232 -125
  50. data/lib/arjdbc/oracle/connection_methods.rb +2 -2
  51. data/lib/arjdbc/postgresql.rb +1 -1
  52. data/lib/arjdbc/postgresql/adapter.rb +134 -86
  53. data/lib/arjdbc/postgresql/connection_methods.rb +6 -4
  54. data/lib/arjdbc/postgresql/explain_support.rb +55 -0
  55. data/lib/arjdbc/sqlite3.rb +1 -1
  56. data/lib/arjdbc/sqlite3/adapter.rb +176 -108
  57. data/lib/arjdbc/sqlite3/connection_methods.rb +5 -5
  58. data/lib/arjdbc/sqlite3/explain_support.rb +32 -0
  59. data/lib/arjdbc/sybase/adapter.rb +7 -6
  60. data/lib/arjdbc/version.rb +1 -1
  61. data/pom.xml +1 -1
  62. data/rakelib/02-test.rake +9 -11
  63. data/rakelib/rails.rake +18 -10
  64. data/src/java/arjdbc/db2/DB2Module.java +70 -0
  65. data/src/java/arjdbc/derby/DerbyModule.java +24 -5
  66. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +66 -0
  67. data/src/java/arjdbc/jdbc/AdapterJavaService.java +14 -7
  68. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +111 -89
  69. data/src/java/arjdbc/mysql/MySQLModule.java +79 -70
  70. data/src/java/arjdbc/oracle/OracleModule.java +74 -0
  71. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +5 -10
  72. data/src/java/arjdbc/sqlite3/SQLite3Module.java +77 -0
  73. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +127 -0
  74. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +25 -111
  75. data/src/java/arjdbc/util/QuotingUtils.java +104 -0
  76. data/test/abstract_db_create.rb +6 -6
  77. data/test/activerecord/connection_adapters/type_conversion_test.rb +2 -2
  78. data/test/assets/flowers.jpg +0 -0
  79. data/test/binary.rb +67 -0
  80. data/test/db/db2.rb +30 -7
  81. data/test/db/jdbc.rb +4 -2
  82. data/test/db/oracle.rb +18 -27
  83. data/test/db2_binary_test.rb +6 -0
  84. data/test/db2_serialize_test.rb +6 -0
  85. data/test/db2_simple_test.rb +20 -25
  86. data/test/db2_test.rb +71 -0
  87. data/test/derby_binary_test.rb +6 -0
  88. data/test/derby_migration_test.rb +42 -35
  89. data/test/derby_reset_column_information_test.rb +1 -0
  90. data/test/derby_row_locking_test.rb +17 -0
  91. data/test/derby_schema_dump_test.rb +9 -0
  92. data/test/derby_serialize_test.rb +6 -0
  93. data/test/derby_simple_test.rb +59 -17
  94. data/test/generic_jdbc_connection_test.rb +112 -5
  95. data/test/h2_binary_test.rb +6 -0
  96. data/test/h2_change_column_test.rb +1 -1
  97. data/test/h2_schema_dump_test.rb +25 -0
  98. data/test/h2_serialize_test.rb +6 -0
  99. data/test/h2_simple_test.rb +23 -9
  100. data/test/has_many_through.rb +18 -4
  101. data/test/hsqldb_binary_test.rb +6 -0
  102. data/test/hsqldb_schema_dump_test.rb +15 -0
  103. data/test/hsqldb_serialize_test.rb +6 -0
  104. data/test/hsqldb_simple_test.rb +1 -0
  105. data/test/informix_simple_test.rb +1 -1
  106. data/test/jdbc/db2.rb +23 -0
  107. data/test/jdbc/oracle.rb +23 -0
  108. data/test/jdbc_common.rb +3 -110
  109. data/test/jndi_callbacks_test.rb +0 -2
  110. data/test/jndi_test.rb +2 -0
  111. data/test/models/binary.rb +18 -0
  112. data/test/models/custom_pk_name.rb +1 -0
  113. data/test/models/data_types.rb +11 -2
  114. data/test/models/entry.rb +1 -1
  115. data/test/models/string_id.rb +2 -2
  116. data/test/models/thing.rb +1 -1
  117. data/test/models/topic.rb +32 -0
  118. data/test/mssql_legacy_types_test.rb +1 -1
  119. data/test/mssql_limit_offset_test.rb +13 -3
  120. data/test/mssql_serialize_test.rb +6 -0
  121. data/test/mysql_binary_test.rb +6 -0
  122. data/test/mysql_schema_dump_test.rb +220 -0
  123. data/test/mysql_serialize_test.rb +6 -0
  124. data/test/mysql_simple_test.rb +22 -2
  125. data/test/mysql_test.rb +93 -0
  126. data/test/oracle_binary_test.rb +6 -0
  127. data/test/oracle_limit_test.rb +2 -1
  128. data/test/oracle_serialize_test.rb +6 -0
  129. data/test/oracle_simple_test.rb +61 -0
  130. data/test/oracle_specific_test.rb +77 -26
  131. data/test/postgres_binary_test.rb +6 -0
  132. data/test/postgres_native_type_mapping_test.rb +12 -11
  133. data/test/postgres_nonseq_pkey_test.rb +1 -0
  134. data/test/postgres_reserved_test.rb +1 -0
  135. data/test/postgres_reset_column_information_test.rb +1 -0
  136. data/test/postgres_row_locking_test.rb +21 -0
  137. data/test/postgres_schema_dump_test.rb +88 -0
  138. data/test/postgres_schema_search_path_test.rb +1 -0
  139. data/test/postgres_simple_test.rb +62 -89
  140. data/test/postgres_table_alias_length_test.rb +1 -0
  141. data/test/postgres_test.rb +31 -0
  142. data/test/postgres_type_conversion_test.rb +16 -16
  143. data/test/row_locking.rb +69 -64
  144. data/test/schema_dump.rb +168 -0
  145. data/test/serialize.rb +277 -0
  146. data/test/simple.rb +326 -122
  147. data/test/sqlite3_serialize_test.rb +6 -0
  148. data/test/sqlite3_simple_test.rb +51 -84
  149. data/test/sqlite3_type_conversion_test.rb +101 -0
  150. data/test/test_helper.rb +224 -0
  151. metadata +325 -366
  152. data/README.rdoc +0 -214
  153. data/test/db/logger.rb +0 -3
  154. data/test/derby_multibyte_test.rb +0 -11
  155. data/test/mysql_info_test.rb +0 -123
@@ -1,126 +1,40 @@
1
1
  /*
2
- **** BEGIN LICENSE BLOCK *****
3
- * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
4
- * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
5
- * Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
2
+ * The MIT License
6
3
  *
7
- * Permission is hereby granted, free of charge, to any person obtaining
8
- * a copy of this software and associated documentation files (the
9
- * "Software"), to deal in the Software without restriction, including
10
- * without limitation the rights to use, copy, modify, merge, publish,
11
- * distribute, sublicense, and/or sell copies of the Software, and to
12
- * permit persons to whom the Software is furnished to do so, subject to
13
- * the following conditions:
4
+ * Copyright 2013 Karol Bucek.
14
5
  *
15
- * The above copyright notice and this permission notice shall be
16
- * included in all copies or substantial portions of the Software.
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
17
12
  *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
- ***** END LICENSE BLOCK *****/
26
-
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
27
24
  package arjdbc.sqlite3;
28
25
 
29
- import java.io.ByteArrayInputStream;
30
- import java.io.IOException;
31
- import java.sql.Connection;
32
- import java.sql.ResultSet;
33
- import java.sql.ResultSetMetaData;
34
- import java.sql.SQLException;
35
- import java.sql.Statement;
36
- import java.sql.Types;
37
-
38
- import arjdbc.jdbc.RubyJdbcConnection;
39
- import arjdbc.jdbc.SQLBlock;
40
-
41
26
  import org.jruby.Ruby;
42
27
  import org.jruby.RubyClass;
43
- import org.jruby.anno.JRubyMethod;
44
- import org.jruby.runtime.ObjectAllocator;
45
- import org.jruby.runtime.ThreadContext;
46
- import org.jruby.runtime.builtin.IRubyObject;
47
28
 
48
29
  /**
49
- *
50
- * @author enebo
30
+ * @see SQLite3RubyJdbcConnection
31
+ * @deprecated only for Java API backwards-compatibility
51
32
  */
52
- public class Sqlite3RubyJdbcConnection extends RubyJdbcConnection {
33
+ @Deprecated
34
+ public class Sqlite3RubyJdbcConnection extends SQLite3RubyJdbcConnection {
35
+
53
36
  protected Sqlite3RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
54
37
  super(runtime, metaClass);
55
38
  }
56
-
57
- public static RubyClass createSqlite3JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
58
- RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("Sqlite3JdbcConnection",
59
- jdbcConnection, SQLITE3_JDBCCONNECTION_ALLOCATOR);
60
- clazz.defineAnnotatedMethods(Sqlite3RubyJdbcConnection.class);
61
-
62
- return clazz;
63
- }
64
-
65
- private static ObjectAllocator SQLITE3_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
66
- public IRubyObject allocate(Ruby runtime, RubyClass klass) {
67
- return new Sqlite3RubyJdbcConnection(runtime, klass);
68
- }
69
- };
70
-
71
- @JRubyMethod(name = "last_insert_row_id")
72
- public IRubyObject getLastInsertRowId(final ThreadContext context)
73
- throws SQLException {
74
- return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
75
- public Object call(Connection c) throws SQLException {
76
- Statement stmt = null;
77
- try {
78
- stmt = c.createStatement();
79
- return unmarshal_id_result(context.getRuntime(),
80
- stmt.getGeneratedKeys());
81
- } catch (SQLException sqe) {
82
- if (context.getRuntime().isDebug()) {
83
- System.out.println("Error SQL:" + sqe.getMessage());
84
- }
85
- throw sqe;
86
- } finally {
87
- close(stmt);
88
- }
89
- }
90
- });
91
- }
92
-
93
- @Override
94
- protected IRubyObject tables(ThreadContext context, String catalog, String schemaPattern, String tablePattern, String[] types) {
95
- return (IRubyObject) withConnectionAndRetry(context, tableLookupBlock(context.getRuntime(), catalog, schemaPattern, tablePattern, types, true));
96
- }
97
-
98
- @Override
99
- protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
100
- throws SQLException {
101
- try {
102
- // This is rather gross, and only needed because the resultset metadata for SQLite tries to be overly
103
- // clever, and returns a type for the column of the "current" row, so an integer value stored in a
104
- // decimal column is returned as Types.INTEGER. Therefore, if the first row of a resultset was an
105
- // integer value, all rows of that result set would get truncated.
106
- if( resultSet instanceof ResultSetMetaData ) {
107
- type = ((ResultSetMetaData)resultSet).getColumnType(column);
108
- }
109
- switch (type) {
110
- case Types.BINARY:
111
- case Types.BLOB:
112
- case Types.LONGVARBINARY:
113
- case Types.VARBINARY:
114
- return streamToRuby(runtime, resultSet, new ByteArrayInputStream(resultSet.getBytes(column)));
115
- case Types.LONGVARCHAR:
116
- return runtime.is1_9() ?
117
- readerToRuby(runtime, resultSet, resultSet.getCharacterStream(column)) :
118
- streamToRuby(runtime, resultSet, new ByteArrayInputStream(resultSet.getBytes(column)));
119
- default:
120
- return super.jdbcToRuby(runtime, column, type, resultSet);
121
- }
122
- } catch (IOException ioe) {
123
- throw (SQLException) new SQLException(ioe.getMessage()).initCause(ioe);
124
- }
125
- }
39
+
126
40
  }
@@ -0,0 +1,104 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright 2013 Karol Bucek.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+ package arjdbc.util;
25
+
26
+ import org.jruby.Ruby;
27
+ import org.jruby.RubyString;
28
+ import org.jruby.runtime.ThreadContext;
29
+ import org.jruby.runtime.builtin.IRubyObject;
30
+ import org.jruby.util.ByteList;
31
+
32
+ /**
33
+ * Shared (common) quoting helpers.
34
+ *
35
+ * <br>
36
+ * NOTE: This is internal API !
37
+ * <br>
38
+ *
39
+ * @author kares
40
+ */
41
+ public abstract class QuotingUtils {
42
+
43
+ public static final ByteList BYTES_0 = new ByteList(new byte[] { '0' }, false);
44
+
45
+ public static final ByteList BYTES_1 = new ByteList(new byte[] { '1' }, false);
46
+
47
+ // e.g. string.gsub("'", "''") -> quoteCharWith(string, '\'', '\'');
48
+ public static RubyString quoteCharWith(
49
+ final ThreadContext context,
50
+ final RubyString string,
51
+ final char value, final char quote) {
52
+
53
+ final ByteList stringBytes = string.getByteList();
54
+ final byte[] bytes = stringBytes.bytes; // unsafeBytes();
55
+ final int begin = stringBytes.begin; // getBegin();
56
+ final int realSize = stringBytes.realSize; // getRealSize();
57
+
58
+ ByteList quotedBytes = null; int appendFrom = begin;
59
+ for ( int i = begin; i < begin + realSize; i++ ) {
60
+ if ( bytes[i] == value ) {
61
+ if ( quotedBytes == null ) {
62
+ quotedBytes = new ByteList(
63
+ new byte[realSize + 8],
64
+ stringBytes.encoding // getEncoding()
65
+ );
66
+ quotedBytes.begin = 0; // setBegin(0);
67
+ quotedBytes.realSize = 0; // setRealSize(0);
68
+ }
69
+ quotedBytes.append(bytes, appendFrom, i - appendFrom);
70
+ quotedBytes.append(quote).append(value); // e.g. "'" => "''"
71
+ appendFrom = i + 1;
72
+ }
73
+ }
74
+ if ( quotedBytes != null ) { // append what's left in the end :
75
+ quotedBytes.append(bytes, appendFrom, begin + realSize - appendFrom);
76
+ }
77
+ else return string; // nothing changed, can return original
78
+
79
+ final Ruby runtime = context.getRuntime();
80
+ return runtime.newString(quotedBytes);
81
+ }
82
+
83
+ static final ByteList SINGLE_Q = new ByteList(new byte[] { '\'' }, false);
84
+ static final ByteList QUOTED_SINGLE_Q = new ByteList(new byte[] { '\'', '\'' }, false);
85
+
86
+ // string.gsub("'", "''") :
87
+ public static IRubyObject quoteSingleQuotesWithFallback(
88
+ final ThreadContext context, final IRubyObject string) {
89
+ // string.gsub("'", "''") :
90
+ if ( string instanceof RubyString ) {
91
+ final char single = '\'';
92
+ return quoteCharWith(context, (RubyString) string, single, single);
93
+ }
94
+ else { // ActiveSupport::Multibyte::Chars
95
+ return string.callMethod(context, "gsub",
96
+ new IRubyObject[] {
97
+ context.getRuntime().newString(SINGLE_Q),
98
+ context.getRuntime().newString(QUOTED_SINGLE_Q)
99
+ }
100
+ );
101
+ }
102
+ }
103
+
104
+ }
@@ -37,7 +37,7 @@ module AbstractDbCreate
37
37
  setup_rails
38
38
  set_rails_constant("env", @env)
39
39
  set_rails_constant("root", ".")
40
- load File.dirname(__FILE__) + '/../lib/arjdbc/jdbc/jdbc.rake' if jruby?
40
+ load File.dirname(__FILE__) + '/../lib/arjdbc/jdbc/jdbc.rake' if defined?(JRUBY_VERSION)
41
41
  task :environment do
42
42
  ActiveRecord::Base.configurations = configurations
43
43
  @full_env_loaded = true
@@ -66,11 +66,11 @@ module AbstractDbCreate
66
66
  end
67
67
 
68
68
  def configurations
69
- the_db_name = @db_name
70
- the_db_config = db_config
71
- the_db_config = the_db_config.merge({:database => the_db_name}) if the_db_name
72
- the_db_config.stringify_keys!
73
- @configs = { @env => the_db_config }
69
+ db_name = @db_name
70
+ db_config = self.db_config
71
+ db_config = db_config.merge({:database => db_name}) if db_name
72
+ db_config.stringify_keys!
73
+ @configs = { @env => db_config }
74
74
  @configs["test"] = @configs[@env].dup
75
75
  @configs
76
76
  end
@@ -19,12 +19,12 @@ class TypeConversionTest < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_timestamp
22
- types = DbType.find(:first)
22
+ types = DbType.first
23
23
  assert_equal TEST_TIME, types.sample_timestamp.getutc
24
24
  end
25
25
 
26
26
  def test_decimal
27
- types = DbType.find(:first)
27
+ types = DbType.first
28
28
  assert_equal((JInteger::MAX_VALUE + 1), types.sample_decimal)
29
29
  end
30
30
  end
Binary file
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'models/binary'
4
+
5
+ # Kindly borrowed from Rails's AR test cases !
6
+
7
+ # Without using prepared statements, it makes no sense to test
8
+ # BLOB data with DB2 or Firebird, because the length of a statement
9
+ # is limited to 32KB.
10
+ #unless current_adapter?(:SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
11
+
12
+ module BinaryTestMethods
13
+
14
+ def self.included(base)
15
+ base.extend UpAndDown
16
+ end
17
+
18
+ module UpAndDown
19
+
20
+ def startup
21
+ super
22
+ BinaryMigration.up
23
+ end
24
+
25
+ def shutdown
26
+ super
27
+ BinaryMigration.down
28
+ end
29
+
30
+ end
31
+
32
+ FIXTURES = %w(flowers.jpg example.log test.txt)
33
+
34
+ def test_mixed_encoding
35
+ str = "\x80"
36
+ str.force_encoding('ASCII-8BIT') if str.respond_to?(:force_encoding)
37
+
38
+ binary = Binary.new :name => 'いただきます!', :data => str
39
+ binary.save!
40
+ binary.reload
41
+ assert_equal str, binary.data
42
+
43
+ name = binary.name
44
+
45
+ assert_equal 'いただきます!', name
46
+ end
47
+
48
+ def test_load_save
49
+ Binary.delete_all
50
+ assets_root = File.expand_path('assets', File.dirname(__FILE__))
51
+ FIXTURES.each do |filename|
52
+ data = File.read("#{assets_root}/#{filename}")
53
+ data.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding)
54
+ data.freeze
55
+
56
+ bin = Binary.new(:data => data)
57
+ assert_equal data, bin.data, 'Newly assigned data differs from original'
58
+
59
+ bin.save!
60
+ assert_equal data, bin.data, 'Data differs from original after save'
61
+
62
+ assert_equal data, bin.reload.data, 'Reloaded data differs from original'
63
+ end
64
+ end
65
+ end
66
+
67
+ #end
@@ -1,13 +1,36 @@
1
1
  require 'jdbc_common'
2
2
 
3
- config = {
3
+ config = { :adapter => "db2" }
4
+
5
+ config[:host] = ENV['DB2HOST'] if ENV['DB2HOST']
6
+ config[:port] = ENV['DB2PORT'] if ENV['DB2PORT']
4
7
  # DB2 uses $USER if running locally, just add
5
8
  # yourself to your db2 groups in /etc/group
6
- # :username => "blog",
7
- # :password => "",
8
- :adapter => "jdbc",
9
- :driver => "com.ibm.db2.jcc.DB2Driver",
10
- :url => "jdbc:db2:weblog_development"
11
- }
9
+ config[:username] = ENV['DB2USER'] if ENV['DB2USER'] # db2inst1
10
+ config[:password] = ENV['DB2PASS'] if ENV['DB2PASS']
11
+
12
+ # DB2 does not like "_" in database names :
13
+ # SQL0104N An unexpected token "weblog_development" was found
14
+ # create the sample database using `db2sampl` command
15
+ database = ENV['DB2DATABASE'] || 'SAMPLE'
16
+ if config[:host]
17
+ config[:database] = database
18
+ else
19
+ config[:url] = "jdbc:db2:#{database}" # local instance
20
+ end
21
+
22
+ require 'jdbc/db2'
23
+ # Download IBM DB2 JCC driver from :
24
+ # https://www-304.ibm.com/support/docview.wss?rs=4020&uid=swg21385217
25
+ begin
26
+ Java::JavaClass.for_name(Jdbc::DB2.driver_name)
27
+ rescue NameError
28
+ begin
29
+ Jdbc::DB2.load_driver
30
+ rescue LoadError => e
31
+ puts "Please setup a JDBC driver to run the DB2 tests !"
32
+ raise e
33
+ end
34
+ end
12
35
 
13
36
  ActiveRecord::Base.establish_connection(config)
@@ -4,10 +4,12 @@ require 'db/mysql_config'
4
4
  require 'jdbc/mysql' # driver not loaded for plain JDBC
5
5
  Jdbc::MySQL.load_driver
6
6
 
7
- ActiveRecord::Base.establish_connection({
7
+ JDBC_CONFIG = {
8
8
  :adapter => 'jdbc',
9
9
  :driver => 'com.mysql.jdbc.Driver',
10
10
  :url => "jdbc:mysql://#{MYSQL_CONFIG[:host]}/#{MYSQL_CONFIG[:database]}",
11
11
  :username => MYSQL_CONFIG[:username],
12
12
  :password => MYSQL_CONFIG[:password],
13
- })
13
+ }
14
+
15
+ ActiveRecord::Base.establish_connection(JDBC_CONFIG)
@@ -1,36 +1,27 @@
1
1
  require 'jdbc_common'
2
2
 
3
3
  config = {
4
- :username => 'blog',
5
- :password => 'blog',
6
4
  :adapter => 'oracle',
5
+ :username => ENV["ORACLE_USER"] || 'blog',
6
+ :password => ENV["ORACLE_PASS"] || 'blog',
7
7
  :host => ENV["ORACLE_HOST"] || 'localhost',
8
- :database => ENV["ORACLE_SID"] || 'XE' # XE is the default SID for oracle xe
8
+ :database => ENV["ORACLE_SID"] || 'XE'
9
9
  }
10
10
 
11
11
  ActiveRecord::Base.establish_connection(config)
12
12
 
13
- # Here are some notes of things I had to do to get running on Oracle
14
- # XE.
15
- #
16
- # ON Linux:
17
- # create tablespace weblog_development
18
- # datafile '/usr/lib/oracle/xe/oradata/XE/weblog_development.dbf';
19
- # ON Windows XP:
20
- # create tablespace weblog_development
21
- # datafile 'C:\ORACLEXE\ORADATA\XE\WEBLOGD.DBF' size 16m;
22
- #
23
- # create user blog identified by blog
24
- # default tablespace weblog_development;
25
- # grant all privileges to blog;
26
- #
27
- # You might need to up the number of processes and restart the
28
- # listener. (In my case, I had to reboot.) See
29
- # http://it.newinstance.it/2007/06/01/ora-12519-tnsno-appropriate-service-handler-found/
30
- #
31
- # alter system set PROCESSES=150 scope=SPFILE;
32
- #
33
- # These might be helpful too (numbers are rather arbitrary...)
34
- #
35
- # alter system set TRANSACTIONS=126 scope=SPFILE;
36
- # alter system set SESSIONS=115 scope=SPFILE;
13
+ require 'jdbc/oracle'
14
+ # Download JDBC driverfrom :
15
+ # http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
16
+ begin
17
+ Java::JavaClass.for_name(Jdbc::Oracle.driver_name)
18
+ rescue NameError
19
+ begin
20
+ Jdbc::Oracle.load_driver
21
+ rescue LoadError => e
22
+ puts "Please setup a JDBC driver to run the Oracle tests !"
23
+ raise e
24
+ end
25
+ end
26
+
27
+ ActiveRecord::Base.establish_connection(config)