activerecord-jdbc-adapter 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/History.txt +33 -0
  2. data/Manifest.txt +17 -0
  3. data/README.txt +48 -20
  4. data/Rakefile +2 -169
  5. data/lib/active_record/connection_adapters/jdbc_adapter.rb +11 -5
  6. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +12 -0
  7. data/lib/jdbc_adapter.rb +1 -1
  8. data/lib/jdbc_adapter/jdbc.rake +43 -30
  9. data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
  10. data/lib/jdbc_adapter/jdbc_db2.rb +2 -2
  11. data/lib/jdbc_adapter/jdbc_derby.rb +11 -0
  12. data/lib/jdbc_adapter/jdbc_hsqldb.rb +6 -1
  13. data/lib/jdbc_adapter/jdbc_mimer.rb +14 -7
  14. data/lib/jdbc_adapter/jdbc_mssql.rb +18 -2
  15. data/lib/jdbc_adapter/jdbc_mysql.rb +3 -0
  16. data/lib/jdbc_adapter/jdbc_oracle.rb +24 -14
  17. data/lib/jdbc_adapter/jdbc_postgre.rb +38 -18
  18. data/lib/jdbc_adapter/jdbc_sqlite3.rb +96 -26
  19. data/lib/jdbc_adapter/missing_functionality_helper.rb +40 -34
  20. data/lib/jdbc_adapter/rake_tasks.rb +1 -1
  21. data/lib/jdbc_adapter/tsql_helper.rb +1 -0
  22. data/lib/jdbc_adapter/version.rb +1 -1
  23. data/lib/pg.rb +4 -0
  24. data/rails_generators/jdbc_generator.rb +15 -0
  25. data/rails_generators/templates/jdbc.rake +8 -0
  26. data/rails_generators/templates/jdbc.rb +7 -0
  27. data/rakelib/compile.rake +23 -0
  28. data/rakelib/package.rake +85 -0
  29. data/rakelib/rails.rake +41 -0
  30. data/rakelib/test.rake +71 -0
  31. data/src/java/jdbc_adapter/JdbcAdapterInternalService.java +1 -0
  32. data/src/java/jdbc_adapter/JdbcDerbySpec.java +11 -46
  33. data/src/java/jdbc_adapter/JdbcMySQLSpec.java +3 -2
  34. data/src/java/jdbc_adapter/MssqlRubyJdbcConnection.java +71 -0
  35. data/src/java/jdbc_adapter/PostgresRubyJdbcConnection.java +24 -4
  36. data/src/java/jdbc_adapter/RubyJdbcConnection.java +57 -44
  37. data/test/abstract_db_create.rb +45 -0
  38. data/test/db/mysql.rb +2 -2
  39. data/test/db/postgres.rb +2 -2
  40. data/test/helper.rb +5 -0
  41. data/test/jdbc_adapter/jdbc_db2_test.rb +5 -0
  42. data/test/jdbc_common.rb +2 -0
  43. data/test/models/entry.rb +3 -0
  44. data/test/models/validates_uniqueness_of_string.rb +19 -0
  45. data/test/mysql_db_create_test.rb +25 -0
  46. data/test/mysql_nonstandard_primary_key_test.rb +42 -0
  47. data/test/mysql_simple_test.rb +5 -0
  48. data/test/postgres_db_create_test.rb +21 -0
  49. data/test/postgres_nonseq_pkey_test.rb +40 -0
  50. data/test/simple.rb +62 -1
  51. data/test/sqlite3_simple_test.rb +153 -10
  52. metadata +26 -5
@@ -102,9 +102,10 @@ public class JdbcMySQLSpec {
102
102
 
103
103
  newBytes.insert(0, BACKQUOTE);
104
104
  newBytes.append(bytes);
105
- int i = 0;
106
- while ((i = newBytes.indexOf('.')) != -1) {
105
+ int i = 0, j = 0;
106
+ while ((i = newBytes.indexOf('.', j)) != -1) {
107
107
  newBytes.replace(i, 1, QUOTED_DOT);
108
+ j = i+3;
108
109
  }
109
110
  newBytes.append(BACKQUOTE);
110
111
 
@@ -0,0 +1,71 @@
1
+ /*
2
+ **** BEGIN LICENSE BLOCK *****
3
+ * Copyright (c) 2006-2009 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>
6
+ *
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:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
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
+ package jdbc_adapter;
27
+
28
+ import java.sql.ResultSet;
29
+ import java.sql.SQLException;
30
+ import java.sql.Types;
31
+ import org.jruby.Ruby;
32
+ import org.jruby.RubyClass;
33
+ import org.jruby.runtime.ObjectAllocator;
34
+ import org.jruby.runtime.builtin.IRubyObject;
35
+
36
+ /**
37
+ *
38
+ * @author nicksieger
39
+ */
40
+ public class MssqlRubyJdbcConnection extends RubyJdbcConnection {
41
+
42
+ protected MssqlRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
43
+ super(runtime, metaClass);
44
+ }
45
+
46
+ public static RubyClass createMssqlJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
47
+ RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("MssqlJdbcConnection",
48
+ jdbcConnection, MSSQL_JDBCCONNECTION_ALLOCATOR);
49
+ clazz.defineAnnotatedMethods(MssqlRubyJdbcConnection.class);
50
+
51
+ return clazz;
52
+ }
53
+ private static ObjectAllocator MSSQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
54
+
55
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
56
+ return new MssqlRubyJdbcConnection(runtime, klass);
57
+ }
58
+ };
59
+
60
+ /**
61
+ * Treat LONGVARCHAR as CLOB on Mssql for purposes of converting a JDBC value to Ruby.
62
+ */
63
+ @Override
64
+ protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
65
+ throws SQLException {
66
+ if (type == Types.LONGVARCHAR) {
67
+ type = Types.CLOB;
68
+ }
69
+ return super.jdbcToRuby(runtime, column, type, resultSet);
70
+ }
71
+ }
@@ -1,8 +1,28 @@
1
1
  /*
2
- * To change this template, choose Tools | Templates
3
- * and open the template in the editor.
4
- */
5
-
2
+ **** BEGIN LICENSE BLOCK *****
3
+ * Copyright (c) 2006-2009 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>
6
+ *
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:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
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 *****/
6
26
  package jdbc_adapter;
7
27
 
8
28
  import org.jruby.Ruby;
@@ -76,7 +76,7 @@ public class RubyJdbcConnection extends RubyObject {
76
76
  private static final String[] TABLE_TYPE = new String[]{"TABLE"};
77
77
 
78
78
  private static RubyObjectAdapter rubyApi;
79
-
79
+
80
80
  protected RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
81
81
  super(runtime, metaClass);
82
82
  }
@@ -103,9 +103,13 @@ public class RubyJdbcConnection extends RubyObject {
103
103
 
104
104
  @JRubyMethod(name = "begin")
105
105
  public IRubyObject begin(ThreadContext context) throws SQLException {
106
- getConnection(true).setAutoCommit(false);
107
-
108
- return context.getRuntime().getNil();
106
+ final Ruby runtime = context.getRuntime();
107
+ return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
108
+ public Object call(Connection c) throws SQLException {
109
+ getConnection(true).setAutoCommit(false);
110
+ return runtime.getNil();
111
+ }
112
+ });
109
113
  }
110
114
 
111
115
  @JRubyMethod(name = {"columns", "columns_internal"}, required = 1, optional = 2)
@@ -126,7 +130,7 @@ public class RubyJdbcConnection extends RubyObject {
126
130
 
127
131
  DatabaseMetaData metadata = c.getMetaData();
128
132
 
129
- if(args.length > 2) schemaName = args[2].toString();
133
+ if(args.length > 2 && schemaName == null) schemaName = toStringOrNull(args[2]);
130
134
 
131
135
  if (schemaName != null) schemaName = caseConvertIdentifierForJdbc(metadata, schemaName);
132
136
  table_name = caseConvertIdentifierForJdbc(metadata, table_name);
@@ -296,7 +300,7 @@ public class RubyJdbcConnection extends RubyObject {
296
300
  DatabaseMetaData metadata = c.getMetaData();
297
301
  String tableName = caseConvertIdentifierForJdbc(metadata, tableNameArg);
298
302
  String schemaName = caseConvertIdentifierForJdbc(metadata, schemaNameArg);
299
-
303
+
300
304
  ResultSet resultSet = null;
301
305
  List indexes = new ArrayList();
302
306
  try {
@@ -383,13 +387,13 @@ public class RubyJdbcConnection extends RubyObject {
383
387
  public IRubyObject native_database_types() {
384
388
  return getInstanceVariable("@native_database_types");
385
389
  }
386
-
390
+
387
391
 
388
392
  @JRubyMethod(name = "primary_keys", required = 1)
389
393
  public IRubyObject primary_keys(ThreadContext context, IRubyObject tableName) throws SQLException {
390
394
  return context.getRuntime().newArray(primaryKeys(context, tableName.toString()));
391
395
  }
392
-
396
+
393
397
  protected List primaryKeys(final ThreadContext context, final String tableNameArg) {
394
398
  return (List) withConnectionAndRetry(context, new SQLBlock() {
395
399
  public Object call(Connection c) throws SQLException {
@@ -419,26 +423,32 @@ public class RubyJdbcConnection extends RubyObject {
419
423
  return setConnection(getConnectionFactory().newConnection());
420
424
  }
421
425
 
426
+
422
427
  @JRubyMethod(name = "rollback")
423
428
  public IRubyObject rollback(ThreadContext context) throws SQLException {
424
- Connection connection = getConnection(true);
429
+ final Ruby runtime = context.getRuntime();
430
+ return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
431
+ public Object call(Connection c) throws SQLException {
432
+ Connection connection = getConnection(true);
425
433
 
426
- if (!connection.getAutoCommit()) {
427
- try {
428
- connection.rollback();
429
- } finally {
430
- connection.setAutoCommit(true);
434
+ if (!connection.getAutoCommit()) {
435
+ try {
436
+ connection.rollback();
437
+ } finally {
438
+ connection.setAutoCommit(true);
439
+ }
431
440
  }
432
- }
433
441
 
434
- return context.getRuntime().getNil();
442
+ return runtime.getNil();
443
+ }
444
+ });
435
445
  }
436
446
 
437
447
  @JRubyMethod(name = "select?", required = 1, meta = true, frame = false)
438
448
  public static IRubyObject select_p(ThreadContext context, IRubyObject recv, IRubyObject _sql) {
439
449
  ByteList sql = rubyApi.convertToRubyString(_sql).getByteList();
440
450
 
441
- return context.getRuntime().newBoolean(startsWithNoCaseCmp(sql, SELECT) ||
451
+ return context.getRuntime().newBoolean(startsWithNoCaseCmp(sql, SELECT) ||
442
452
  startsWithNoCaseCmp(sql, SHOW) || startsWithNoCaseCmp(sql, CALL));
443
453
  }
444
454
 
@@ -453,7 +463,7 @@ public class RubyJdbcConnection extends RubyObject {
453
463
 
454
464
  return runtime.getNil();
455
465
  }
456
-
466
+
457
467
  @JRubyMethod(name = "tables")
458
468
  public IRubyObject tables(ThreadContext context) {
459
469
  return tables(context, null, null, null, TABLE_TYPE);
@@ -561,7 +571,7 @@ public class RubyJdbcConnection extends RubyObject {
561
571
  public static String caseConvertIdentifierForRails(DatabaseMetaData metadata, String value)
562
572
  throws SQLException {
563
573
  if (value == null) return null;
564
-
574
+
565
575
  return metadata.storesUpperCaseIdentifiers() ? value.toLowerCase() : value;
566
576
  }
567
577
 
@@ -570,10 +580,10 @@ public class RubyJdbcConnection extends RubyObject {
570
580
  * storage case. Methods like DatabaseMetaData.getPrimaryKeys() needs the table name to match
571
581
  * the internal storage name. Arbtrary queries and the like DO NOT need to do this.
572
582
  */
573
- public static String caseConvertIdentifierForJdbc(DatabaseMetaData metadata, String value)
583
+ public static String caseConvertIdentifierForJdbc(DatabaseMetaData metadata, String value)
574
584
  throws SQLException {
575
585
  if (value == null) return null;
576
-
586
+
577
587
  if (metadata.storesUpperCaseIdentifiers()) {
578
588
  return value.toUpperCase();
579
589
  } else if (metadata.storesLowerCaseIdentifiers()) {
@@ -618,13 +628,12 @@ public class RubyJdbcConnection extends RubyObject {
618
628
  return arg.isNil() ? null : arg.toString();
619
629
  }
620
630
 
621
- private static IRubyObject floatToRuby(Ruby runtime, ResultSet resultSet, float floatValue)
631
+ protected IRubyObject doubleToRuby(Ruby runtime, ResultSet resultSet, double doubleValue)
622
632
  throws SQLException, IOException {
623
- if (floatValue == 0 && resultSet.wasNull()) return runtime.getNil();
624
-
625
- return runtime.newFloat(floatValue);
633
+ if (doubleValue == 0 && resultSet.wasNull()) return runtime.getNil();
634
+ return runtime.newFloat(doubleValue);
626
635
  }
627
-
636
+
628
637
  protected Connection getConnection() {
629
638
  return getConnection(false);
630
639
  }
@@ -642,7 +651,8 @@ public class RubyJdbcConnection extends RubyObject {
642
651
  IRubyObject connection_factory = getInstanceVariable("@connection_factory");
643
652
  JdbcConnectionFactory factory = null;
644
653
  try {
645
- factory = (JdbcConnectionFactory) ((JavaObject) rubyApi.getInstanceVariable(connection_factory, "@java_object")).getValue();
654
+ factory = (JdbcConnectionFactory) JavaEmbedUtils.rubyToJava(
655
+ connection_factory.getRuntime(), connection_factory, JdbcConnectionFactory.class);
646
656
  } catch (Exception e) {
647
657
  factory = null;
648
658
  }
@@ -713,23 +723,26 @@ public class RubyJdbcConnection extends RubyObject {
713
723
  } else {
714
724
  return !c.isClosed();
715
725
  }
716
- } catch (SQLException sx) {
726
+ } catch (Exception sx) {
717
727
  return true;
718
728
  }
719
729
  }
720
730
 
721
- private static IRubyObject integerToRuby(Ruby runtime, ResultSet resultSet, long longValue)
731
+ protected IRubyObject integerToRuby(Ruby runtime, ResultSet resultSet, long longValue)
722
732
  throws SQLException, IOException {
723
733
  if (longValue == 0 && resultSet.wasNull()) return runtime.getNil();
724
734
 
725
735
  return runtime.newFixnum(longValue);
726
736
  }
727
737
 
728
- private static IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
738
+ protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
729
739
  throws SQLException {
730
740
  try {
731
741
  switch (type) {
732
- case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY:
742
+ case Types.BINARY:
743
+ case Types.BLOB:
744
+ case Types.LONGVARBINARY:
745
+ case Types.VARBINARY:
733
746
  case Types.LONGVARCHAR:
734
747
  return streamToRuby(runtime, resultSet, resultSet.getBinaryStream(column));
735
748
  case Types.CLOB:
@@ -739,7 +752,7 @@ public class RubyJdbcConnection extends RubyObject {
739
752
  case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT:
740
753
  return integerToRuby(runtime, resultSet, resultSet.getLong(column));
741
754
  case Types.REAL:
742
- return floatToRuby(runtime, resultSet, resultSet.getFloat(column));
755
+ return doubleToRuby(runtime, resultSet, resultSet.getDouble(column));
743
756
  default:
744
757
  return stringToRuby(runtime, resultSet, resultSet.getString(column));
745
758
  }
@@ -748,7 +761,7 @@ public class RubyJdbcConnection extends RubyObject {
748
761
  }
749
762
  }
750
763
 
751
- private static void populateFromResultSet(ThreadContext context, Ruby runtime, List results,
764
+ protected void populateFromResultSet(ThreadContext context, Ruby runtime, List results,
752
765
  ResultSet resultSet, ColumnData[] columns) throws SQLException {
753
766
  int columnCount = columns.length;
754
767
 
@@ -763,7 +776,7 @@ public class RubyJdbcConnection extends RubyObject {
763
776
  }
764
777
 
765
778
 
766
- private static IRubyObject readerToRuby(Ruby runtime, ResultSet resultSet, Reader reader)
779
+ protected IRubyObject readerToRuby(Ruby runtime, ResultSet resultSet, Reader reader)
767
780
  throws SQLException, IOException {
768
781
  if (reader == null && resultSet.wasNull()) return runtime.getNil();
769
782
 
@@ -850,7 +863,7 @@ public class RubyJdbcConnection extends RubyObject {
850
863
  }
851
864
  }
852
865
 
853
- private static IRubyObject streamToRuby(Ruby runtime, ResultSet resultSet, InputStream is)
866
+ protected IRubyObject streamToRuby(Ruby runtime, ResultSet resultSet, InputStream is)
854
867
  throws SQLException, IOException {
855
868
  if (is == null && resultSet.wasNull()) return runtime.getNil();
856
869
 
@@ -868,7 +881,7 @@ public class RubyJdbcConnection extends RubyObject {
868
881
  return runtime.newString(str);
869
882
  }
870
883
 
871
- private static IRubyObject stringToRuby(Ruby runtime, ResultSet resultSet, String string)
884
+ protected IRubyObject stringToRuby(Ruby runtime, ResultSet resultSet, String string)
872
885
  throws SQLException, IOException {
873
886
  if (string == null && resultSet.wasNull()) return runtime.getNil();
874
887
 
@@ -890,7 +903,7 @@ public class RubyJdbcConnection extends RubyObject {
890
903
 
891
904
  String realschema = schemapat;
892
905
  String realtablepat = tablepat;
893
-
906
+
894
907
  if (realtablepat != null) realtablepat = caseConvertIdentifierForJdbc(metadata, realtablepat);
895
908
  if (realschema != null) realschema = caseConvertIdentifierForJdbc(metadata, realschema);
896
909
 
@@ -898,7 +911,7 @@ public class RubyJdbcConnection extends RubyObject {
898
911
  List arr = new ArrayList();
899
912
  while (rs.next()) {
900
913
  String name;
901
-
914
+
902
915
  if (downCase) {
903
916
  name = rs.getString(TABLE_NAME).toLowerCase();
904
917
  } else {
@@ -917,7 +930,7 @@ public class RubyJdbcConnection extends RubyObject {
917
930
  };
918
931
  }
919
932
 
920
- private static IRubyObject timestampToRuby(Ruby runtime, ResultSet resultSet, Timestamp time)
933
+ protected IRubyObject timestampToRuby(Ruby runtime, ResultSet resultSet, Timestamp time)
921
934
  throws SQLException, IOException {
922
935
  if (time == null && resultSet.wasNull()) return runtime.getNil();
923
936
 
@@ -959,14 +972,14 @@ public class RubyJdbcConnection extends RubyObject {
959
972
  // valid precision 1 decimal also. Seems sketchy to me...
960
973
  if (numberAsBoolean && precision != 1 &&
961
974
  resultSet.getInt(DATA_TYPE) == java.sql.Types.DECIMAL) precision = -1;
962
-
975
+
963
976
  String type = resultSet.getString(TYPE_NAME);
964
977
  if (precision > 0) {
965
978
  type += "(" + precision;
966
979
  if(scale > 0) type += "," + scale;
967
980
  type += ")";
968
981
  }
969
-
982
+
970
983
  return type;
971
984
  }
972
985
 
@@ -992,7 +1005,7 @@ public class RubyJdbcConnection extends RubyObject {
992
1005
  IRubyObject column = jdbcCol.callMethod(context, "new",
993
1006
  new IRubyObject[] {
994
1007
  getInstanceVariable("@config"),
995
- RubyString.newUnicodeString(runtime,
1008
+ RubyString.newUnicodeString(runtime,
996
1009
  caseConvertIdentifierForRails(metadata, rs.getString(COLUMN_NAME))),
997
1010
  defaultValueFromResultSet(runtime, rs),
998
1011
  RubyString.newUnicodeString(runtime, typeFromResultSet(rs, isOracle)),
@@ -1031,7 +1044,7 @@ public class RubyJdbcConnection extends RubyObject {
1031
1044
  *
1032
1045
  * @param downCase should column names only be in lower case?
1033
1046
  */
1034
- protected static IRubyObject unmarshalResult(ThreadContext context, DatabaseMetaData metadata,
1047
+ protected IRubyObject unmarshalResult(ThreadContext context, DatabaseMetaData metadata,
1035
1048
  ResultSet resultSet, boolean downCase) throws SQLException {
1036
1049
  Ruby runtime = context.getRuntime();
1037
1050
  List results = new ArrayList();
@@ -1099,7 +1112,7 @@ public class RubyJdbcConnection extends RubyObject {
1099
1112
 
1100
1113
  return end;
1101
1114
  }
1102
-
1115
+
1103
1116
  private static byte[] CALL = new byte[]{'c', 'a', 'l', 'l'};
1104
1117
  private static byte[] INSERT = new byte[] {'i', 'n', 's', 'e', 'r', 't'};
1105
1118
  private static byte[] SELECT = new byte[] {'s', 'e', 'l', 'e', 'c', 't'};
@@ -0,0 +1,45 @@
1
+ require 'jdbc_common'
2
+ require 'rake'
3
+
4
+ module AbstractDbCreate
5
+ def setup
6
+ @prevapp = Rake.application
7
+ Rake.application = Rake::Application.new
8
+ verbose(true)
9
+ @prevenv = Object.const_get("RAILS_ENV") rescue nil
10
+ @prevroot = Object.const_get("RAILS_ENV") rescue nil
11
+ Object.const_set("RAILS_ENV", "unittest")
12
+ Object.const_set("RAILS_ROOT", ".")
13
+ @prevconfigs = ActiveRecord::Base.configurations
14
+ ActiveRecord::Base.connection.disconnect!
15
+ @db_name = 'test_rake_db_create'
16
+ require 'initializer'
17
+ the_db_name = @db_name
18
+ the_db_config = db_config
19
+ Rails::Configuration.class_eval do
20
+ define_method(:database_configuration) do
21
+ { "unittest" => the_db_config.merge({:database => the_db_name}).stringify_keys! }
22
+ end
23
+ end
24
+ load rails_databases_rake_file
25
+ load File.dirname(__FILE__) + '/../lib/jdbc_adapter/jdbc.rake' if jruby?
26
+ task :environment; task :rails_env # dummy environment, rails_env tasks
27
+ end
28
+
29
+ def teardown
30
+ Rake::Task["db:drop"].invoke
31
+ Rake.application = @prevapp
32
+ Object.const_set("RAILS_ENV", @prevenv) if @prevenv
33
+ Object.const_set("RAILS_ROOT", @prevroot) if @prevroot
34
+ ActiveRecord::Base.configurations = @prevconfigs
35
+ ActiveRecord::Base.establish_connection(db_config)
36
+ end
37
+
38
+ def rails_databases_rake_file
39
+ ar_version = $LOADED_FEATURES.grep(%r{active_record/version}).first
40
+ ar_lib_path = $LOAD_PATH.detect {|p| p if File.exist?File.join(p, ar_version)}
41
+ ar_lib_path = ar_lib_path.sub(%r{activerecord/lib}, 'railties/lib') # edge rails
42
+ rails_lib_path = ar_lib_path.sub(/activerecord/, 'rails') # gem rails
43
+ "#{rails_lib_path}/tasks/databases.rake"
44
+ end
45
+ end