Title: [469] trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb: Fix the Derby sequence problem the correct way: by implement reset_sequence! and reset_pk_sequence!
Revision
469
Author
olabini
Date
2007-04-22 12:45:10 -0400 (Sun, 22 Apr 2007)

Log Message

Fix the Derby sequence problem the correct way: by implement reset_sequence! and reset_pk_sequence!

Modified Paths

Diff

Modified: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb (468 => 469)


--- trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb	2007-04-20 22:17:24 UTC (rev 468)
+++ trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb	2007-04-22 16:45:10 UTC (rev 469)
@@ -60,6 +60,17 @@
       @limit = nil
     end
 
+    # Set the sequence to the max value of the table's column.
+    def reset_sequence!(table, column, sequence = nil)
+      mpk = select_value("SELECT MAX(#{column}) FROM #{table}")
+      execute("ALTER TABLE #{table} ALTER COLUMN #{column} RESTART WITH #{mpk.to_i + 1}")      
+    end
+      
+    def reset_pk_sequence!(table, pk = nil, sequence = nil)
+      pk = :id unless pk
+      reset_sequence!(table, pk, sequence)
+    end
+    
     def execute(sql, name = nil)
       log_no_bench(sql, name) do
         if sql =~ /^select/i
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to