intentmedia-activerecord-jdbc-adapter 1.1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/History.txt +404 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.txt +181 -0
  4. data/Rakefile +10 -0
  5. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
  6. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
  7. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
  8. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
  9. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
  10. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
  11. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  12. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  13. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
  14. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
  15. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
  16. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
  17. data/lib/activerecord-jdbc-adapter.rb +8 -0
  18. data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
  19. data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
  20. data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
  21. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
  22. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
  23. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
  24. data/lib/arel/visitors/compat.rb +13 -0
  25. data/lib/arel/visitors/db2.rb +17 -0
  26. data/lib/arel/visitors/derby.rb +21 -0
  27. data/lib/arel/visitors/hsqldb.rb +26 -0
  28. data/lib/arel/visitors/sql_server.rb +46 -0
  29. data/lib/arjdbc.rb +29 -0
  30. data/lib/arjdbc/db2.rb +2 -0
  31. data/lib/arjdbc/db2/adapter.rb +413 -0
  32. data/lib/arjdbc/derby.rb +7 -0
  33. data/lib/arjdbc/derby/adapter.rb +348 -0
  34. data/lib/arjdbc/derby/connection_methods.rb +18 -0
  35. data/lib/arjdbc/discover.rb +92 -0
  36. data/lib/arjdbc/firebird.rb +2 -0
  37. data/lib/arjdbc/firebird/adapter.rb +131 -0
  38. data/lib/arjdbc/h2.rb +4 -0
  39. data/lib/arjdbc/h2/adapter.rb +36 -0
  40. data/lib/arjdbc/h2/connection_methods.rb +12 -0
  41. data/lib/arjdbc/hsqldb.rb +4 -0
  42. data/lib/arjdbc/hsqldb/adapter.rb +184 -0
  43. data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
  44. data/lib/arjdbc/informix.rb +3 -0
  45. data/lib/arjdbc/informix/adapter.rb +138 -0
  46. data/lib/arjdbc/informix/connection_methods.rb +10 -0
  47. data/lib/arjdbc/jdbc.rb +2 -0
  48. data/lib/arjdbc/jdbc/adapter.rb +285 -0
  49. data/lib/arjdbc/jdbc/callbacks.rb +44 -0
  50. data/lib/arjdbc/jdbc/column.rb +38 -0
  51. data/lib/arjdbc/jdbc/compatibility.rb +51 -0
  52. data/lib/arjdbc/jdbc/connection.rb +128 -0
  53. data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
  54. data/lib/arjdbc/jdbc/core_ext.rb +24 -0
  55. data/lib/arjdbc/jdbc/discover.rb +18 -0
  56. data/lib/arjdbc/jdbc/driver.rb +44 -0
  57. data/lib/arjdbc/jdbc/extension.rb +47 -0
  58. data/lib/arjdbc/jdbc/java.rb +14 -0
  59. data/lib/arjdbc/jdbc/jdbc.rake +127 -0
  60. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +87 -0
  61. data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
  62. data/lib/arjdbc/jdbc/railtie.rb +9 -0
  63. data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
  64. data/lib/arjdbc/jdbc/require_driver.rb +16 -0
  65. data/lib/arjdbc/jdbc/type_converter.rb +127 -0
  66. data/lib/arjdbc/mimer.rb +2 -0
  67. data/lib/arjdbc/mimer/adapter.rb +142 -0
  68. data/lib/arjdbc/mssql.rb +4 -0
  69. data/lib/arjdbc/mssql/adapter.rb +472 -0
  70. data/lib/arjdbc/mssql/connection_methods.rb +30 -0
  71. data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
  72. data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
  73. data/lib/arjdbc/mysql.rb +4 -0
  74. data/lib/arjdbc/mysql/adapter.rb +416 -0
  75. data/lib/arjdbc/mysql/connection_methods.rb +27 -0
  76. data/lib/arjdbc/oracle.rb +3 -0
  77. data/lib/arjdbc/oracle/adapter.rb +412 -0
  78. data/lib/arjdbc/oracle/connection_methods.rb +11 -0
  79. data/lib/arjdbc/postgresql.rb +4 -0
  80. data/lib/arjdbc/postgresql/adapter.rb +579 -0
  81. data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
  82. data/lib/arjdbc/sqlite3.rb +4 -0
  83. data/lib/arjdbc/sqlite3/adapter.rb +381 -0
  84. data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
  85. data/lib/arjdbc/sybase.rb +2 -0
  86. data/lib/arjdbc/sybase/adapter.rb +46 -0
  87. data/lib/arjdbc/version.rb +8 -0
  88. data/lib/generators/jdbc/jdbc_generator.rb +9 -0
  89. data/lib/jdbc_adapter.rb +2 -0
  90. data/lib/jdbc_adapter/rake_tasks.rb +3 -0
  91. data/lib/jdbc_adapter/version.rb +3 -0
  92. data/lib/pg.rb +26 -0
  93. data/rails_generators/jdbc_generator.rb +15 -0
  94. data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
  95. data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
  96. data/rakelib/compile.rake +25 -0
  97. data/rakelib/db.rake +19 -0
  98. data/rakelib/package.rake +91 -0
  99. data/rakelib/rails.rake +41 -0
  100. data/rakelib/test.rake +81 -0
  101. data/src/java/arjdbc/derby/DerbyModule.java +322 -0
  102. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
  103. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
  104. data/src/java/arjdbc/jdbc/AdapterJavaService.java +66 -0
  105. data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
  106. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1305 -0
  107. data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
  108. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
  109. data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
  110. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
  111. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
  112. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +57 -0
  113. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
  114. data/test/abstract_db_create.rb +124 -0
  115. data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
  116. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
  117. data/test/db/db2.rb +11 -0
  118. data/test/db/derby.rb +12 -0
  119. data/test/db/h2.rb +11 -0
  120. data/test/db/hsqldb.rb +13 -0
  121. data/test/db/informix.rb +11 -0
  122. data/test/db/jdbc.rb +11 -0
  123. data/test/db/jndi_config.rb +40 -0
  124. data/test/db/logger.rb +3 -0
  125. data/test/db/mssql.rb +9 -0
  126. data/test/db/mysql.rb +10 -0
  127. data/test/db/oracle.rb +34 -0
  128. data/test/db/postgres.rb +9 -0
  129. data/test/db/sqlite3.rb +11 -0
  130. data/test/db2_simple_test.rb +66 -0
  131. data/test/derby_migration_test.rb +68 -0
  132. data/test/derby_multibyte_test.rb +12 -0
  133. data/test/derby_simple_test.rb +99 -0
  134. data/test/generic_jdbc_connection_test.rb +29 -0
  135. data/test/h2_simple_test.rb +41 -0
  136. data/test/has_many_through.rb +79 -0
  137. data/test/helper.rb +5 -0
  138. data/test/hsqldb_simple_test.rb +6 -0
  139. data/test/informix_simple_test.rb +48 -0
  140. data/test/jdbc_common.rb +25 -0
  141. data/test/jndi_callbacks_test.rb +40 -0
  142. data/test/jndi_test.rb +25 -0
  143. data/test/manualTestDatabase.rb +191 -0
  144. data/test/models/add_not_null_column_to_table.rb +12 -0
  145. data/test/models/auto_id.rb +18 -0
  146. data/test/models/data_types.rb +28 -0
  147. data/test/models/entry.rb +43 -0
  148. data/test/models/mixed_case.rb +25 -0
  149. data/test/models/reserved_word.rb +18 -0
  150. data/test/models/string_id.rb +18 -0
  151. data/test/models/validates_uniqueness_of_string.rb +19 -0
  152. data/test/mssql_db_create_test.rb +26 -0
  153. data/test/mssql_identity_insert_test.rb +19 -0
  154. data/test/mssql_legacy_types_test.rb +58 -0
  155. data/test/mssql_limit_offset_test.rb +136 -0
  156. data/test/mssql_multibyte_test.rb +18 -0
  157. data/test/mssql_simple_test.rb +55 -0
  158. data/test/mysql_db_create_test.rb +27 -0
  159. data/test/mysql_info_test.rb +123 -0
  160. data/test/mysql_multibyte_test.rb +10 -0
  161. data/test/mysql_nonstandard_primary_key_test.rb +42 -0
  162. data/test/mysql_simple_test.rb +49 -0
  163. data/test/oracle_simple_test.rb +18 -0
  164. data/test/oracle_specific_test.rb +83 -0
  165. data/test/pick_rails_version.rb +3 -0
  166. data/test/postgres_db_create_test.rb +32 -0
  167. data/test/postgres_drop_db_test.rb +16 -0
  168. data/test/postgres_mixed_case_test.rb +29 -0
  169. data/test/postgres_nonseq_pkey_test.rb +38 -0
  170. data/test/postgres_reserved_test.rb +22 -0
  171. data/test/postgres_schema_search_path_test.rb +44 -0
  172. data/test/postgres_simple_test.rb +65 -0
  173. data/test/postgres_table_alias_length_test.rb +15 -0
  174. data/test/simple.rb +546 -0
  175. data/test/sqlite3_simple_test.rb +233 -0
  176. data/test/sybase_jtds_simple_test.rb +28 -0
  177. metadata +259 -0
@@ -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
+ }
@@ -0,0 +1,134 @@
1
+ /***** BEGIN LICENSE BLOCK *****
2
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
3
+ * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ ***** END LICENSE BLOCK *****/
24
+
25
+ package arjdbc.mysql;
26
+
27
+ import java.sql.Connection;
28
+
29
+ import org.jruby.RubyModule;
30
+ import org.jruby.RubyString;
31
+
32
+ import org.jruby.anno.JRubyMethod;
33
+ import org.jruby.runtime.ThreadContext;
34
+ import org.jruby.runtime.builtin.IRubyObject;
35
+
36
+ import org.jruby.util.ByteList;
37
+
38
+ public class MySQLModule {
39
+ public static void load(RubyModule arJdbc) {
40
+ RubyModule mysql = arJdbc.defineModuleUnder("MySQL");
41
+ mysql.defineAnnotatedMethods(MySQLModule.class);
42
+ }
43
+
44
+ private final static byte BACKQUOTE = '`';
45
+ private final static byte[] QUOTED_DOT = new byte[] {'`', '.', '`'};
46
+
47
+ private final static byte[] ZERO = new byte[] {'\\','0'};
48
+ private final static byte[] NEWLINE = new byte[] {'\\','n'};
49
+ private final static byte[] CARRIAGE = new byte[] {'\\','r'};
50
+ private final static byte[] ZED = new byte[] {'\\','Z'};
51
+ private final static byte[] DBL = new byte[] {'\\','"'};
52
+ private final static byte[] SINGLE = new byte[] {'\\','\''};
53
+ private final static byte[] ESCAPE = new byte[] {'\\','\\'};
54
+
55
+ @JRubyMethod(name = "quote_string", required = 1, frame=false)
56
+ public static IRubyObject quote_string(ThreadContext context, IRubyObject recv, IRubyObject string) {
57
+ ByteList bytes = ((RubyString) string).getByteList();
58
+ ByteList newBytes = new ByteList();
59
+
60
+ newBytes.append(bytes);
61
+
62
+ for(int i = newBytes.begin; i < newBytes.begin + newBytes.realSize; i++) {
63
+ byte[] rep = null;
64
+ switch (newBytes.bytes[i]) {
65
+ case 0: rep = ZERO; break;
66
+ case '\n': rep = NEWLINE; break;
67
+ case '\r': rep = CARRIAGE; break;
68
+ case 26: rep = ZED; break;
69
+ case '"': rep = DBL; break;
70
+ case '\'': rep = SINGLE; break;
71
+ case '\\': rep = ESCAPE; break;
72
+ }
73
+
74
+ if (rep != null) {
75
+ newBytes.replace(i, 1, rep);
76
+ i += rep.length - 1; // We subtract one since for loop already adds one
77
+ }
78
+ }
79
+
80
+ // Nothing changed, can return original
81
+ if (newBytes.length() == bytes.length()) return string;
82
+
83
+ return context.getRuntime().newString(newBytes);
84
+ }
85
+
86
+ @JRubyMethod(name = "quote_column_name", frame=false)
87
+ public static IRubyObject quote_column_name(ThreadContext context, IRubyObject recv, IRubyObject arg) {
88
+ ByteList bytes = arg.asString().getByteList();
89
+ ByteList newBytes = new ByteList();
90
+
91
+ newBytes.insert(0, BACKQUOTE);
92
+ newBytes.append(bytes);
93
+ newBytes.append(BACKQUOTE);
94
+
95
+ return context.getRuntime().newString(newBytes);
96
+ }
97
+
98
+ @JRubyMethod(name = "quote_table_name", frame=false)
99
+ public static IRubyObject quote_table_name(ThreadContext context, IRubyObject recv, IRubyObject arg) {
100
+ ByteList bytes = arg.asString().getByteList();
101
+ ByteList newBytes = new ByteList();
102
+
103
+ newBytes.insert(0, BACKQUOTE);
104
+ newBytes.append(bytes);
105
+ int i = 0, j = 0;
106
+ while ((i = newBytes.indexOf('.', j)) != -1) {
107
+ newBytes.replace(i, 1, QUOTED_DOT);
108
+ j = i+3;
109
+ }
110
+ newBytes.append(BACKQUOTE);
111
+
112
+ return context.getRuntime().newString(newBytes);
113
+ }
114
+
115
+ /**
116
+ * HACK HACK HACK See http://bugs.mysql.com/bug.php?id=36565
117
+ * MySQL's statement cancel timer can cause memory leaks, so cancel it
118
+ * if we loaded MySQL classes from the same classloader as JRuby
119
+ */
120
+ @JRubyMethod(module = true, frame = false)
121
+ public static IRubyObject kill_cancel_timer(ThreadContext context, IRubyObject recv, IRubyObject raw_connection) {
122
+ Connection conn = (Connection) raw_connection.dataGetStruct();
123
+ if (conn != null && conn.getClass().getClassLoader() == recv.getRuntime().getJRubyClassLoader()) {
124
+ try {
125
+ java.lang.reflect.Field f = conn.getClass().getDeclaredField("cancelTimer");
126
+ f.setAccessible(true);
127
+ java.util.Timer timer = (java.util.Timer) f.get(null);
128
+ timer.cancel();
129
+ } catch (Exception e) {
130
+ }
131
+ }
132
+ return recv.getRuntime().getNil();
133
+ }
134
+ }
@@ -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
+ }