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.
- data/History.txt +163 -0
- data/Manifest.txt +130 -65
- data/README.txt +64 -72
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -633
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
- data/lib/activerecord-jdbc-adapter.rb +6 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/db2.rb +15 -0
- data/lib/arel/visitors/derby.rb +19 -0
- data/lib/arel/visitors/hsqldb.rb +24 -0
- data/lib/arel/visitors/mssql.rb +44 -0
- data/lib/arjdbc.rb +29 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +413 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +58 -132
- data/lib/arjdbc/derby/connection_methods.rb +18 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +36 -14
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +36 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +34 -62
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +10 -19
- data/lib/arjdbc/informix/connection_methods.rb +10 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +285 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +38 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +128 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +36 -26
- data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +17 -16
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +472 -0
- data/lib/arjdbc/mssql/connection_methods.rb +30 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
- data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +2 -1
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +416 -0
- data/lib/arjdbc/mysql/connection_methods.rb +27 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +68 -33
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +147 -72
- data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +381 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -27
- data/lib/jdbc_adapter/rake_tasks.rb +3 -10
- data/lib/jdbc_adapter/version.rb +3 -5
- data/lib/pg.rb +23 -1
- data/rails_generators/jdbc_generator.rb +2 -2
- data/rails_generators/templates/{jdbc.rb → config/initializers/jdbc.rb} +1 -1
- data/rails_generators/templates/{jdbc.rake → lib/tasks/jdbc.rake} +2 -2
- data/rakelib/compile.rake +5 -3
- data/rakelib/db.rake +19 -0
- data/rakelib/package.rake +12 -6
- data/rakelib/test.rake +24 -14
- data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +63 -34
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/{jdbc_adapter/MssqlRubyJdbcConnection.java → arjdbc/informix/InformixRubyJdbcConnection.java} +15 -12
- data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +21 -8
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +210 -67
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/test/abstract_db_create.rb +98 -19
- data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
- data/test/db/db2.rb +4 -2
- data/test/db/derby.rb +12 -14
- data/test/db/hsqldb.rb +3 -2
- data/test/db/jndi_config.rb +22 -12
- data/test/db/mssql.rb +5 -5
- data/test/db/sqlite3.rb +2 -6
- data/test/db2_simple_test.rb +56 -0
- data/test/derby_migration_test.rb +50 -3
- data/test/derby_simple_test.rb +87 -0
- data/test/generic_jdbc_connection_test.rb +21 -1
- data/test/h2_simple_test.rb +35 -0
- data/test/jdbc_common.rb +4 -5
- data/test/jndi_callbacks_test.rb +3 -1
- data/test/jndi_test.rb +1 -11
- data/test/models/entry.rb +20 -0
- data/test/models/mixed_case.rb +7 -2
- data/test/models/string_id.rb +18 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_simple_test.rb +49 -0
- data/test/mysql_db_create_test.rb +8 -6
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_simple_test.rb +19 -1
- data/test/oracle_simple_test.rb +9 -20
- data/test/oracle_specific_test.rb +83 -0
- data/test/pick_rails_version.rb +3 -0
- data/test/postgres_db_create_test.rb +11 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_mixed_case_test.rb +11 -1
- data/test/postgres_nonseq_pkey_test.rb +0 -2
- data/test/postgres_schema_search_path_test.rb +44 -0
- data/test/postgres_simple_test.rb +53 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/simple.rb +103 -9
- data/test/sqlite3_simple_test.rb +1 -0
- data/test/sybase_jtds_simple_test.rb +22 -0
- metadata +239 -137
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
- data/lib/jdbc_adapter/jdbc_db2.rb +0 -191
- data/lib/jdbc_adapter/jdbc_mssql.rb +0 -333
- data/lib/jdbc_adapter/jdbc_mysql.rb +0 -236
- data/lib/jdbc_adapter/jdbc_sqlite3.rb +0 -379
- data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
- data/src/java/jdbc_adapter/SQLBlock.java +0 -27
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
- data/test/cachedb_simple_test.rb +0 -6
- data/test/db/cachedb.rb +0 -9
- data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
- data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
- data/test/minirunit.rb +0 -109
- data/test/minirunit/testConnect.rb +0 -14
- data/test/minirunit/testH2.rb +0 -73
- data/test/minirunit/testHsqldb.rb +0 -73
- data/test/minirunit/testLoadActiveRecord.rb +0 -3
- data/test/minirunit/testMysql.rb +0 -83
- 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-
|
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
|
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
|
39
|
-
public static void load(RubyModule
|
40
|
-
RubyModule mysql =
|
41
|
-
mysql.defineAnnotatedMethods(
|
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-
|
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
|
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
|
38
|
-
protected
|
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
|
44
|
+
public static RubyClass createPostgresqlJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
43
45
|
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("PostgresJdbcConnection",
|
44
|
-
jdbcConnection,
|
45
|
-
clazz.defineAnnotatedMethods(
|
46
|
+
jdbcConnection, POSTGRESQL_JDBCCONNECTION_ALLOCATOR);
|
47
|
+
clazz.defineAnnotatedMethods(PostgresqlRubyJdbcConnection.class);
|
46
48
|
|
47
49
|
return clazz;
|
48
50
|
}
|
49
51
|
|
50
|
-
private static ObjectAllocator
|
52
|
+
private static ObjectAllocator POSTGRESQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
51
53
|
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
52
|
-
return new
|
54
|
+
return new PostgresqlRubyJdbcConnection(runtime, klass);
|
53
55
|
}
|
54
56
|
};
|
55
57
|
}
|