activerecord-jdbc-adapter 0.9.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/History.txt +163 -0
  2. data/Manifest.txt +130 -65
  3. data/README.txt +64 -72
  4. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
  5. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
  6. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
  7. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
  8. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -633
  9. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
  10. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  11. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  12. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
  13. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
  14. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
  15. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
  16. data/lib/activerecord-jdbc-adapter.rb +6 -0
  17. data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
  18. data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
  19. data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
  20. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
  21. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
  22. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
  23. data/lib/arel/visitors/db2.rb +15 -0
  24. data/lib/arel/visitors/derby.rb +19 -0
  25. data/lib/arel/visitors/hsqldb.rb +24 -0
  26. data/lib/arel/visitors/mssql.rb +44 -0
  27. data/lib/arjdbc.rb +29 -0
  28. data/lib/arjdbc/db2.rb +2 -0
  29. data/lib/arjdbc/db2/adapter.rb +413 -0
  30. data/lib/arjdbc/derby.rb +7 -0
  31. data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +58 -132
  32. data/lib/arjdbc/derby/connection_methods.rb +18 -0
  33. data/lib/arjdbc/discover.rb +92 -0
  34. data/lib/arjdbc/firebird.rb +2 -0
  35. data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +36 -14
  36. data/lib/arjdbc/h2.rb +4 -0
  37. data/lib/arjdbc/h2/adapter.rb +36 -0
  38. data/lib/arjdbc/h2/connection_methods.rb +12 -0
  39. data/lib/arjdbc/hsqldb.rb +4 -0
  40. data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +34 -62
  41. data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
  42. data/lib/arjdbc/informix.rb +3 -0
  43. data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +10 -19
  44. data/lib/arjdbc/informix/connection_methods.rb +10 -0
  45. data/lib/arjdbc/jdbc.rb +2 -0
  46. data/lib/arjdbc/jdbc/adapter.rb +285 -0
  47. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  48. data/lib/arjdbc/jdbc/callbacks.rb +44 -0
  49. data/lib/arjdbc/jdbc/column.rb +38 -0
  50. data/lib/arjdbc/jdbc/compatibility.rb +51 -0
  51. data/lib/arjdbc/jdbc/connection.rb +128 -0
  52. data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
  53. data/lib/arjdbc/jdbc/core_ext.rb +24 -0
  54. data/lib/arjdbc/jdbc/discover.rb +18 -0
  55. data/lib/arjdbc/jdbc/driver.rb +44 -0
  56. data/lib/arjdbc/jdbc/extension.rb +47 -0
  57. data/lib/arjdbc/jdbc/java.rb +14 -0
  58. data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +36 -26
  59. data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
  60. data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
  61. data/lib/arjdbc/jdbc/railtie.rb +9 -0
  62. data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
  63. data/lib/arjdbc/jdbc/require_driver.rb +16 -0
  64. data/lib/arjdbc/jdbc/type_converter.rb +126 -0
  65. data/lib/arjdbc/mimer.rb +2 -0
  66. data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +17 -16
  67. data/lib/arjdbc/mssql.rb +4 -0
  68. data/lib/arjdbc/mssql/adapter.rb +472 -0
  69. data/lib/arjdbc/mssql/connection_methods.rb +30 -0
  70. data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
  71. data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +2 -1
  72. data/lib/arjdbc/mysql.rb +4 -0
  73. data/lib/arjdbc/mysql/adapter.rb +416 -0
  74. data/lib/arjdbc/mysql/connection_methods.rb +27 -0
  75. data/lib/arjdbc/oracle.rb +3 -0
  76. data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +68 -33
  77. data/lib/arjdbc/oracle/connection_methods.rb +11 -0
  78. data/lib/arjdbc/postgresql.rb +4 -0
  79. data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +147 -72
  80. data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
  81. data/lib/arjdbc/sqlite3.rb +4 -0
  82. data/lib/arjdbc/sqlite3/adapter.rb +381 -0
  83. data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
  84. data/lib/arjdbc/sybase.rb +2 -0
  85. data/lib/arjdbc/sybase/adapter.rb +46 -0
  86. data/lib/arjdbc/version.rb +8 -0
  87. data/lib/generators/jdbc/jdbc_generator.rb +9 -0
  88. data/lib/jdbc_adapter.rb +2 -27
  89. data/lib/jdbc_adapter/rake_tasks.rb +3 -10
  90. data/lib/jdbc_adapter/version.rb +3 -5
  91. data/lib/pg.rb +23 -1
  92. data/rails_generators/jdbc_generator.rb +2 -2
  93. data/rails_generators/templates/{jdbc.rb → config/initializers/jdbc.rb} +1 -1
  94. data/rails_generators/templates/{jdbc.rake → lib/tasks/jdbc.rake} +2 -2
  95. data/rakelib/compile.rake +5 -3
  96. data/rakelib/db.rake +19 -0
  97. data/rakelib/package.rake +12 -6
  98. data/rakelib/test.rake +24 -14
  99. data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +63 -34
  100. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
  101. data/src/java/{jdbc_adapter/MssqlRubyJdbcConnection.java → arjdbc/informix/InformixRubyJdbcConnection.java} +15 -12
  102. data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +21 -8
  103. data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
  104. data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +210 -67
  105. data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
  106. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
  107. data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
  108. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
  109. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
  110. data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
  111. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
  112. data/test/abstract_db_create.rb +98 -19
  113. data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
  114. data/test/db/db2.rb +4 -2
  115. data/test/db/derby.rb +12 -14
  116. data/test/db/hsqldb.rb +3 -2
  117. data/test/db/jndi_config.rb +22 -12
  118. data/test/db/mssql.rb +5 -5
  119. data/test/db/sqlite3.rb +2 -6
  120. data/test/db2_simple_test.rb +56 -0
  121. data/test/derby_migration_test.rb +50 -3
  122. data/test/derby_simple_test.rb +87 -0
  123. data/test/generic_jdbc_connection_test.rb +21 -1
  124. data/test/h2_simple_test.rb +35 -0
  125. data/test/jdbc_common.rb +4 -5
  126. data/test/jndi_callbacks_test.rb +3 -1
  127. data/test/jndi_test.rb +1 -11
  128. data/test/models/entry.rb +20 -0
  129. data/test/models/mixed_case.rb +7 -2
  130. data/test/models/string_id.rb +18 -0
  131. data/test/mssql_db_create_test.rb +26 -0
  132. data/test/mssql_identity_insert_test.rb +19 -0
  133. data/test/mssql_legacy_types_test.rb +58 -0
  134. data/test/mssql_limit_offset_test.rb +136 -0
  135. data/test/mssql_multibyte_test.rb +18 -0
  136. data/test/mssql_simple_test.rb +49 -0
  137. data/test/mysql_db_create_test.rb +8 -6
  138. data/test/mysql_info_test.rb +123 -0
  139. data/test/mysql_simple_test.rb +19 -1
  140. data/test/oracle_simple_test.rb +9 -20
  141. data/test/oracle_specific_test.rb +83 -0
  142. data/test/pick_rails_version.rb +3 -0
  143. data/test/postgres_db_create_test.rb +11 -0
  144. data/test/postgres_drop_db_test.rb +16 -0
  145. data/test/postgres_mixed_case_test.rb +11 -1
  146. data/test/postgres_nonseq_pkey_test.rb +0 -2
  147. data/test/postgres_schema_search_path_test.rb +44 -0
  148. data/test/postgres_simple_test.rb +53 -0
  149. data/test/postgres_table_alias_length_test.rb +15 -0
  150. data/test/simple.rb +103 -9
  151. data/test/sqlite3_simple_test.rb +1 -0
  152. data/test/sybase_jtds_simple_test.rb +22 -0
  153. metadata +239 -137
  154. data/lib/active_record/connection_adapters/cachedb_adapter.rb +0 -1
  155. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
  156. data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
  157. data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
  158. data/lib/jdbc_adapter/jdbc_db2.rb +0 -191
  159. data/lib/jdbc_adapter/jdbc_mssql.rb +0 -333
  160. data/lib/jdbc_adapter/jdbc_mysql.rb +0 -236
  161. data/lib/jdbc_adapter/jdbc_sqlite3.rb +0 -379
  162. data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
  163. data/src/java/jdbc_adapter/SQLBlock.java +0 -27
  164. data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
  165. data/test/cachedb_simple_test.rb +0 -6
  166. data/test/db/cachedb.rb +0 -9
  167. data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
  168. data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
  169. data/test/minirunit.rb +0 -109
  170. data/test/minirunit/testConnect.rb +0 -14
  171. data/test/minirunit/testH2.rb +0 -73
  172. data/test/minirunit/testHsqldb.rb +0 -73
  173. data/test/minirunit/testLoadActiveRecord.rb +0 -3
  174. data/test/minirunit/testMysql.rb +0 -83
  175. data/test/minirunit/testRawSelect.rb +0 -24
@@ -0,0 +1,48 @@
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>
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
+
27
+ package arjdbc.jdbc;
28
+
29
+ import java.sql.Connection;
30
+ import java.sql.ResultSet;
31
+ import java.sql.SQLException;
32
+ import java.sql.Statement;
33
+
34
+ /**
35
+ *
36
+ * @author nicksieger
37
+ */
38
+ public abstract class SQLBlock {
39
+ abstract Object call(Connection c) throws SQLException;
40
+
41
+ public void close(Statement statement) {
42
+ RubyJdbcConnection.close(statement);
43
+ }
44
+
45
+ public void close(ResultSet resultSet) {
46
+ RubyJdbcConnection.close(resultSet);
47
+ }
48
+ }
@@ -0,0 +1,127 @@
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>
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 arjdbc.mssql;
27
+
28
+ import java.sql.ResultSet;
29
+ import java.sql.SQLException;
30
+ import java.sql.Types;
31
+ import java.util.List;
32
+
33
+ import arjdbc.jdbc.RubyJdbcConnection;
34
+ import static arjdbc.jdbc.RubyJdbcConnection.ColumnData;
35
+
36
+ import org.jruby.Ruby;
37
+ import org.jruby.RubyClass;
38
+ import org.jruby.RubyString;
39
+ import org.jruby.runtime.ObjectAllocator;
40
+ import org.jruby.runtime.ThreadContext;
41
+ import org.jruby.runtime.builtin.IRubyObject;
42
+
43
+ /**
44
+ *
45
+ * @author nicksieger
46
+ */
47
+ public class MssqlRubyJdbcConnection extends RubyJdbcConnection {
48
+
49
+ private RubyString _row_num;
50
+
51
+ protected MssqlRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
52
+ super(runtime, metaClass);
53
+ _row_num = runtime.newString("_row_num");
54
+ }
55
+
56
+ public static RubyClass createMssqlJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
57
+ RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("MssqlJdbcConnection",
58
+ jdbcConnection, MSSQL_JDBCCONNECTION_ALLOCATOR);
59
+ clazz.defineAnnotatedMethods(MssqlRubyJdbcConnection.class);
60
+
61
+ return clazz;
62
+ }
63
+
64
+ private static ObjectAllocator MSSQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
65
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
66
+ return new MssqlRubyJdbcConnection(runtime, klass);
67
+ }
68
+ };
69
+
70
+ protected static IRubyObject booleanToRuby(Ruby runtime, ResultSet resultSet, boolean booleanValue)
71
+ throws SQLException {
72
+ if (booleanValue == false && resultSet.wasNull()) return runtime.getNil();
73
+ return runtime.newBoolean(booleanValue);
74
+ }
75
+
76
+ /**
77
+ * Treat LONGVARCHAR as CLOB on Mssql for purposes of converting a JDBC value to Ruby.
78
+ * Treat BOOLEAN/BIT as Boolean, rather than the default behaviour of conversion to string
79
+ */
80
+ @Override
81
+ protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
82
+ throws SQLException {
83
+ if ( Types.BOOLEAN == type || Types.BIT == type ) {
84
+ return booleanToRuby(runtime, resultSet, resultSet.getBoolean(column));
85
+ }
86
+ if (type == Types.LONGVARCHAR) {
87
+ type = Types.CLOB;
88
+ }
89
+ return super.jdbcToRuby(runtime, column, type, resultSet);
90
+ }
91
+
92
+ /**
93
+ * Microsoft SQL 2000+ support schemas
94
+ */
95
+ @Override
96
+ protected boolean databaseSupportsSchemas() {
97
+ return true;
98
+ }
99
+
100
+ @Override
101
+ protected void populateFromResultSet(ThreadContext context, Ruby runtime, List results,
102
+ ResultSet resultSet, ColumnData[] columns) throws SQLException {
103
+ super.populateFromResultSet(context, runtime, results, resultSet, filterRowNumFromColumns(columns));
104
+ }
105
+
106
+ /**
107
+ * Filter out the <tt>_row_num</tt> column from results.
108
+ */
109
+ private ColumnData[] filterRowNumFromColumns(ColumnData[] columns) {
110
+ for (int i = 0; i < columns.length; i++) {
111
+ if (columns[i].name.equals(_row_num)) {
112
+ ColumnData[] filtered = new ColumnData[columns.length - 1];
113
+ if (i > 0) {
114
+ System.arraycopy(columns, 0, filtered, 0, i);
115
+ }
116
+
117
+ if (i + 1 < columns.length) {
118
+ System.arraycopy(columns, i + 1, filtered, i, columns.length - (i + 1));
119
+ }
120
+
121
+ return filtered;
122
+ }
123
+ }
124
+
125
+ return columns;
126
+ }
127
+ }
@@ -1,7 +1,7 @@
1
1
  /***** BEGIN LICENSE BLOCK *****
2
- * Copyright (c) 2006-2009 Nick Sieger <nick@nicksieger.com>
2
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
3
3
  * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
4
- *
4
+ *
5
5
  * Permission is hereby granted, free of charge, to any person obtaining
6
6
  * a copy of this software and associated documentation files (the
7
7
  * "Software"), to deal in the Software without restriction, including
@@ -9,10 +9,10 @@
9
9
  * distribute, sublicense, and/or sell copies of the Software, and to
10
10
  * permit persons to whom the Software is furnished to do so, subject to
11
11
  * the following conditions:
12
- *
12
+ *
13
13
  * The above copyright notice and this permission notice shall be
14
14
  * included in all copies or substantial portions of the Software.
15
- *
15
+ *
16
16
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
17
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
18
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,7 +22,7 @@
22
22
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  ***** END LICENSE BLOCK *****/
24
24
 
25
- package jdbc_adapter;
25
+ package arjdbc.mysql;
26
26
 
27
27
  import java.sql.Connection;
28
28
 
@@ -35,10 +35,10 @@ import org.jruby.runtime.builtin.IRubyObject;
35
35
 
36
36
  import org.jruby.util.ByteList;
37
37
 
38
- public class JdbcMySQLSpec {
39
- public static void load(RubyModule jdbcSpec) {
40
- RubyModule mysql = jdbcSpec.defineModuleUnder("MySQL");
41
- mysql.defineAnnotatedMethods(JdbcMySQLSpec.class);
38
+ public class MySQLModule {
39
+ public static void load(RubyModule arJdbc) {
40
+ RubyModule mysql = arJdbc.defineModuleUnder("MySQL");
41
+ mysql.defineAnnotatedMethods(MySQLModule.class);
42
42
  }
43
43
 
44
44
  private final static byte BACKQUOTE = '`';
@@ -56,9 +56,9 @@ public class JdbcMySQLSpec {
56
56
  public static IRubyObject quote_string(ThreadContext context, IRubyObject recv, IRubyObject string) {
57
57
  ByteList bytes = ((RubyString) string).getByteList();
58
58
  ByteList newBytes = new ByteList();
59
-
59
+
60
60
  newBytes.append(bytes);
61
-
61
+
62
62
  for(int i = newBytes.begin; i < newBytes.begin + newBytes.realSize; i++) {
63
63
  byte[] rep = null;
64
64
  switch (newBytes.bytes[i]) {
@@ -94,7 +94,7 @@ public class JdbcMySQLSpec {
94
94
 
95
95
  return context.getRuntime().newString(newBytes);
96
96
  }
97
-
97
+
98
98
  @JRubyMethod(name = "quote_table_name", frame=false)
99
99
  public static IRubyObject quote_table_name(ThreadContext context, IRubyObject recv, IRubyObject arg) {
100
100
  ByteList bytes = arg.asString().getByteList();
@@ -0,0 +1,87 @@
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>
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 arjdbc.mysql;
27
+
28
+ import java.sql.Connection;
29
+ import java.sql.SQLException;
30
+ import java.sql.ResultSet;
31
+ import java.sql.Statement;
32
+ import java.sql.Types;
33
+
34
+ import org.jruby.Ruby;
35
+ import org.jruby.RubyClass;
36
+ import org.jruby.runtime.ObjectAllocator;
37
+ import org.jruby.runtime.ThreadContext;
38
+ import org.jruby.runtime.builtin.IRubyObject;
39
+
40
+ import arjdbc.jdbc.RubyJdbcConnection;
41
+
42
+ /**
43
+ *
44
+ * @author nicksieger
45
+ */
46
+ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
47
+ protected MySQLRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
48
+ super(runtime, metaClass);
49
+ }
50
+
51
+ @Override
52
+ protected boolean genericExecute(Statement stmt, String query) throws SQLException {
53
+ return stmt.execute(query, Statement.RETURN_GENERATED_KEYS);
54
+ }
55
+
56
+ @Override
57
+ protected IRubyObject unmarshalKeysOrUpdateCount(ThreadContext context, Connection c, Statement stmt) throws SQLException {
58
+ IRubyObject key = unmarshal_id_result(context.getRuntime(), stmt.getGeneratedKeys());
59
+ if (key.isNil()) {
60
+ return context.getRuntime().newFixnum(stmt.getUpdateCount());
61
+ }
62
+ return key;
63
+ }
64
+
65
+ @Override
66
+ protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
67
+ throws SQLException {
68
+ if (Types.BOOLEAN == type || Types.BIT == type) {
69
+ return integerToRuby(runtime, resultSet, resultSet.getBoolean(column) ? 1 : 0);
70
+ }
71
+ return super.jdbcToRuby(runtime, column, type, resultSet);
72
+ }
73
+
74
+ public static RubyClass createMySQLJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
75
+ RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("MySQLJdbcConnection",
76
+ jdbcConnection, MYSQL_JDBCCONNECTION_ALLOCATOR);
77
+ clazz.defineAnnotatedMethods(MySQLRubyJdbcConnection.class);
78
+
79
+ return clazz;
80
+ }
81
+
82
+ private static ObjectAllocator MYSQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
83
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
84
+ return new MySQLRubyJdbcConnection(runtime, klass);
85
+ }
86
+ };
87
+ }
@@ -0,0 +1,85 @@
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>
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 arjdbc.oracle;
27
+
28
+ import java.sql.ResultSet;
29
+ import java.sql.SQLException;
30
+
31
+ import arjdbc.jdbc.RubyJdbcConnection;
32
+
33
+ import org.jruby.Ruby;
34
+ import org.jruby.RubyClass;
35
+ import org.jruby.runtime.ObjectAllocator;
36
+ import org.jruby.runtime.builtin.IRubyObject;
37
+
38
+ /**
39
+ *
40
+ * @author nicksieger
41
+ */
42
+ public class OracleRubyJdbcConnection extends RubyJdbcConnection {
43
+ protected OracleRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
44
+ super(runtime, metaClass);
45
+ }
46
+
47
+ public static RubyClass createOracleJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
48
+ RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("OracleJdbcConnection",
49
+ jdbcConnection, ORACLE_JDBCCONNECTION_ALLOCATOR);
50
+ clazz.defineAnnotatedMethods(OracleRubyJdbcConnection.class);
51
+
52
+ return clazz;
53
+ }
54
+
55
+ private static ObjectAllocator ORACLE_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
56
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
57
+ return new OracleRubyJdbcConnection(runtime, klass);
58
+ }
59
+ };
60
+
61
+ /**
62
+ * Oracle needs this override to reconstruct NUMBER which is different
63
+ * from NUMBER(x) or NUMBER(x,y).
64
+ */
65
+ @Override
66
+ protected String typeFromResultSet(ResultSet resultSet) throws SQLException {
67
+ int precision = intFromResultSet(resultSet, COLUMN_SIZE);
68
+ int scale = intFromResultSet(resultSet, DECIMAL_DIGITS);
69
+
70
+ // According to http://forums.oracle.com/forums/thread.jspa?threadID=658646
71
+ // Unadorned NUMBER reports scale == null, so we look for that here.
72
+ if (scale < 0 && resultSet.getInt(DATA_TYPE) == java.sql.Types.DECIMAL) {
73
+ precision = -1;
74
+ }
75
+
76
+ String type = resultSet.getString(TYPE_NAME);
77
+ if (precision > 0) {
78
+ type += "(" + precision;
79
+ if(scale > 0) type += "," + scale;
80
+ type += ")";
81
+ }
82
+
83
+ return type;
84
+ }
85
+ }
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  **** BEGIN LICENSE BLOCK *****
3
- * Copyright (c) 2006-2009 Nick Sieger <nick@nicksieger.com>
3
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
4
4
  * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
5
5
  * Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
6
6
  *
@@ -23,7 +23,9 @@
23
23
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
24
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
  ***** END LICENSE BLOCK *****/
26
- package jdbc_adapter;
26
+ package arjdbc.postgresql;
27
+
28
+ import arjdbc.jdbc.RubyJdbcConnection;
27
29
 
28
30
  import org.jruby.Ruby;
29
31
  import org.jruby.RubyClass;
@@ -34,22 +36,22 @@ import org.jruby.runtime.builtin.IRubyObject;
34
36
  *
35
37
  * @author enebo
36
38
  */
37
- public class PostgresRubyJdbcConnection extends RubyJdbcConnection {
38
- protected PostgresRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
39
+ public class PostgresqlRubyJdbcConnection extends RubyJdbcConnection {
40
+ protected PostgresqlRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
39
41
  super(runtime, metaClass);
40
42
  }
41
43
 
42
- public static RubyClass createPostgresJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
44
+ public static RubyClass createPostgresqlJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
43
45
  RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("PostgresJdbcConnection",
44
- jdbcConnection, POSTGRES_JDBCCONNECTION_ALLOCATOR);
45
- clazz.defineAnnotatedMethods(PostgresRubyJdbcConnection.class);
46
+ jdbcConnection, POSTGRESQL_JDBCCONNECTION_ALLOCATOR);
47
+ clazz.defineAnnotatedMethods(PostgresqlRubyJdbcConnection.class);
46
48
 
47
49
  return clazz;
48
50
  }
49
51
 
50
- private static ObjectAllocator POSTGRES_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
52
+ private static ObjectAllocator POSTGRESQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
51
53
  public IRubyObject allocate(Ruby runtime, RubyClass klass) {
52
- return new PostgresRubyJdbcConnection(runtime, klass);
54
+ return new PostgresqlRubyJdbcConnection(runtime, klass);
53
55
  }
54
56
  };
55
57
  }