Permalink
Browse files

Adding support in SqlSrv for drop table if exists

  • Loading branch information...
1 parent cf49d51 commit cdc81333e8f41c44d7e0c2acc8398b2edef2e84b @lorenzo lorenzo committed Jun 21, 2011
@@ -753,4 +753,23 @@ protected function _execute($sql, $params = array(), $prepareOptions = array())
}
}
+/**
+ * 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;
+ }
+
}
@@ -235,7 +235,7 @@ public function testGetPrefix() {
*/
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);

0 comments on commit cdc8133

Please sign in to comment.