1
0
mirror of synced 2024-12-13 22:56:04 +03:00
This commit is contained in:
zYne 2007-05-18 09:33:51 +00:00
parent 4b09d95d0f
commit 9d8cb481a7

View File

@ -20,7 +20,7 @@
*/
Doctrine::autoload('Doctrine_Export');
/**
* Doctrine_Export_Oracle
* Doctrine_Export_Mssql
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
@ -60,7 +60,7 @@ class Doctrine_Export_Mssql extends Doctrine_Export
public function dropDatabase($name)
{
$name = $this->conn->quoteIdentifier($name, true);
return $this->conn->standaloneQuery("DROP DATABASE $name", null, true);
return $this->conn->standaloneQuery('DROP DATABASE ' . $name, null, true);
}
/**
* alter an existing table
@ -152,8 +152,8 @@ class Doctrine_Export_Mssql extends Doctrine_Export
*/
public function alterTable($name, $changes, $check)
{
foreach ($changes as $change_name => $change) {
switch ($change_name) {
foreach ($changes as $changeName => $change) {
switch ($changeName) {
case 'add':
break;
case 'remove':
@ -162,50 +162,50 @@ class Doctrine_Export_Mssql extends Doctrine_Export
case 'rename':
case 'change':
default:
throw new Doctrine_Export_Exception('alterTable: change type "' . $change_name . '" not yet supported');
throw new Doctrine_Export_Exception('alterTable: change type "' . $changeName . '" not yet supported');
}
}
$query = '';
if (!empty($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $field_name => $field) {
if ( ! empty($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $fieldName => $field) {
if ($query) {
$query.= ', ';
$query .= ', ';
}
$query.= 'ADD ' . $this->conn->getDeclaration($field['type'], $field_name, $field);
$query .= 'ADD ' . $this->conn->getDeclaration($field['type'], $fieldName, $field);
}
}
if (!empty($changes['remove']) && is_array($changes['remove'])) {
foreach ($changes['remove'] as $field_name => $field) {
if ( ! empty($changes['remove']) && is_array($changes['remove'])) {
foreach ($changes['remove'] as $fieldName => $field) {
if ($query) {
$query.= ', ';
$query .= ', ';
}
$field_name = $this->conn->quoteIdentifier($field_name, true);
$query.= 'DROP COLUMN ' . $field_name;
$field_name = $this->conn->quoteIdentifier($fieldName, true);
$query .= 'DROP COLUMN ' . $fieldName;
}
}
if (!$query) {
if ( ! $query) {
return false;
}
$name = $this->conn->quoteIdentifier($name, true);
return $this->conn->exec("ALTER TABLE $name $query");
return $this->conn->exec('ALTER TABLE ' . $name . ' ' . $query);
}
/**
* create sequence
*
* @param string $seq_name name of the sequence to be created
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @return void
*/
public function createSequence($seq_name, $start = 1)
public function createSequence($seqName, $start = 1)
{
$sequence_name = $this->conn->quoteIdentifier($this->conn->getSequenceName($seq_name), true);
$seqcol_name = $this->conn->quoteIdentifier($this->conn->options['seqcol_name'], true);
$query = "CREATE TABLE $sequence_name ($seqcol_name " .
"INT PRIMARY KEY CLUSTERED IDENTITY($start,1) NOT NULL)";
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->options['seqcol_name'], true);
$query = 'CREATE TABLE ' . $sequenceName . ' (' . $seqcolName .
' INT PRIMARY KEY CLUSTERED IDENTITY(' . $start . ',1) NOT NULL)';
$res = $this->conn->exec($query);
@ -214,11 +214,11 @@ class Doctrine_Export_Mssql extends Doctrine_Export
}
try {
$query = 'SET IDENTITY_INSERT $sequence_name ON ' .
'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')';
$query = 'SET IDENTITY_INSERT ' . $sequenceName . ' ON ' .
'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES ( ' . $start . ')';
$res = $this->conn->exec($query);
} catch (Exception $e) {
$result = $this->conn->exec("DROP TABLE $sequence_name");
$result = $this->conn->exec('DROP TABLE ' . $sequenceName);
}
return true;
}