本文整理匯總了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();
}