Title: [992] trunk/activerecord-jdbc: JRUBY-2438: Updates to SQLite driver from Joseph Athman
Revision
992
Author
nicksieger
Date
2008-05-13 22:20:56 -0400 (Tue, 13 May 2008)

Log Message

JRUBY-2438: Updates to SQLite driver from Joseph Athman

Modified Paths


Diff

Modified: trunk/activerecord-jdbc/History.txt (991 => 992)


--- trunk/activerecord-jdbc/History.txt	2008-05-13 22:10:32 UTC (rev 991)
+++ trunk/activerecord-jdbc/History.txt	2008-05-14 02:20:56 UTC (rev 992)
@@ -3,6 +3,8 @@
 - Now sporting a JDBC sqlite3 adapter! Thanks Joseph Athman.
 - Added support for InterSystems Cache database (Ryan Bell)
 - Fix for JRUBY-2256
+- JRUBY-1638, JRUBY-2404, JRUBY-2463: schema.table handling and Oracle NUMBER fixes (Thanks Darcy Schultz & Jesse Hu)
+- Add structure dump and other DDL-ish for DB2 (courtesy abedra and stuarthalloway)
 
 == 0.8
 

Modified: trunk/activerecord-jdbc/README.txt (991 => 992)


--- trunk/activerecord-jdbc/README.txt	2008-05-13 22:10:32 UTC (rev 991)
+++ trunk/activerecord-jdbc/README.txt	2008-05-14 02:20:56 UTC (rev 992)
@@ -26,8 +26,7 @@
   * rename_column
 * HSQLDB - Complete
 * H2 - Complete
-* SQLite3 - work in progress, definitely not working:
-  * remove_column
+* SQLite3 - work in progress
 
 Other databases will require testing and likely a custom configuration module. Please join the jruby-extras mailing-list[http://rubyforge.org/mail/?group_id=2014] to help us discover support for more databases.
 

Modified: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_sqlite3.rb (991 => 992)


--- trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_sqlite3.rb	2008-05-13 22:10:32 UTC (rev 991)
+++ trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_sqlite3.rb	2008-05-14 02:20:56 UTC (rev 992)
@@ -113,7 +113,21 @@
     end
 
     def remove_column(table_name, column_name) #:nodoc:
-      puts "not implemented in SQLite3"
+      cols = columns(table_name).collect {|col| col.name}
+      cols.delete(column_name)
+      cols = cols.join(', ')
+      table_backup = table_name + "_backup"
+
+      @connection.begin
+
+      execute "CREATE TEMPORARY TABLE #{table_backup}(#{cols})"
+      insert "INSERT INTO #{table_backup} SELECT #{cols} FROM #{table_name}"
+      execute "DROP TABLE #{table_name}"
+      execute "CREATE TABLE #{table_name}(#{cols})"
+      insert "INSERT INTO #{table_name} SELECT #{cols} FROM #{table_backup}"
+      execute "DROP TABLE #{table_backup}"
+
+      @connection.commit
     end
 
     def change_column(table_name, column_name, type, options = {}) #:nodoc:
@@ -144,17 +158,6 @@
       Integer(select_value("SELECT SEQ FROM SQLITE_SEQUENCE WHERE NAME = '#{table}'"))
     end
 
-    # Override normal #_execute: See Rubyforge #11567
-    def _execute(sql, name = nil)
-      if ::ActiveRecord::ConnectionAdapters::JdbcConnection::select?(sql)
-        @connection.execute_query(sql)
-      elsif ::ActiveRecord::ConnectionAdapters::JdbcConnection::insert?(sql)
-        insert(sql, name)
-      else
-        @connection.execute_update(sql)
-      end
-    end
-
     def add_limit_offset!(sql, options) #:nodoc:
       if options[:limit]
         sql << " LIMIT #{options[:limit]}"
@@ -171,24 +174,15 @@
     end
 
     def indexes(table_name, name = nil)
-      result = select_rows(<<-SQL, name)
-        SELECT name, sql
-          FROM sqlite_master
-         WHERE tbl_name = '#{table_name}'
-           AND type = 'index'
-      SQL
+      result = select_rows("SELECT name, sql FROM sqlite_master WHERE tbl_name = '#{table_name}' AND type = 'index'", name)
 
-      indexes = []
-
-      result.each do |row|
+      result.collect do |row|
         name = row[0]
         index_sql = row[1]
         unique = (index_sql =~ /unique/i)
         cols = index_sql.match(/\((.*)\)/)[1].gsub(/,/,' ').split
-        indexes << ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, name, unique, cols)
+        ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, name, unique, cols)
       end
-
-      indexes
     end
   end
 end
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to