jdbc_mysql structure dump fails for mysql views (fix included)
--------------------------------------------------------------

                 Key: JRUBY-2012
                 URL: http://jira.codehaus.org/browse/JRUBY-2012
             Project: JRuby
          Issue Type: Bug
          Components: ActiveRecord-JDBC
    Affects Versions: JRuby 1.1RC1
         Environment: Windows XP, Rails 2.0.2, JRuby, MySQL 5.0.27
            Reporter: Tyler Jennings


Attempting a 'rake db:structure:dump' on a mysql database which includes mysql 
views will fail.  Here is the stack trace:

rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.+
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/jdbc_mysql.rb:131:in
 `structure_dump'
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/jdbc_mysql.rb:129:in
 `inject'
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/jdbc_mysql.rb:129:in
 `each'
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/jdbc_mysql.rb:129:in
 `inject'
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/jdbc_mysql.rb:129:in
 `structure_dump'
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/jdbc_mysql.rb:129
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/rake_tasks.rb:26:in
 `open'
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/rake_tasks.rb:26
C:/projects/mmh/mmh-web-mvn/src/main/webapp/rails/config/../vendor/activerecord-jdbc-adapter-0.7.1/lib/jdbc_adapter/rake_tasks.rb:26:in
 `call'


Here is my naive fix in jdbc_mysql.rb:

def structure_dump #:nodoc:
      if supports_views?
        sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
      else
        sql = "SHOW TABLES"
      end
      
      select_all(sql).inject("") do |structure, table|
        table.delete('Table_type')
        #puts ":::: " + "SHOW CREATE TABLE 
#{quote_table_name(table.to_a.first.last)}"
        hash = select_one("SHOW CREATE TABLE 
#{quote_table_name(table.to_a.first.last)}")
                       
        if(table = hash["Create Table"])
          structure += table + ";\n\n"
        elsif(view = hash["Create View"])
          structure += view + ";\n\n"
        end
      end
    end

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to