From cfaa5f121f21e66d65cdad3c7b1258905b0af768 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 23 Jul 2007 23:18:11 +0000 Subject: [PATCH] --- lib/Doctrine/Export/Sqlite.php | 14 +++++++++++++- lib/Doctrine/Table.php | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Export/Sqlite.php b/lib/Doctrine/Export/Sqlite.php index 7fd7389d7..5d94408c1 100644 --- a/lib/Doctrine/Export/Sqlite.php +++ b/lib/Doctrine/Export/Sqlite.php @@ -180,7 +180,19 @@ class Doctrine_Export_Sqlite extends Doctrine_Export } $name = $this->conn->quoteIdentifier($name, true); - $query[] = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; + $sql = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; + + if ($check = $this->getCheckDeclaration($fields)) { + $sql .= ', ' . $check; + } + + if (isset($options['checks']) && $check = $this->getCheckDeclaration($options['checks'])) { + $sql .= ', ' . $check; + } + + $sql .= ')'; + + $query[] = $sql; if (isset($options['indexes']) && ! empty($options['indexes'])) { foreach ($options['indexes'] as $index => $definition) { diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 72756776d..3500a2348 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -121,7 +121,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable * * -- foreignKeys the foreign keys of this table * - * -- collation + * -- checks the check constraints of this table, eg. 'price > dicounted_price' + * + * -- collation collation attribute * * -- indexes the index definitions of this table * @@ -468,6 +470,23 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $this->options['foreignKeys'][] = $definition; } + /** + * addCheckConstraint + * + * adds a check constraint to this table + * + * @return void + */ + public function addCheckConstraint($definition, $name) + { + if (is_string($name)) { + $this->options['checks'][$name] = $definition; + } else { + $this->options['checks'][] = $definition; + } + + return $this; + } /** * addIndex *