public function getAssoc($sql, $bindings = array())
{
$this->sql = $sql;
$this->signal('sql_exec', $this);
$rows = $this->db->GetAll($sql, $bindings);
$assoc = array();
if (!$rows) {
return $assoc;
}
foreach ($rows as $row) {
if (empty($row)) {
continue;
}
if (count($row) > 2) {
$key = array_shift($row);
$value = $row;
} elseif (count($row) > 1) {
$key = array_shift($row);
$value = array_shift($row);
} else {
$key = array_shift($row);
$value = $key;
}
$assoc[$key] = $value;
}
return $assoc;
}
/** * @see QueryWriter::wipeAll */ public function wipeAll() { foreach ($this->getTables() as $t) { try { $foreignKeys = $this->adapter->getAssoc("SELECT\n\t\t\t\t 'ALTER TABLE ' + OBJECT_SCHEMA_NAME(parent_object_id) +\n\t\t\t\t '.[' + OBJECT_NAME(parent_object_id) +\n\t\t\t\t '] DROP CONSTRAINT ' + name\n\t\t\t\tFROM sys.foreign_keys\n\t\t\t\tWHERE referenced_object_id = object_id('{$t}')"); if (count($foreignKeys)) { foreach ($foreignKeys as $sql) { $this->adapter->exec($sql); } } $this->adapter->exec("IF OBJECT_ID('[{$t}]', 'U') IS NOT NULL DROP TABLE [{$t}];"); } catch (SQLException $e) { } } }