本文整理汇总了PHP中OCP\DB::insertIfNotExist方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::insertIfNotExist方法的具体用法?PHP DB::insertIfNotExist怎么用?PHP DB::insertIfNotExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\DB
的用法示例。
在下文中一共展示了DB::insertIfNotExist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInsertIfNotExistsViolatingThrows
/**
* @dataProvider insertIfNotExistsViolatingThrows
* @expectedException \Doctrine\DBAL\Exception\UniqueConstraintViolationException
*
* @param array $compareKeys
*/
public function testInsertIfNotExistsViolatingThrows($compareKeys)
{
$result = \OCP\DB::insertIfNotExist('*PREFIX*' . $this->table5, array('storage' => 1, 'path_hash' => md5('welcome.txt'), 'etag' => $this->getUniqueID()));
$this->assertEquals(1, $result);
$result = \OCP\DB::insertIfNotExist('*PREFIX*' . $this->table5, array('storage' => 1, 'path_hash' => md5('welcome.txt'), 'etag' => $this->getUniqueID()), $compareKeys);
$this->assertEquals(0, $result);
}
示例2: tagAs
/**
* Creates a tag/object relation.
*
* @param int $objid The id of the object
* @param string $tag The id or name of the tag
* @return boolean Returns false on error.
*/
public function tagAs($objid, $tag)
{
if (is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag);
if ($tag === '') {
\OCP\Util::writeLog('core', __METHOD__ . ', Cannot add an empty tag', \OCP\Util::DEBUG);
return false;
}
if (!$this->hasTag($tag)) {
$this->add($tag);
}
$tagId = $this->getTagId($tag);
} else {
$tagId = $tag;
}
try {
\OCP\DB::insertIfNotExist(self::RELATION_TABLE, array('objid' => $objid, 'categoryid' => $tagId, 'type' => $this->type));
} catch (\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
return true;
}