From 8a393ab44df25525239e086f41de13114f477969 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 23 Jul 2007 23:44:14 +0000 Subject: [PATCH] --- lib/Doctrine/Export.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 37b2b2b00..c63cd2fde 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -229,7 +229,17 @@ class Doctrine_Export extends Doctrine_Connection_Module } $name = $this->conn->quoteIdentifier($name, true); - $query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; + $query = 'CREATE TABLE ' . $name . ' (' . $queryFields; + + $check = $this->getCheckDeclaration($fields); + + if ( ! empty($check)) { + $query .= ', ' . $check; + } + + $query .= ')'; + + $sql[] = $query; @@ -694,24 +704,22 @@ class Doctrine_Export extends Doctrine_Connection_Module */ public function getCheckDeclaration(array $definition) { - $query .= 'CHECK '; - $constraints = array(); foreach ($definition as $field => $def) { - if (isset($def['min'])) { - $constraints[] = 'CHECK (' . $field . ' > ' . $def['min'] . ')'; - } - - if (isset($def['max'])) { - $constraints[] = 'CHECK (' . $field . ' < ' . $def['max'] . ')'; - } - if (is_string($def)) { $constraints[] = 'CHECK (' . $def . ')'; + } else { + if (isset($def['min'])) { + $constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')'; + } + + if (isset($def['max'])) { + $constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')'; + } } } - $query .= implode(', ', $constraints); + return implode(', ', $constraints); } /** * Obtain DBMS specific SQL code portion needed to set an index