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; }
public function testDelete() { $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))->returning('id'); $this->assertEquals($query->toDialectString($dialect), 'DELETE FROM "pity_table" WHERE ("count" = \'2\') RETURNING "pity_table"."id"'); }
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 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\')'); }
/** * @throws WrongArgumentException * @return OneToManyLinkedLazy **/ public function sync($insert, $update = array(), $delete) { Assert::isTrue($update === array()); $db = DBPool::getByDao($this->container->getDao()); $uc = $this->container; $dao = $uc->getDao(); if ($insert) { $db->queryNull($this->makeMassUpdateQuery($insert)); } if ($delete) { // unlink or drop $uc->isUnlinkable() ? $db->queryNull($this->makeMassUpdateQuery($delete)) : $db->queryNull(OSQL::delete()->from($dao->getTable())->where(Expression::in($uc->getChildIdField(), $delete))); $dao->uncacheByIds($delete); } return $this; }
/** * @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; }
/** * only unlinking, we don't want to drop original object * * @return DeleteQuery **/ protected function makeDeleteQuery($delete) { $uc = $this->container; return OSQL::delete()->from($uc->getHelperTable())->where(Expression::eq(new DBField($uc->getParentIdField()), new DBValue($uc->getParentObject()->getId())))->andWhere(Expression::in($uc->getChildIdField(), $delete)); }
public function dropByIds(array $ids) { $result = DBPool::getByDao($this->dao)->queryCount(OSQL::delete()->from($this->dao->getTable())->where(Expression::in($this->dao->getIdName(), $ids))); $this->dao->uncacheByIds($ids); return $result; }