Created
February 5, 2009 21:15
-
-
Save jrun/59013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/active_record/connection_adapters/jdbc_adapter.rb b/lib/active_record/connection_adapters/jdbc_adapter.rb | |
index b40a59e..e5cbd63 100644 | |
--- a/lib/active_record/connection_adapters/jdbc_adapter.rb | |
+++ b/lib/active_record/connection_adapters/jdbc_adapter.rb | |
@@ -374,15 +374,15 @@ module ActiveRecord | |
while resultset.next | |
index_name = resultset.get_string(Jdbc::IndexMetaData::INDEX_NAME) | |
next unless index_name | |
- index_name.downcase! | |
- column_name = resultset.get_string(Jdbc::IndexMetaData::COLUMN_NAME).downcase | |
+ index_name#.downcase! | |
+ column_name = resultset.get_string(Jdbc::IndexMetaData::COLUMN_NAME)#.downcase | |
next if primary_keys.include? column_name | |
# We are working on a new index | |
if current_index != index_name | |
current_index = index_name | |
- table_name = resultset.get_string(Jdbc::IndexMetaData::TABLE_NAME).downcase | |
+ table_name = resultset.get_string(Jdbc::IndexMetaData::TABLE_NAME)#.downcase | |
non_unique = resultset.get_boolean(Jdbc::IndexMetaData::NON_UNIQUE) | |
# empty list for column names, we'll add to that in just a bit | |
diff --git a/src/java/jdbc_adapter/RubyJdbcConnection.java b/src/java/jdbc_adapter/RubyJdbcConnection.java | |
index 04ad0b0..a823746 100644 | |
--- a/src/java/jdbc_adapter/RubyJdbcConnection.java | |
+++ b/src/java/jdbc_adapter/RubyJdbcConnection.java | |
@@ -268,7 +268,7 @@ public class RubyJdbcConnection extends RubyObject { | |
try { | |
stmt = c.createStatement(); | |
stmt.setMaxRows(maxRows); | |
- return unmarshalResult(context, stmt.executeQuery(query), false); | |
+ return unmarshalResult(context, stmt.executeQuery(query), c.getMetaData().storesUpperCaseIdentifiers(), false); | |
} finally { | |
close(stmt); | |
} | |
@@ -386,14 +386,15 @@ public class RubyJdbcConnection extends RubyObject { | |
public static IRubyObject select_p(ThreadContext context, IRubyObject recv, IRubyObject _sql) { | |
ByteList sql = rubyApi.convertToRubyString(_sql).getByteList(); | |
- return context.getRuntime().newBoolean(startsWithNoCaseCmp(sql, SELECT) || | |
+ return context.getRuntime().newBoolean(startsWithNoCaseCmp(sql, SELECT) || | |
startsWithNoCaseCmp(sql, SHOW) || startsWithNoCaseCmp(sql, CALL)); | |
} | |
@JRubyMethod(name = "set_native_database_types") | |
public IRubyObject set_native_database_types(ThreadContext context) throws SQLException, IOException { | |
Ruby runtime = context.getRuntime(); | |
- IRubyObject types = unmarshalResult(context, getConnection(true).getMetaData().getTypeInfo(), true); | |
+ DatabaseMetaData metaData = getConnection(true).getMetaData(); | |
+ IRubyObject types = unmarshalResult(context, metaData.getTypeInfo(), metaData.storesUpperCaseIdentifiers(), true); | |
IRubyObject typeConverter = getConnectionAdapters(runtime).getConstant("JdbcTypeConverter"); | |
IRubyObject value = rubyApi.callMethod(rubyApi.callMethod(typeConverter, "new", types), "choose_best_types"); | |
setInstanceVariable("@native_types", value); | |
@@ -803,7 +804,13 @@ public class RubyJdbcConnection extends RubyObject { | |
rs = metadata.getTables(catalog, realschema, realtablepat, types); | |
List arr = new ArrayList(); | |
while (rs.next()) { | |
- String name = rs.getString(3).toLowerCase(); | |
+ //String name = rs.getString(3).toLowerCase(); | |
+ | |
+ | |
+ | |
+ String name = rs.getString(3); | |
+ | |
+ | |
// Handle stupid Oracle 10g RecycleBin feature | |
if (!isOracle || !name.startsWith("bin$")) { | |
arr.add(RubyString.newUnicodeString(runtime, name)); | |
@@ -923,13 +930,12 @@ public class RubyJdbcConnection extends RubyObject { | |
* @param downCase should column names only be in lower case? | |
*/ | |
protected static IRubyObject unmarshalResult(ThreadContext context, ResultSet resultSet, | |
- boolean downCase) throws SQLException { | |
+ boolean storesUpper, boolean downCase) throws SQLException { | |
Ruby runtime = context.getRuntime(); | |
List results = new ArrayList(); | |
try { | |
- boolean storesUpper = !downCase && resultSet.getStatement().getConnection().getMetaData().storesUpperCaseIdentifiers(); | |
- ColumnData[] columns = ColumnData.setup(runtime, resultSet.getMetaData(), storesUpper); | |
+ ColumnData[] columns = ColumnData.setup(runtime, resultSet.getMetaData(), storesUpper, downCase); | |
populateFromResultSet(context, runtime, results, resultSet, columns); | |
} finally { | |
@@ -991,7 +997,7 @@ public class RubyJdbcConnection extends RubyObject { | |
return end; | |
} | |
- | |
+ | |
private static byte[] CALL = new byte[]{'c', 'a', 'l', 'l'}; | |
private static byte[] INSERT = new byte[] {'i', 'n', 's', 'e', 'r', 't'}; | |
private static byte[] SELECT = new byte[] {'s', 'e', 'l', 'e', 'c', 't'}; | |
@@ -1020,14 +1026,20 @@ public class RubyJdbcConnection extends RubyObject { | |
} | |
public static ColumnData[] setup(Ruby runtime, ResultSetMetaData metadata, | |
- boolean storesUpper) throws SQLException { | |
+ boolean storesUpper, boolean downCase) throws SQLException { | |
int columnsCount = metadata.getColumnCount(); | |
ColumnData[] columns = new ColumnData[columnsCount]; | |
for (int i = 1; i <= columnsCount; i++) { // metadata is one-based | |
String name = metadata.getColumnLabel(i); | |
- // We don't want to lowercase mixed case columns | |
- if (!storesUpper || (storesUpper && !HAS_SMALL.matcher(name).find())) name = name.toLowerCase(); | |
+ // We don't want to lowercase mixed case colums | |
+ if (downCase || (storesUpper && !HAS_SMALL.matcher(name).find())) | |
+ name = name.toLowerCase(); | |
columns[i - 1] = new ColumnData(RubyString.newUnicodeString(runtime, name), | |
metadata.getColumnType(i)); | |
diff --git a/test/simple.rb b/test/simple.rb | |
index da064fa..6e9e4ed 100644 | |
--- a/test/simple.rb | |
+++ b/test/simple.rb | |
@@ -5,6 +5,13 @@ ActiveRecord::Base.default_timezone = :utc | |
#just a random zone, unlikely to be local, and not utc | |
Time.zone = 'Moscow' if Time.respond_to?(:zone) | |
+module Rails | |
+ def Rails.logger | |
+ ActiveRecord::Base.logger | |
+ end | |
+end | |
+ | |
+ | |
module MigrationSetup | |
def setup | |
DbTypeMigration.up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment