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