public function testIterator() { $graph = new Doctrine_Query($this->connection); $entities = $graph->query("FROM Entity"); $i = 0; foreach($entities as $entity) { $this->assertEqual(gettype($entity->name),"string"); $i++; } $this->assertTrue($i == $entities->count()); $user = $graph->query("FROM User"); foreach($user[1]->Group as $group) { $this->assertTrue(is_string($group->name)); } $user = new User(); $user->name = "tester"; $user->Address[0]->address = "street 1"; $user->Address[1]->address = "street 2"; $this->assertEqual($user->name, "tester"); $this->assertEqual($user->Address[0]->address, "street 1"); $this->assertEqual($user->Address[1]->address, "street 2"); foreach($user->Address as $address) { $a[] = $address->address; } $this->assertEqual($a, array("street 1", "street 2")); $user->save(); $user = $user->getTable()->find($user->id); $this->assertEqual($user->name, "tester"); $this->assertEqual($user->Address[0]->address, "street 1"); $this->assertEqual($user->Address[1]->address, "street 2"); $user = $user->getTable()->find($user->id); $a = array(); foreach($user->Address as $address) { $a[] = $address->address; } $this->assertEqual($a, array("street 1", "street 2")); $user = $graph->query("FROM User"); }
public function execute() { Doctrine::loadModels($this->getArgument('models_path')); $dql = $this->getArgument('dql_query'); $query = new Doctrine_Query(); $this->notify('executing: "' . $dql . '"'); $results = $query->query($dql); $this->printResults($results); }
public function execute() { Doctrine::loadModels($this->getArgument('models_path')); $dql = $this->getArgument('dql_query'); $query = new Doctrine_Query(); $params = $this->getArgument('params'); $params = $params ? explode(',', $params) : array(); $this->notify('executing: "' . $dql . '" (' . implode(', ', $params) . ')'); $results = $query->query($dql, $params, Doctrine::HYDRATE_ARRAY); $this->_printResults($results); }
/** * findByDql * finds records with given DQL where clause * returns a collection of records * * @param string $dql DQL after WHERE clause * @param array $params query parameters * @param int $hydrationMode Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD * @return Doctrine_Collection */ public function findByDql($dql, $params = array(), $hydrationMode = null) { $parser = new Doctrine_Query($this->_conn); $component = $this->getComponentName(); $query = 'FROM ' . $component . ' dctrn_find WHERE ' . $dql; return $parser->query($query, $params, $hydrationMode); }
/** * Load all relationships or the named relationship passed * * @param mixed $name * @return boolean */ public function loadRelated($name = null) { $list = array(); $query = new Doctrine_Query($this->_table->getConnection()); if (!isset($name)) { foreach ($this->data as $record) { $value = $record->getIncremented(); if ($value !== null) { $list[] = $value; } } $query->from($this->_table->getComponentName()); $query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)), 0, -2) . ')'); return $query; } $rel = $this->_table->getRelation($name); if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) { foreach ($this->data as $record) { $list[] = $record[$rel->getLocal()]; } } else { foreach ($this->data as $record) { $value = $record->getIncremented(); if ($value !== null) { $list[] = $value; } } } $dql = $rel->getRelationDql(count($list), 'collection'); $coll = $query->query($dql, $list); $this->populateRelated($name, $coll); }
/** * query * queries the database using Doctrine Query Language and returns * the first record found * * <code> * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.id = ?', array(1)); * * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.name LIKE ? AND u.password = ?', * array('someone', 'password') * ); * </code> * * @param string $query DQL query * @param array $params query parameters * @see Doctrine_Query * @return Doctrine_Record|false Doctrine_Record object on success, * boolean false on failure */ public function queryOne($query, array $params = array()) { $parser = new Doctrine_Query($this); $coll = $parser->query($query, $params); if (!$coll->contains(0)) { return false; } return $coll[0]; }
public function testNotEqual() { try { $query = new Doctrine_Query($this->connection); $ret = $query->query("FROM EnumTest WHERE EnumTest.status != 'closed'"); $this->assertEqual(count($ret), 1); } catch (Exception $e) { $this->fail(); } }
public function testFetchingWithSmartConversion() { $query = new Doctrine_Query($this->connection); $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = false'); $this->assertEqual(count($ret), 1); $query = new Doctrine_Query($this->connection); $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = true'); $this->assertEqual(count($ret), 1); }
/** * findByDql * finds records with given DQL where clause * returns a collection of records * * @param string $dql DQL after WHERE clause * @param array $params query parameters * @return Doctrine_Collection */ public function findBySql($dql, array $params = array()) { $q = new Doctrine_Query($this->conn); $users = $q->query('FROM ' . $this->options['name'] . ' WHERE ' . $dql, $params); return $users; }
public function testMultipleOneToManyFetchingWithOrderBy() { $query = new Doctrine_Query(); $users = $query->query("FROM User.Album.Song WHERE User.id IN (4,5) ORDER BY User.Album.Song.title DESC"); }