本文整理汇总了PHP中OC\DB\Connection::getQueryBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::getQueryBuilder方法的具体用法?PHP Connection::getQueryBuilder怎么用?PHP Connection::getQueryBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\DB\Connection
的用法示例。
在下文中一共展示了Connection::getQueryBuilder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRemoveDeletedFiles
/**
* @dataProvider dataTestRemoveDeletedFiles
* @param boolean $nodeExists
*/
public function testRemoveDeletedFiles($nodeExists)
{
$this->initTable();
$this->rootFolder->expects($this->once())->method('nodeExists')->with('/' . $this->user0 . '/files_trashbin')->willReturn($nodeExists);
if ($nodeExists) {
$this->rootFolder->expects($this->once())->method('get')->with('/' . $this->user0 . '/files_trashbin')->willReturn($this->rootFolder);
$this->rootFolder->expects($this->once())->method('delete');
} else {
$this->rootFolder->expects($this->never())->method('get');
$this->rootFolder->expects($this->never())->method('delete');
}
$this->invokePrivate($this->cleanup, 'removeDeletedFiles', [$this->user0]);
if ($nodeExists) {
// if the delete operation was execute only files from user1
// should be left.
$query = $this->dbConnection->getQueryBuilder();
$result = $query->select('user')->from($this->trashTable)->execute()->fetchAll();
$this->assertSame(5, count($result));
foreach ($result as $r) {
$this->assertSame('user1', $r['user']);
}
} else {
// if no delete operation was execute we should still have all 10
// database entries
$getAllQuery = $this->dbConnection->getQueryBuilder();
$result = $getAllQuery->select('id')->from($this->trashTable)->execute()->fetchAll();
$this->assertSame(10, count($result));
}
}
示例2: copyTable
protected function copyTable(Connection $fromDB, Connection $toDB, $table, InputInterface $input, OutputInterface $output)
{
$chunkSize = $input->getOption('chunk-size');
/** @var $progress \Symfony\Component\Console\Helper\ProgressHelper */
$progress = $this->getHelperSet()->get('progress');
$query = $fromDB->getQueryBuilder();
$query->automaticTablePrefix(false);
$query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries')->from($table);
$result = $query->execute();
$count = $result->fetchColumn();
$result->closeCursor();
$numChunks = ceil($count / $chunkSize);
if ($numChunks > 1) {
$output->writeln('chunked query, ' . $numChunks . ' chunks');
}
$progress->start($output, $count);
$redraw = $count > $chunkSize ? 100 : ($count > 100 ? 5 : 1);
$progress->setRedrawFrequency($redraw);
$query = $fromDB->getQueryBuilder();
$query->automaticTablePrefix(false);
$query->select('*')->from($table)->setMaxResults($chunkSize);
$insertQuery = $toDB->getQueryBuilder();
$insertQuery->automaticTablePrefix(false);
$insertQuery->insert($table);
$parametersCreated = false;
for ($chunk = 0; $chunk < $numChunks; $chunk++) {
$query->setFirstResult($chunk * $chunkSize);
$result = $query->execute();
while ($row = $result->fetch()) {
$progress->advance();
if (!$parametersCreated) {
foreach ($row as $key => $value) {
$insertQuery->setValue($key, $insertQuery->createParameter($key));
}
$parametersCreated = true;
}
foreach ($row as $key => $value) {
$insertQuery->setParameter($key, $value);
}
$insertQuery->execute();
}
$result->closeCursor();
}
$progress->finish();
}