activerecord-jdbc-adapter-onsite 1.2.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.
- data/.gitignore +22 -0
- data/.travis.yml +14 -0
- data/Appraisals +16 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/History.txt +488 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +214 -0
- data/Rakefile +62 -0
- data/activerecord-jdbc-adapter.gemspec +23 -0
- data/bench/bench_attributes.rb +13 -0
- data/bench/bench_attributes_new.rb +14 -0
- data/bench/bench_create.rb +12 -0
- data/bench/bench_find_all.rb +12 -0
- data/bench/bench_find_all_mt.rb +25 -0
- data/bench/bench_model.rb +85 -0
- data/bench/bench_new.rb +12 -0
- data/bench/bench_new_valid.rb +12 -0
- data/bench/bench_valid.rb +13 -0
- data/gemfiles/rails23.gemfile +10 -0
- data/gemfiles/rails23.gemfile.lock +38 -0
- data/gemfiles/rails30.gemfile +9 -0
- data/gemfiles/rails30.gemfile.lock +33 -0
- data/gemfiles/rails31.gemfile +9 -0
- data/gemfiles/rails31.gemfile.lock +35 -0
- data/gemfiles/rails32.gemfile +9 -0
- data/gemfiles/rails32.gemfile.lock +35 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- 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 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -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/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +32 -0
- data/lib/arel/visitors/firebird.rb +24 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +46 -0
- data/lib/arjdbc.rb +24 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +541 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/derby/adapter.rb +358 -0
- data/lib/arjdbc/derby/connection_methods.rb +19 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/firebird/adapter.rb +140 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +54 -0
- data/lib/arjdbc/h2/connection_methods.rb +13 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/arjdbc/hsqldb/adapter.rb +184 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +15 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +142 -0
- data/lib/arjdbc/informix/connection_methods.rb +11 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +356 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +47 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +134 -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 +35 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/arjdbc/jdbc/jdbc.rake +131 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +88 -0
- 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/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +477 -0
- data/lib/arjdbc/mssql/connection_methods.rb +31 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +101 -0
- data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
- data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +505 -0
- data/lib/arjdbc/mysql/connection_methods.rb +28 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/arjdbc/oracle/adapter.rb +432 -0
- data/lib/arjdbc/oracle/connection_methods.rb +12 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +861 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +23 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +389 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +35 -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/USAGE +10 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/pom.xml +57 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/db.rake +39 -0
- data/rakelib/rails.rake +41 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +69 -0
- data/src/java/arjdbc/derby/DerbyModule.java +324 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +68 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1346 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +161 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +82 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +126 -0
- data/test/abstract_db_create.rb +135 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/activerecord/jall.sh +7 -0
- data/test/activerecord/jtest.sh +3 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +12 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +18 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_reset_column_information_test.rb +8 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_reset_column_information_test.rb +8 -0
- data/test/derby_row_locking_test.rb +9 -0
- data/test/derby_simple_test.rb +139 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_change_column_test.rb +68 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +108 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +28 -0
- data/test/jndi_callbacks_test.rb +36 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +9 -0
- data/test/models/auto_id.rb +15 -0
- data/test/models/custom_pk_name.rb +14 -0
- data/test/models/data_types.rb +30 -0
- data/test/models/entry.rb +40 -0
- data/test/models/mixed_case.rb +22 -0
- data/test/models/reserved_word.rb +15 -0
- data/test/models/string_id.rb +17 -0
- data/test/models/thing.rb +16 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_ignore_system_views_test.rb +27 -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_null_test.rb +14 -0
- data/test/mssql_reset_column_information_test.rb +8 -0
- data/test/mssql_row_locking_sql_test.rb +159 -0
- data/test/mssql_row_locking_test.rb +9 -0
- data/test/mssql_simple_test.rb +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_index_length_test.rb +58 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_reset_column_information_test.rb +8 -0
- data/test/mysql_simple_test.rb +125 -0
- data/test/oracle_reset_column_information_test.rb +8 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_information_schema_leak_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_native_type_mapping_test.rb +93 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_reset_column_information_test.rb +8 -0
- data/test/postgres_schema_search_path_test.rb +48 -0
- data/test/postgres_simple_test.rb +168 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/postgres_type_conversion_test.rb +34 -0
- data/test/row_locking.rb +90 -0
- data/test/simple.rb +731 -0
- data/test/sqlite3_reset_column_information_test.rb +8 -0
- data/test/sqlite3_simple_test.rb +316 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- data/test/sybase_reset_column_information_test.rb +8 -0
- metadata +288 -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
|
+
protected 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,161 @@
|
|
|
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.DatabaseMetaData;
|
|
30
|
+
import java.sql.PreparedStatement;
|
|
31
|
+
import java.sql.SQLException;
|
|
32
|
+
import java.sql.ResultSet;
|
|
33
|
+
import java.sql.Statement;
|
|
34
|
+
import java.sql.Types;
|
|
35
|
+
import java.util.ArrayList;
|
|
36
|
+
import java.util.List;
|
|
37
|
+
|
|
38
|
+
import arjdbc.jdbc.SQLBlock;
|
|
39
|
+
import org.jruby.Ruby;
|
|
40
|
+
import org.jruby.RubyClass;
|
|
41
|
+
import org.jruby.RubyModule;
|
|
42
|
+
import org.jruby.RubyNil;
|
|
43
|
+
import org.jruby.RubyString;
|
|
44
|
+
import org.jruby.runtime.ObjectAllocator;
|
|
45
|
+
import org.jruby.runtime.ThreadContext;
|
|
46
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
47
|
+
|
|
48
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @author nicksieger
|
|
53
|
+
*/
|
|
54
|
+
public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
55
|
+
protected MySQLRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
|
56
|
+
super(runtime, metaClass);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Override
|
|
60
|
+
protected boolean genericExecute(Statement stmt, String query) throws SQLException {
|
|
61
|
+
return stmt.execute(query, Statement.RETURN_GENERATED_KEYS);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Override
|
|
65
|
+
protected IRubyObject unmarshalKeysOrUpdateCount(ThreadContext context, Connection c, Statement stmt) throws SQLException {
|
|
66
|
+
IRubyObject key = unmarshal_id_result(context.getRuntime(), stmt.getGeneratedKeys());
|
|
67
|
+
if (key.isNil()) {
|
|
68
|
+
return context.getRuntime().newFixnum(stmt.getUpdateCount());
|
|
69
|
+
}
|
|
70
|
+
return key;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Override
|
|
74
|
+
protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
|
|
75
|
+
throws SQLException {
|
|
76
|
+
if (Types.BOOLEAN == type || Types.BIT == type) {
|
|
77
|
+
return integerToRuby(runtime, resultSet, resultSet.getBoolean(column) ? 1 : 0);
|
|
78
|
+
}
|
|
79
|
+
return super.jdbcToRuby(runtime, column, type, resultSet);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public static RubyClass createMySQLJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
|
83
|
+
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("MySQLJdbcConnection",
|
|
84
|
+
jdbcConnection, MYSQL_JDBCCONNECTION_ALLOCATOR);
|
|
85
|
+
clazz.defineAnnotatedMethods(MySQLRubyJdbcConnection.class);
|
|
86
|
+
|
|
87
|
+
return clazz;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private static ObjectAllocator MYSQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
|
91
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
|
92
|
+
return new MySQLRubyJdbcConnection(runtime, klass);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
@Override
|
|
97
|
+
protected IRubyObject indexes(final ThreadContext context, final String tableNameArg, String name, final String schemaNameArg) {
|
|
98
|
+
return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
|
|
99
|
+
@Override
|
|
100
|
+
public Object call(Connection connection) throws SQLException {
|
|
101
|
+
Ruby runtime = context.getRuntime();
|
|
102
|
+
DatabaseMetaData metadata = connection.getMetaData();
|
|
103
|
+
String jdbcTableName = caseConvertIdentifierForJdbc(metadata, tableNameArg);
|
|
104
|
+
String jdbcSchemaName = caseConvertIdentifierForJdbc(metadata, schemaNameArg);
|
|
105
|
+
|
|
106
|
+
StringBuilder buffer = new StringBuilder("SHOW KEYS FROM ");
|
|
107
|
+
if (jdbcSchemaName != null) buffer.append(jdbcSchemaName).append(".");
|
|
108
|
+
buffer.append(jdbcTableName);
|
|
109
|
+
buffer.append(" WHERE key_name != 'PRIMARY'");
|
|
110
|
+
String query = buffer.toString();
|
|
111
|
+
|
|
112
|
+
List<IRubyObject> indexes = new ArrayList<IRubyObject>();
|
|
113
|
+
PreparedStatement stmt = null;
|
|
114
|
+
ResultSet rs = null;
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
stmt = connection.prepareStatement(query);
|
|
118
|
+
rs = stmt.executeQuery();
|
|
119
|
+
|
|
120
|
+
IRubyObject rubyTableName = RubyString.newUnicodeString(runtime, caseConvertIdentifierForJdbc(metadata, tableNameArg));
|
|
121
|
+
RubyModule indexDefinitionClass = getConnectionAdapters(runtime).getClass("IndexDefinition");
|
|
122
|
+
String currentKeyName = null;
|
|
123
|
+
|
|
124
|
+
while (rs.next()) {
|
|
125
|
+
String keyName = caseConvertIdentifierForRails(metadata, rs.getString("key_name"));
|
|
126
|
+
|
|
127
|
+
if (!keyName.equals(currentKeyName)) {
|
|
128
|
+
currentKeyName = keyName;
|
|
129
|
+
|
|
130
|
+
boolean nonUnique = rs.getBoolean("non_unique");
|
|
131
|
+
IRubyObject indexDefinition = indexDefinitionClass.callMethod(context, "new", new IRubyObject[]{
|
|
132
|
+
rubyTableName,
|
|
133
|
+
RubyString.newUnicodeString(runtime, keyName),
|
|
134
|
+
runtime.newBoolean(!nonUnique),
|
|
135
|
+
runtime.newArray(),
|
|
136
|
+
runtime.newArray()
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
indexes.add(indexDefinition);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
IRubyObject lastIndex = indexes.get(indexes.size() - 1);
|
|
143
|
+
if (lastIndex != null) {
|
|
144
|
+
String columnName = caseConvertIdentifierForRails(metadata, rs.getString("column_name"));
|
|
145
|
+
int length = rs.getInt("sub_part");
|
|
146
|
+
boolean lengthIsNull = rs.wasNull();
|
|
147
|
+
|
|
148
|
+
lastIndex.callMethod(context, "columns").callMethod(context, "<<", RubyString.newUnicodeString(runtime, columnName));
|
|
149
|
+
lastIndex.callMethod(context, "lengths").callMethod(context, "<<", lengthIsNull ? runtime.getNil() : runtime.newFixnum(length));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return runtime.newArray(indexes);
|
|
154
|
+
} finally {
|
|
155
|
+
close(rs);
|
|
156
|
+
close(stmt);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|