From 5059dbc90de2e859b7c2cb221d47b5b4287e61fe Mon Sep 17 00:00:00 2001 From: zYne Date: Sun, 20 Aug 2006 18:52:07 +0000 Subject: [PATCH] Sqlite Datadict updated, Doctrine_Record::merge fixed --- Doctrine.php | 16 +++++++++++----- Doctrine/Hydrate.php | 7 ++++--- Doctrine/Record.php | 3 ++- Doctrine/Table.php | 3 +-- Doctrine/Validator/Email.php | 10 +++++++++- Doctrine/adodb-hack/adodb-datadict.inc.php | 2 +- .../adodb-hack/drivers/datadict-sqlite.inc.php | 7 ++++--- tests/ValidatorTestCase.php | 4 +++- tests/ValueHolderTestCase.php | 4 ++-- 9 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Doctrine.php b/Doctrine.php index 7f92e31ca..659cc045a 100644 --- a/Doctrine.php +++ b/Doctrine.php @@ -196,19 +196,25 @@ final class Doctrine { * mode for lazy offset fetching */ const FETCH_LAZY_OFFSET = 4; + /** - * RETURN CONSTANTS + * FETCH CONSTANTS */ /** - * RETURN VALUEHOLDER + * FETCH VALUEHOLDER */ - const RETURN_VHOLDER = 1; + const FETCH_VHOLDER = 1; /** - * RETURN RECORD + * FETCH RECORD */ - const RETURN_RECORD = 2; + const FETCH_RECORD = 2; + /** + * FETCH ARRAY + */ + const FETCH_ARRAY = 3; + /** * LOCKMODE CONSTANTS diff --git a/Doctrine/Hydrate.php b/Doctrine/Hydrate.php index 7c119c620..faa9bd3ad 100644 --- a/Doctrine/Hydrate.php +++ b/Doctrine/Hydrate.php @@ -226,7 +226,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { * @param string $params * @return Doctrine_Collection the root collection */ - public function execute($params = array(), $return = Doctrine::RETURN_RECORD) { + public function execute($params = array(), $return = Doctrine::FETCH_RECORD) { $this->data = array(); $this->collections = array(); @@ -275,9 +275,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $array = $this->parseData($stmt); - if($return == Doctrine::RETURN_VHOLDER) { + if($return == Doctrine::FETCH_VHOLDER) { return $this->hydrateHolders($array); - } + } elseif($return == Doctrine::FETCH_ARRAY) + return $array; foreach($array as $data) { /** diff --git a/Doctrine/Record.php b/Doctrine/Record.php index bb09c45f5..3e2559b6e 100644 --- a/Doctrine/Record.php +++ b/Doctrine/Record.php @@ -1239,7 +1239,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite public function merge(array $values) { foreach($this->table->getColumnNames() as $value) { try { - $this->data[$value] = $values[$value]; + if(isset($values[$value])) + $this->set($value, $values[$value]); } catch(Exception $e) { } } } diff --git a/Doctrine/Table.php b/Doctrine/Table.php index f210149be..b6254bf56 100644 --- a/Doctrine/Table.php +++ b/Doctrine/Table.php @@ -143,7 +143,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { // reverse names $names = array_reverse($names); - // create database table if(method_exists($record,"setTableDefinition")) { $record->setTableDefinition(); @@ -734,7 +733,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $users = $q->query("FROM ".$this->name." WHERE ".$dql, $params); return $users; } - + public function findByDql($dql, array $params = array()) { return $this->findBySql($dql, $params); } diff --git a/Doctrine/Validator/Email.php b/Doctrine/Validator/Email.php index 54e39f554..37f1e7ebe 100644 --- a/Doctrine/Validator/Email.php +++ b/Doctrine/Validator/Email.php @@ -11,6 +11,14 @@ class Doctrine_Validator_Email { if(empty($value)) return true; + return self::validateEmail($value); + } + /** + * validateEmail + * + * @param string $value + */ + public static function validateEmail($value) { $parts = explode("@", $value); if(count($parts) != 2) @@ -27,7 +35,7 @@ class Doctrine_Validator_Email { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $parts[$i])) { return false; } - } + } if (!ereg("^\[?[0-9\.]+\]?$", $parts[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $parts[1]); if (count($domain_array) < 2) { diff --git a/Doctrine/adodb-hack/adodb-datadict.inc.php b/Doctrine/adodb-hack/adodb-datadict.inc.php index db30d64c7..638356b47 100644 --- a/Doctrine/adodb-hack/adodb-datadict.inc.php +++ b/Doctrine/adodb-hack/adodb-datadict.inc.php @@ -898,7 +898,7 @@ class ADODB_DataDict { } // return string must begin with space - function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint) + function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned = null) { $suffix = ''; if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; diff --git a/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php b/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php index 3bb3621b0..1cd4deb63 100644 --- a/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php +++ b/Doctrine/adodb-hack/drivers/datadict-sqlite.inc.php @@ -50,7 +50,8 @@ class ADODB2_sqlite extends ADODB_DataDict { } } // return string must begin with space - function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) + + function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned = null) { $suffix = ''; if ($funsigned) $suffix .= ' UNSIGNED'; @@ -97,14 +98,14 @@ class ADODB2_sqlite extends ADODB_DataDict { return $sql; } - function AlterColumnSQL($tabname, $flds) + function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { if ($this->debug) $this->outp("AlterColumnSQL not supported"); return array(); } - function DropColumnSQL($tabname, $flds) + function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { if ($this->debug) $this->outp("DropColumnSQL not supported"); return array(); diff --git a/tests/ValidatorTestCase.php b/tests/ValidatorTestCase.php index 7a841f09e..60599f35a 100644 --- a/tests/ValidatorTestCase.php +++ b/tests/ValidatorTestCase.php @@ -84,11 +84,13 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase { $this->assertEqual($stack['mystring'], Doctrine_Validator::ERR_NOTNULL); $this->assertEqual($stack['myemail2'], Doctrine_Validator::ERR_NOTBLANK); - $test->mystring = 'str'; + $test->save(); } + public function testEmailValidation() { + } public function testValidate() { $user = $this->session->getTable("User")->find(4); diff --git a/tests/ValueHolderTestCase.php b/tests/ValueHolderTestCase.php index 81a73d881..e88d486ef 100644 --- a/tests/ValueHolderTestCase.php +++ b/tests/ValueHolderTestCase.php @@ -19,7 +19,7 @@ class Doctrine_ValueHolder_TestCase extends Doctrine_UnitTestCase { public function testSimpleQuery() { $q = new Doctrine_Query($this->session); $q->from("User"); - $users = $q->execute(array(), Doctrine::RETURN_VHOLDER); + $users = $q->execute(array(), Doctrine::FETCH_VHOLDER); $this->assertEqual($users->count(), 8); @@ -27,7 +27,7 @@ class Doctrine_ValueHolder_TestCase extends Doctrine_UnitTestCase { public function testQueryWithOneToManyRelation() { $q = new Doctrine_Query($this->session); $q->from("User.Phonenumber"); - $users = $q->execute(array(), Doctrine::RETURN_VHOLDER); + $users = $q->execute(array(), Doctrine::FETCH_VHOLDER); $this->assertEqual($users->count(), 8); $this->assertTrue($users[0] instanceof Doctrine_ValueHolder); $this->assertTrue($users[3] instanceof Doctrine_ValueHolder);