Browse Source

Adding support in SqlSrv for drop table if exists

Jose Lorenzo Rodriguez 14 years ago
parent
commit
cdc81333e8

+ 19 - 0
lib/Cake/Model/Datasource/Database/Sqlserver.php

@@ -753,4 +753,23 @@ class Sqlserver extends DboSource {
 		}
 	}
 
+/**
+ * Generate a "drop table" statement for the given Schema object
+ *
+ * @param CakeSchema $schema An instance of a subclass of CakeSchema
+ * @param string $table Optional.  If specified only the table name given will be generated.
+ *   Otherwise, all tables defined in the schema are generated.
+ * @return string
+ */
+	public function dropSchema(CakeSchema $schema, $table = null) {
+		$out = '';
+		foreach ($schema->tables as $curTable => $columns) {
+			if (!$table || $table == $curTable) {
+				$t =  $this->fullTableName($curTable);
+				$out .= "IF OBJECT_ID('" . $this->fullTableName($curTable, false). "', 'U') IS NOT NULL DROP TABLE " .  $this->fullTableName($curTable) . ";\n";
+			}
+		}
+		return $out;
+	}
+
 }

+ 1 - 1
lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php

@@ -235,7 +235,7 @@ class ProjectTaskTest extends CakeTestCase {
  */
 	public function testCakeAdmin() {
 		$file = new File(APP . 'Config' . DS . 'core.php');
-		$contents = $file->read();;
+		$contents = $file->read();
 		$file = new File(TMP . 'tests' . DS . 'core.php');
 		$file->write($contents);