public function dropList()
 {
     $dao = $this->container->getDao();
     DBPool::getByDao($dao)->queryNull(OSQL::delete()->from($this->container->getHelperTable())->where(Expression::eq($this->container->getParentIdField(), $this->container->getParentObject()->getId())));
     $dao->uncacheLists();
     return $this;
 }
 private function getSome()
 {
     for ($i = 1; $i < 3; ++$i) {
         $this->assertTrue(TestUser::dao()->getByLogic(Expression::eq('city_id', $i)) == TestUser::dao()->getById($i));
     }
     $this->assertEquals(count(TestUser::dao()->getPlainList()), count(TestCity::dao()->getPlainList()));
 }
 /**
  * @return SelectQuery
  **/
 protected function joinHelperTable(SelectQuery $query)
 {
     $uc = $this->container;
     if (!$query->hasJoinedTable($uc->getHelperTable())) {
         $query->join($uc->getHelperTable(), Expression::eq(new DBField($uc->getParentTableIdField(), $uc->getDao()->getTable()), new DBField($uc->getChildIdField(), $uc->getHelperTable())));
     }
     return $query->andWhere(Expression::eq(new DBField($uc->getParentIdField(), $uc->getHelperTable()), new DBValue($uc->getParentObject()->getId())));
 }
 public function testLazy()
 {
     foreach (DBTestPool::me()->getPool() as $db) {
         DBPool::me()->setDefault($db);
         $parent = TestParentObject::create();
         $child = TestChildObject::create()->setParent($parent);
         $parent->dao()->add($parent);
         $child->dao()->add($child);
         $this->assertEquals($parent->getId(), Criteria::create(TestChildObject::dao())->setProjection(Projection::property('parent.id', 'parentId'))->add(Expression::eq('id', $child->getId()))->getCustom('parentId'));
     }
 }
 public function testHasNoReturning()
 {
     $dialect = ImaginaryDialect::me();
     $query = OSQL::update('test_table')->set('field1', 1)->where(Expression::eq('field1', 2))->returning('field1');
     try {
         $query->toDialectString($dialect);
     } catch (UnimplementedFeatureException $e) {
         return $this;
     }
     $this->fail();
 }
 public function testIpRangeProperty()
 {
     foreach (DBTestPool::me()->getPool() as $db) {
         DBPool::me()->setDefault($db);
         $akado = TestInternetProvider::create()->setName('Akada')->setRange(IpRange::create(IpAddress::create('192.168.1.1'), IpAddress::create('192.168.1.42')));
         TestInternetProvider::dao()->add($akado);
         $plainRange = Criteria::create(TestInternetProvider::dao())->addProjection(Projection::property('range'))->add(Expression::eq('name', 'Akada'))->getCustom();
         $this->assertEquals($plainRange['range'], '192.168.1.1-192.168.1.42');
         TestInternetProvider::dao()->add(TestInternetProvider::create()->setName('DomRu')->setRange(IpRange::create('192.168.2.0/24')));
         $list = Criteria::create(TestInternetProvider::dao())->addOrder('id')->getList();
         $this->assertEquals(count($list), 2);
     }
 }
 public function testQuery()
 {
     $query = OSQL::delete()->from('pity_table');
     $dialect = PostgresDialect::me();
     try {
         $query->toDialectString($dialect);
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     $query->where(Expression::eq('count', 2));
     $this->assertEquals($query->toDialectString($dialect), 'DELETE FROM "pity_table" WHERE ("count" = \'2\')');
     $query->andWhere(Expression::notEq('a', '2'));
     $this->assertEquals($query->toDialectString($dialect), 'DELETE FROM "pity_table" WHERE ("count" = \'2\') AND ("a" != \'2\')');
 }
 public function testSelectJoin()
 {
     $dialect = $this->getDbByType('PgSQL')->getDialect();
     $joinTypeList = array('JOIN ' => 'join', 'LEFT JOIN ' => 'leftJoin', 'RIGHT JOIN ' => 'rightJoin', 'FULL OUTER JOIN ' => 'fullOuterJoin');
     $joinExpression = Expression::eq(DBField::create('joinField', 'table1'), DBField::create('joinField', 'table2'));
     $baseRawQuery = 'SELECT ' . '"table1"."field1", ' . '"table2"."field2" ' . 'FROM "table1" ';
     foreach ($joinTypeList as $sqlJoin => $method) {
         $query = $this->getBaseJoinSelect()->{$method}('table2', $joinExpression);
         $rawQuery = $baseRawQuery . $sqlJoin . '"table2" ON ("table1"."joinField" = "table2"."joinField")';
         $this->assertEquals($rawQuery, $query->toDialectString($dialect));
         $query = $this->getBaseJoinSelect()->{$method}('table2', $joinExpression, 'table2');
         $rawQuery = $baseRawQuery . $sqlJoin . '"table2" AS "table2" ' . 'ON ("table1"."joinField" = "table2"."joinField")';
         $this->assertEquals($rawQuery, $query->toDialectString($dialect));
     }
 }
 public function testQuery()
 {
     $query = OSQL::delete()->from('pity_table');
     $dialect = ImaginaryDialect::me();
     try {
         $query->toDialectString($dialect);
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     $query->where(Expression::eq(1, 2));
     $this->assertEquals($query->toDialectString($dialect), 'DELETE FROM pity_table WHERE (1 = 2)');
     $query->andWhere(Expression::notEq('a', 'b'));
     $this->assertEquals($query->toDialectString($dialect), 'DELETE FROM pity_table WHERE (1 = 2) AND (a != b)');
 }
 public function testForgottenDao()
 {
     $criteria = Criteria::create()->add(Expression::eq('id', 42));
     $listCriteria = clone $criteria;
     try {
         $listCriteria->getList();
         $this->fail();
     } catch (WrongStateException $e) {
         /*it's good*/
     }
     $customCriteria = clone $criteria;
     try {
         $customCriteria->addProjection(Projection::property('id'))->getCustomList();
         $this->fail();
     } catch (WrongStateException $e) {
         /*it's good*/
     }
 }
 public function testInnerTransaction()
 {
     foreach (DBTestPool::me()->getPool() as $connector => $db) {
         DBPool::me()->setDefault($db);
         $this->getDBCreator()->fillDB();
         $moscow = TestCity::dao()->getByLogic(Expression::eq('name', 'Moscow'));
         $piter = TestCity::dao()->getByLogic(Expression::eq('name', 'Saint-Peterburg'));
         $cityNewer = function (TestCity $city) {
             $city->dao()->merge($city->setName('New ' . $city->getName()));
         };
         $citiesNewer = function ($moscow, $piter) use($cityNewer, $db) {
             $cityNewer($moscow);
             InnerTransactionWrapper::create()->setDB($db)->setFunction($cityNewer)->run($piter);
         };
         InnerTransactionWrapper::create()->setDao($moscow->dao())->setFunction($citiesNewer)->run($moscow, $piter);
         $this->assertNotNull(TestCity::dao()->getByLogic(Expression::eq('name', 'New Moscow')));
         $this->assertNotNull(TestCity::dao()->getByLogic(Expression::eq('name', 'New Saint-Peterburg')));
     }
 }
 /**
  * @return OneToManyLinkedFull
  **/
 public function sync($insert, $update = array(), $delete)
 {
     $uc = $this->container;
     $dao = $uc->getDao();
     if ($delete) {
         DBPool::getByDao($dao)->queryNull(OSQL::delete()->from($dao->getTable())->where(Expression::eq(new DBField($uc->getParentIdField()), $uc->getParentObject()->getId()))->andWhere(Expression::in($uc->getChildIdField(), ArrayUtils::getIdsArray($delete))));
         $dao->uncacheByIds(ArrayUtils::getIdsArray($delete));
     }
     if ($insert) {
         for ($i = 0, $size = count($insert); $i < $size; ++$i) {
             $dao->add($insert[$i]);
         }
     }
     if ($update) {
         for ($i = 0, $size = count($update); $i < $size; ++$i) {
             $dao->save($update[$i]);
         }
     }
     return $this;
 }
示例#13
0
 public function testChainForm()
 {
     $form = Form::create()->add(Primitive::string('a'))->add(Primitive::string('b'))->add(Primitive::integer('c'))->add(Primitive::integer('d'))->add(Primitive::boolean('e'))->add(Primitive::string('f'))->import(array('a' => 'true', 'c' => 123, 'd' => 123));
     $andChain = Expression::chain()->expAnd(Expression::expOr(new FormField('a'), Expression::notNull(new FormField('b'))))->expAnd(Expression::eq(new FormField('c'), new FormField('d')))->expAnd(Expression::isFalse(new FormField('e')));
     $this->assertTrue($andChain->toBoolean($form));
     $form->importMore(array('e' => 'on'));
     $this->assertFalse($andChain->toBoolean($form));
     $orChain = Expression::chain()->expOr(Expression::eq(new FormField('a'), new FormField('b')))->expOr(Expression::expOr(new FormField('e'), Expression::gt(new FormField('c'), new FormField('d'))))->expOr(Expression::in(new FormField('f'), array('qwer', 'asdf', 'zxcv')));
     $form->import(array());
     $this->assertFalse($orChain->toBoolean($form));
     $form->import(array('e' => '1'));
     $this->assertTrue($orChain->toBoolean($form));
     $form->import(array('a' => 'asdf', 'b' => 'qwerq', 'c' => '13', 'd' => '1313', 'f' => 'iukj'));
     $this->assertFalse($orChain->toBoolean($form));
     $form->import(array('c' => '13', 'd' => '12'));
     $this->assertTrue($orChain->toBoolean($form));
     $form->import(array('f' => 'asdfwer'));
     $this->assertFalse($orChain->toBoolean($form));
     $form->import(array('f' => 'qwer'));
     $this->assertTrue($orChain->toBoolean($form));
 }
 public function getById($id, $expires = Cache::EXPIRES_MEDIUM)
 {
     if ($expires !== Cache::DO_NOT_CACHE && ($object = $this->getCachedById($id))) {
         if ($object === Cache::NOT_FOUND) {
             throw new CachedObjectNotFoundException("there is no such object for '" . $this->dao->getObjectName() . "' with id=" . $id);
         }
         return $this->dao->completeObject($object);
     } else {
         $query = $this->dao->makeSelectHead()->andWhere(Expression::eq(DBField::create($this->dao->getIdName(), $this->dao->getTable()), $id));
         if ($expires === Cache::DO_NOT_CACHE) {
             $object = $this->fetchObject($query);
         } else {
             $object = $this->cachedFetchObject($query, $expires, true);
         }
         if ($object) {
             return $object;
         } else {
             throw new ObjectNotFoundException("there is no such object for '" . $this->dao->getObjectName() . "' with query == " . $query->toDialectString(DBPool::me()->getByDao($this->dao)->getDialect()));
         }
     }
 }
 public function testHaving()
 {
     $query = OQL::select('from TestUser');
     $criteria = Criteria::create(TestUser::dao());
     $this->assertCriteria($query->addHaving(OQL::having('id > 0')), $criteria->addProjection(Projection::having(Expression::gt('id', 0))));
     $this->assertCriteria($query->addHaving(OQL::having('name is not null and (id <> $1 or id != $2)')->bindNext(4)->bindNext(8)), $criteria->addProjection(Projection::having(Expression::expAnd(Expression::notNull('name'), Expression::expOr(Expression::notEq('id', 4), Expression::notEq('id', 8))))));
     $this->assertEquals(OQL::having('id + $15')->bind(15, 16)->toProjection(), Projection::having(Expression::add('id', 16)));
     $this->assertCriteria(OQL::select('from TestUser')->addHaving(OQL::having('id = $1')->bindNext(23))->bindNext(42), Criteria::create(TestUser::dao())->addProjection(Projection::having(Expression::eq('id', 42))));
 }
 private function processPath(AbstractProtoClass $proto, $probablyPath, JoinCapableQuery $query, $table, $parentRequired = true, $prefix = null)
 {
     $path = explode('.', $probablyPath);
     try {
         $property = $proto->getPropertyByName($path[0]);
     } catch (MissingElementException $e) {
         // oh, it's a value, not a property
         return new DBValue($probablyPath);
     }
     unset($path[0]);
     Assert::isTrue($property->getRelationId() != null && !$property->isGenericType());
     Assert::classExists($property->getClassName());
     // checking whether we're playing with value object
     if (!method_exists($property->getClassName(), 'dao')) {
         if (method_exists($property->getClassName(), 'proto') && count($path) > 1) {
             return $this->processPath($property->getProto(), implode('.', $path), $query, $table);
         } else {
             return $this->guessAtom(implode('.', $path), $query, $table, $prefix);
         }
     } else {
         $propertyDao = call_user_func(array($property->getClassName(), 'dao'));
         Assert::isNotNull($propertyDao, 'can not find target dao for "' . $property->getName() . '" property at "' . get_class($proto) . '"');
     }
     $alias = $propertyDao->getJoinName($property->getColumnName(), $prefix);
     if ($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY) {
         $remoteName = $property->getClassName();
         $selfName = $this->getObjectName();
         $self = new $selfName();
         $getter = $property->getGetter();
         $dao = call_user_func(array($remoteName, 'dao'));
         if ($property->getRelationId() == MetaRelation::MANY_TO_MANY) {
             $helperTable = $self->{$getter}()->getHelperTable();
             $helperAlias = $helperTable;
             if (!$query->hasJoinedTable($helperAlias)) {
                 $logic = Expression::eq(DBField::create($this->getIdName(), $table), DBField::create($self->{$getter}()->getParentIdField(), $helperAlias));
                 if ($property->isRequired()) {
                     $query->join($helperTable, $logic, $helperAlias);
                 } else {
                     $query->leftJoin($helperTable, $logic, $helperAlias);
                 }
             }
             $logic = Expression::eq(DBField::create($propertyDao->getIdName(), $alias), DBField::create($self->{$getter}()->getChildIdField(), $helperAlias));
         } else {
             $logic = Expression::eq(DBField::create($self->{$getter}()->getParentIdField(), $alias), DBField::create($this->getIdName(), $table));
         }
         if (!$query->hasJoinedTable($alias)) {
             if ($property->isRequired() && $parentRequired) {
                 $query->join($dao->getTable(), $logic, $alias);
             } else {
                 $query->leftJoin($dao->getTable(), $logic, $alias);
             }
         }
     } else {
         // OneToOne, lazy OneToOne
         // prevents useless joins
         if (isset($path[1]) && count($path) == 1 && $path[1] == $propertyDao->getIdName()) {
             return new DBField($property->getColumnName(), $table);
         }
         if (!$query->hasJoinedTable($alias)) {
             $logic = Expression::eq(DBField::create($property->getColumnName(), $table), DBField::create($propertyDao->getIdName(), $alias));
             if ($property->isRequired() && $parentRequired) {
                 $query->join($propertyDao->getTable(), $logic, $alias);
             } else {
                 $query->leftJoin($propertyDao->getTable(), $logic, $alias);
             }
         }
     }
     if ($path) {
         return $propertyDao->guessAtom(implode('.', $path), $query, $alias, $property->isRequired() && $parentRequired, $propertyDao->getJoinPrefix($property->getColumnName(), $prefix));
     }
     // ok, we're done
 }
 private function checkEnumerationReferentialIntegrity(Enumeration $enumeration, $tableName)
 {
     $updateQueries = null;
     $db = DBPool::me()->getLink();
     $class = get_class($enumeration);
     $ids = array();
     $list = $enumeration->getObjectList();
     foreach ($list as $enumerationObject) {
         $ids[$enumerationObject->getId()] = $enumerationObject->getName();
     }
     $rows = $db->querySet(OSQL::select()->from($tableName)->multiGet('id', 'name'));
     echo "\n";
     foreach ($rows as $row) {
         if (!isset($ids[$row['id']])) {
             echo "Class '{$class}', strange id: {$row['id']} found. \n";
         } else {
             if ($ids[$row['id']] != $row['name']) {
                 echo "Class '{$class}',id: {$row['id']} sync names. \n";
                 $updateQueries .= OSQL::update($tableName)->set('name', $ids[$row['id']])->where(Expression::eq('id', $row['id']))->toDialectString($db->getDialect()) . ";\n";
             }
             unset($ids[$row['id']]);
         }
     }
     foreach ($ids as $id => $name) {
         echo "Class '{$class}', id: {$id} not present in database. \n";
     }
     echo $updateQueries;
     return $this;
 }
示例#18
0
 private function update(IdentifiableOrmEntity $entity)
 {
     $affected = $this->executeQuery(UpdateQuery::create($this->physicalSchema->getTable())->setValues($this->map->disassemble($entity))->setCondition(EntityQuery::create($this->entity)->where(Expression::eq($this->identifier, $entity->_getId()))->toExpression()));
     $entity->setFetched();
     return $affected > 0;
 }
 public function logIn($username, $password)
 {
     return $this->getByLogic(Expression::expAnd(Expression::eq('username', $username), Expression::eq('password', $password)));
 }
 public function dropById($id)
 {
     $result = DBPool::getByDao($this->dao)->queryCount(OSQL::delete()->from($this->dao->getTable())->where(Expression::eq($this->dao->getIdName(), $id)));
     $this->dao->uncacheById($id);
     return $result;
 }
 /**
  * @param TestCase $test
  * @return DBTestCreator
  */
 public function fillDB(TestCase $test = null)
 {
     $moscow = TestCity::create()->setName('Moscow');
     $piter = TestCity::create()->setName('Saint-Peterburg');
     $mysqler = TestUser::create()->setCity($moscow)->setCredentials(Credentials::create()->setNickname('mysqler')->setPassword(sha1('mysqler')))->setLastLogin(Timestamp::create(time()))->setRegistered(Timestamp::create(time())->modify('-1 day'));
     $postgreser = clone $mysqler;
     $postgreser->setCredentials(Credentials::create()->setNickName('postgreser')->setPassword(sha1('postgreser')))->setCity($piter)->setUrl(HttpUrl::create()->parse('http://postgresql.org/'));
     $piter = TestCity::dao()->add($piter);
     $moscow = TestCity::dao()->add($moscow);
     if ($test) {
         $test->assertEquals($piter->getId(), 1);
         $test->assertEquals($moscow->getId(), 2);
     }
     $postgreser = TestUser::dao()->add($postgreser);
     for ($i = 0; $i < 10; $i++) {
         $encapsulant = TestEncapsulant::dao()->add(TestEncapsulant::create()->setName($i));
         $encapsulant->getCities()->fetch()->setList(array($piter, $moscow))->save();
     }
     $mysqler = TestUser::dao()->add($mysqler);
     if ($test) {
         $test->assertEquals($postgreser->getId(), 1);
         $test->assertEquals($mysqler->getId(), 2);
     }
     if ($test) {
         // put them in cache now
         TestUser::dao()->dropIdentityMap();
         TestUser::dao()->getById(1);
         TestUser::dao()->getById(2);
         if ($test instanceof DBDataTest) {
             $test->getListByIdsTest();
         }
         Cache::me()->clean();
         $test->assertTrue($postgreser == TestUser::dao()->getById(1));
         $test->assertTrue($mysqler == TestUser::dao()->getById(2));
     }
     $firstClone = clone $postgreser;
     $secondClone = clone $mysqler;
     $firstCount = TestUser::dao()->dropById($postgreser->getId());
     $secondCount = TestUser::dao()->dropByIds(array($mysqler->getId()));
     if ($test) {
         $test->assertEquals($firstCount, 1);
         $test->assertEquals($secondCount, 1);
         try {
             TestUser::dao()->getById(1);
             $test->fail();
         } catch (ObjectNotFoundException $e) {
             /* pass */
         }
         $result = Criteria::create(TestUser::dao())->add(Expression::eq(1, 2))->getResult();
         $test->assertEquals($result->getCount(), 0);
         $test->assertEquals($result->getList(), array());
     }
     TestUser::dao()->import($firstClone);
     TestUser::dao()->import($secondClone);
     if ($test && $test instanceof DBDataTest) {
         // cache multi-get
         $test->getListByIdsTest();
         $test->getListByIdsTest();
     }
     return $this;
 }
示例#22
0
 private function joinProperties(SelectQuery $query, ProtoDAO $parentDao, $parentTable, $parentRequired, $prefix = null)
 {
     $proto = call_user_func(array($parentDao->getObjectName(), 'proto'));
     foreach ($proto->getPropertyList() as $property) {
         if ($property instanceof LightMetaProperty && $property->getRelationId() == MetaRelation::ONE_TO_ONE && !$property->isGenericType() && (!$property->getFetchStrategyId() && $this->getFetchStrategy()->getId() == FetchStrategy::JOIN || $property->getFetchStrategyId() == FetchStrategy::JOIN)) {
             if (is_subclass_of($property->getClassName(), 'Enumeration')) {
                 // field already added by makeSelectHead
                 continue;
             } elseif ($property->isInner()) {
                 $proto = call_user_func(array($property->getClassName(), 'proto'));
                 foreach ($proto->getPropertyList() as $innerProperty) {
                     $query->get(new DBField($innerProperty->getColumnName(), $parentTable));
                 }
                 continue;
             }
             $propertyDao = call_user_func(array($property->getClassName(), 'dao'));
             // add's custom dao's injection possibility
             if (!$propertyDao instanceof ProtoDAO) {
                 continue;
             }
             $tableAlias = $propertyDao->getJoinName($property->getColumnName(), $prefix);
             $fields = $propertyDao->getFields();
             if (!$query->hasJoinedTable($tableAlias)) {
                 $logic = Expression::eq(DBField::create($property->getColumnName(), $parentTable), DBField::create($propertyDao->getIdName(), $tableAlias));
                 if ($property->isRequired() && $parentRequired) {
                     $query->join($propertyDao->getTable(), $logic, $tableAlias);
                 } else {
                     $query->leftJoin($propertyDao->getTable(), $logic, $tableAlias);
                 }
             }
             foreach ($fields as $field) {
                 $query->get(new DBField($field, $tableAlias), $propertyDao->getJoinPrefix($property->getColumnName(), $prefix) . $field);
             }
             $this->joinProperties($query, $propertyDao, $tableAlias, $property->isRequired() && $parentRequired, $propertyDao->getJoinPrefix($property->getColumnName(), $prefix));
         }
     }
 }
 /**
  * @return ISqlSelectQuery
  */
 private function makeSqlSelectQuery(EntityQuery $query)
 {
     $query = $query->toSelectQuery();
     $joinMethod = SqlJoinMethod::INNER;
     $childrenTable = $this->getChildren()->getPhysicalSchema()->getTable();
     $proxyTable = $this->mtm->getProxy()->getPhysicalSchema()->getTable();
     $condition = Expression::andChain();
     $srcSqlFields = $this->getChildren()->getLogicalSchema()->getIdentifier()->getFields();
     $dstSqlFields = $this->mtm->getEncapsulantProxyProperty()->getFields();
     foreach ($srcSqlFields as $k => $v) {
         $condition->add(Expression::eq(new SqlColumn($srcSqlFields[$k], $childrenTable), new SqlColumn($dstSqlFields[$k], $proxyTable)));
     }
     $query->join(new SqlConditionalJoin(new SelectQuerySource(new SqlIdentifier($proxyTable)), new SqlJoinMethod($joinMethod), $condition));
     $columnName = $this->mtm->getContainerProxyProperty()->getField();
     $query->andWhere(Expression::eq(new SqlColumn($columnName, $this->mtm->getProxy()->getPhysicalSchema()->getTable()), new SqlValue($this->getParentObject()->_getId())));
     return $query;
 }
 private function checkEnumerationReferentialIntegrity($enumeration, $tableName)
 {
     Assert::isTrue($enumeration instanceof Enumeration || $enumeration instanceof Enum, 'argument enumeation must be instacne of Enumeration or Enum! gived, "' . gettype($enumeration) . '"');
     $updateQueries = null;
     $db = DBPool::me()->getLink();
     $class = get_class($enumeration);
     $ids = array();
     if ($enumeration instanceof Enumeration) {
         $list = $enumeration->getList();
     } elseif ($enumeration instanceof Enum) {
         $list = ClassUtils::callStaticMethod($class . '::getList');
     }
     foreach ($list as $enumerationObject) {
         $ids[$enumerationObject->getId()] = $enumerationObject->getName();
     }
     $rows = $db->querySet(OSQL::select()->from($tableName)->multiGet('id', 'name'));
     echo "\n";
     foreach ($rows as $row) {
         if (!isset($ids[$row['id']])) {
             echo "Class '{$class}', strange id: {$row['id']} found. \n";
         } else {
             if ($ids[$row['id']] != $row['name']) {
                 echo "Class '{$class}',id: {$row['id']} sync names. \n";
                 $updateQueries .= OSQL::update($tableName)->set('name', $ids[$row['id']])->where(Expression::eq('id', $row['id']))->toDialectString($db->getDialect()) . ";\n";
             }
             unset($ids[$row['id']]);
         }
     }
     foreach ($ids as $id => $name) {
         echo "Class '{$class}', id: {$id} not present in database. \n";
     }
     echo $updateQueries;
     return $this;
 }
 /**
  * @return void
  */
 private function join(OrmProperty $property, AssociationPropertyType $type, EntityQueryBuilder $builder, SelectQuerySource $source)
 {
     $joinMethod = $type->getAssociationMultiplicity()->is(AssociationMultiplicity::EXACTLY_ONE) ? SqlJoinMethod::INNER : SqlJoinMethod::LEFT;
     $condition = Expression::andChain();
     $srcSqlFields = $property->getFields();
     $dstSqlFields = $builder->entity->getLogicalSchema()->getIdentifier()->getFields();
     foreach ($srcSqlFields as $k => $v) {
         $condition->add(Expression::eq(new SqlColumn($srcSqlFields[$k], $this->alias), new SqlColumn($dstSqlFields[$k], $builder->alias)));
     }
     $source->join(new SqlConditionalJoin(new SelectQuerySource(new AliasedSqlValueExpression(new SqlIdentifier($builder->table), $builder->alias)), new SqlJoinMethod($joinMethod), $condition));
 }
 private function fillQuery(EntityQuery $query)
 {
     $query->andWhere(Expression::eq($this->referentialProperty, $this->getParentObject()));
 }
 public function testQuery()
 {
     $criteria = Criteria::create(TestUser::dao())->setProjection(Projection::property('id'))->add(Expression::isTrue('id'));
     $this->assertCriteria('id from TestUser where id is true', $criteria)->assertCriteria('id from TestUser where id is true order by id asc', $criteria->addOrder(OrderBy::create('id')->asc()))->assertCriteria('id from TestUser where id is true order by id asc limit 10 offset 1', $criteria->setLimit(10)->setOffset(1))->assertCriteria('id from TestUser where id is true group by id order by id asc limit 10 offset 1', $criteria->setProjection(Projection::chain()->add(Projection::property('id'))->add(Projection::group('id'))))->assertCriteria('id from TestUser where id is true group by id order by id asc having id = 1 limit 10 offset 1', $criteria->setProjection(Projection::chain()->add(Projection::property('id'))->add(Projection::group('id'))->add(Projection::having(Expression::eq('id', 1)))))->assertCriteria('count(id) as count from TestUser group by id having count = 2', Criteria::create(TestUser::dao())->setProjection(Projection::chain()->add(Projection::count('id', 'count'))->add(Projection::group('id'))->add(Projection::having(Expression::eq('count', 2)))));
 }
 /**
  * @param string $name
  * @return TestCity
  */
 public static function getCityByName($name)
 {
     return Criteria::create(TestCity::dao())->add(Expression::eq('name', DBValue::create($name)))->get();
 }