Permalink
Browse files

Fix Database#rename_table on Microsoft SQL Server (Fixes #293)

  • Loading branch information...
1 parent a39fc8f commit 70f58e6e9b04ffa2a6a1f8b8178cd8bdd115b788 @jeremyevans committed Apr 15, 2010
Showing with 18 additions and 0 deletions.
  1. +2 −0 CHANGELOG
  2. +5 −0 lib/sequel/adapters/shared/mssql.rb
  3. +11 −0 spec/integration/schema_test.rb
View
2 CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Fix Database#rename_table on Microsoft SQL Server (rohit.namjoshi) (#293)
+
* Add Dataset#provides_accurate_rows_matched?, for seeing if update and delete are likely to return correct numbers (jeremyevans)
* Add require_modification to Sequel::Model, for checking that model instance updating and deleting affects a single row (jeremyevans)
View
5 lib/sequel/adapters/shared/mssql.rb
@@ -109,6 +109,11 @@ def metadata_dataset
ds
end
+ # Use SP_RENAME to rename the table
+ def rename_table_sql(name, new_name)
+ "SP_RENAME #{quote_schema_table(name)}, #{quote_schema_table(new_name)}"
+ end
+
# SQL to rollback to a savepoint
def rollback_savepoint_sql(depth)
SQL_ROLLBACK_TO_SAVEPOINT % depth
View
11 spec/integration/schema_test.rb
@@ -159,6 +159,17 @@
@ds.columns!.should == [:number]
end
+ specify "should rename tables correctly" do
+ @db.drop_table(:items) rescue nil
+ @db.create_table!(:items2){Integer :number}
+ @db.rename_table(:items2, :items)
+ @db.table_exists?(:items).should == true
+ @db.table_exists?(:items2).should == false
+ @db.schema(:items, :reload=>true).map{|x| x.first}.should == [:number]
+ @ds.insert([10])
+ @ds.columns!.should == [:number]
+ end
+
specify "should allow creating indexes with tables" do
@db.create_table!(:items){Integer :number; index :number}
@db.table_exists?(:items).should == true

0 comments on commit 70f58e6

Please sign in to comment.