Bugs item #11179, was opened at 2007-05-28 10:47
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=7857&aid=11179&group_id=2014

Category: AR-JDBC
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Jack Hung (jackhung)
Assigned to: Nobody (None)
Summary: db:schema:dump failed on SQL Server with JTDS

Initial Comment:
Two Problems when doing 'rake db:schema:dump'

Environment: JRuby 0.9, ActiveRecord 0.3.1, JTDS 1.2, SQL Server 2000

----------------------------------------------------------------------------
Problem 1 - noMethodError for method 'indexes' jdbc_mssql.rb, rake complete but 
in the generated schema.rb, you get the following for all tables:

  ActiveRecord::Schema.define() do

  # Could not dump table "country" because of following NoMethodError
  #   undefined or inaccessible method `indexes' for 
#<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x104bce3   
@connection=#<ActiveRecord::ConnectionAdapters::JdbcConnection:0x176484e 
@connection=#<Java::NetSourceforgeJtdsJdbc::ConnectionJDBC3:0x84fdbc @[EMAIL 
PROTECTED]>, @adapter=#<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x104bce3 
...>,...

Fix for Problem 1: add the following to jdbc_mssql.rb 
-----------------------------------------------------------------------------
#### copy from mysql ###
def indexes(table_name, name = nil)#:nodoc:
  r = @connection.indexes(table_name.upcase)
end

-----------------------------------------------------------------------------

Problem 2 - noMethodError for nil.downcase, rake complete but you get a 
different error in schema.rb,

 ActiveRecord::Schema.define() do

 # Could not dump table "country" because of following NoMethodError
 #   You have a nil object when you didn't expect it!
 The error occurred while evaluating nil.downcase
------------------------------------------------------------------------------
Fix for Problem 2: For JTDS, the first result in the resultset returned from 
metadata.getIndexInfo does not contain the normal index info (INDEX_NAME is 
null). 
Making the following modification to jdbc_adapter.rb fixes the problem:


 def indexes(table_name, name = nil)
   metadata = @connection.getMetaData
   unless String === table_name
     table_name = table_name.to_s
   else
     table_name = table_name.dup
   end
   table_name.upcase! if metadata.storesUpperCaseIdentifiers
   table_name.downcase! if metadata.storesLowerCaseIdentifiers
   resultset = metadata.getIndexInfo(nil, nil, table_name, false, false)
   primary_keys = primary_keys(table_name)
   indexes = []
   current_index = nil
   while resultset.next
+ #   index_name = 
resultset.get_string(Jdbc::IndexMetaData::INDEX_NAME).downcase
+ #   The first resultset seems to contain information other than that of a 
index's column. INDEX_NAME is null.
+ #   And you get a nil.downcase problem
+     index_name = resultset.get_string(Jdbc::IndexMetaData::INDEX_NAME)
+ #   just ignore if index_name is null
+     next if !index_name
+     index_name.downcase!
     column_name = 
resultset.get_string(Jdbc::IndexMetaData::COLUMN_NAME).downcase



----------------------------------------------------------------------

>Comment By: Ola Bini (olabini)
Date: 2007-08-11 15:35

Message:
Is this still a problem?

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=7857&aid=11179&group_id=2014
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to