本文整理汇总了PHP中Zotero_DB::rowQueryFromStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP Zotero_DB::rowQueryFromStatement方法的具体用法?PHP Zotero_DB::rowQueryFromStatement怎么用?PHP Zotero_DB::rowQueryFromStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zotero_DB
的用法示例。
在下文中一共展示了Zotero_DB::rowQueryFromStatement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadPrimaryData
private function loadPrimaryData($allowFail = false)
{
Z_Core::debug("Loading primary data for item {$this->libraryID}/{$this->key}");
if ($this->loaded['primaryData']) {
throw new Exception("Primary data already loaded for item {$this->libraryID}/{$this->key}");
}
$libraryID = $this->libraryID;
$id = $this->id;
$key = $this->key;
if (!$libraryID) {
throw new Exception("Library ID not set");
}
if (!$id && !$key) {
throw new Exception("ID or key not set");
}
// Use cached check for existence if possible
if ($libraryID && $key) {
if (!Zotero_Items::existsByLibraryAndKey($libraryID, $key)) {
$this->loaded['primaryData'] = true;
if ($allowFail) {
return false;
}
throw new Exception("Item " . ($id ? $id : "{$libraryID}/{$key}") . " not found");
}
}
$columns = array();
foreach (Zotero_Items::$primaryFields as $field) {
$colSQL = '';
if (is_null($field == 'itemID' ? $this->id : $this->{$field})) {
switch ($field) {
case 'itemID':
case 'itemTypeID':
case 'dateAdded':
case 'dateModified':
case 'libraryID':
case 'key':
case 'serverDateModified':
$colSQL = 'I.' . $field;
break;
case 'itemVersion':
$colSQL = 'I.version AS itemVersion';
break;
case 'numNotes':
$colSQL = '(SELECT COUNT(*) FROM itemNotes INo
WHERE sourceItemID=I.itemID AND INo.itemID NOT IN
(SELECT itemID FROM deletedItems)) AS numNotes';
break;
case 'numAttachments':
$colSQL = '(SELECT COUNT(*) FROM itemAttachments IA
WHERE sourceItemID=I.itemID AND IA.itemID NOT IN
(SELECT itemID FROM deletedItems)) AS numAttachments';
break;
case 'numNotes':
$colSQL = '(SELECT COUNT(*) FROM itemNotes
WHERE sourceItemID=I.itemID) AS numNotes';
break;
case 'numAttachments':
$colSQL = '(SELECT COUNT(*) FROM itemAttachments
WHERE sourceItemID=I.itemID) AS numAttachments';
break;
}
if ($colSQL) {
$columns[] = $colSQL;
}
}
}
if (!$columns) {
Z_Core::debug("No primary columns to load");
return;
}
$sql = 'SELECT ' . implode(', ', $columns) . " FROM items I WHERE ";
if ($id) {
if (!is_numeric($id)) {
trigger_error("Invalid itemID '{$id}'", E_USER_ERROR);
}
$sql .= "itemID=?";
$stmt = Zotero_DB::getStatement($sql, 'loadPrimaryData_id', Zotero_Shards::getByLibraryID($libraryID));
$row = Zotero_DB::rowQueryFromStatement($stmt, array($id));
} else {
if (!is_numeric($libraryID)) {
trigger_error("Invalid libraryID '{$libraryID}'", E_USER_ERROR);
}
if (!preg_match('/[A-Z0-9]{8}/', $key)) {
trigger_error("Invalid key '{$key}'!", E_USER_ERROR);
}
$sql .= "libraryID=? AND `key`=?";
$stmt = Zotero_DB::getStatement($sql, 'loadPrimaryData_key', Zotero_Shards::getByLibraryID($libraryID));
$row = Zotero_DB::rowQueryFromStatement($stmt, array($libraryID, $key));
}
$this->loaded['primaryData'] = true;
if (!$row) {
if ($allowFail) {
return false;
}
throw new Exception("Item " . ($id ? $id : "{$libraryID}/{$key}") . " not found");
}
$this->loadFromRow($row);
return true;
}
示例2: load
private function load()
{
$libraryID = $this->libraryID;
$id = $this->id;
$key = $this->key;
if (!$libraryID) {
throw new Exception("Library ID not set");
}
if (!$id && !$key) {
throw new Exception("ID or key not set");
}
// Cache tag data for the entire library
if (true) {
if ($id) {
Z_Core::debug("Loading data for tag {$this->libraryID}/{$this->id}");
$row = Zotero_Tags::getPrimaryDataByID($libraryID, $id);
} else {
Z_Core::debug("Loading data for tag {$this->libraryID}/{$this->key}");
$row = Zotero_Tags::getPrimaryDataByKey($libraryID, $key);
}
$this->loaded = true;
if (!$row) {
return;
}
if ($row['libraryID'] != $libraryID) {
throw new Exception("libraryID {$row['libraryID']} != {$this->libraryID}");
}
foreach ($row as $key => $val) {
$this->{$key} = $val;
}
} else {
// Use cached check for existence if possible
if ($libraryID && $key) {
if (!Zotero_Tags::existsByLibraryAndKey($libraryID, $key)) {
$this->loaded = true;
return;
}
}
$shardID = Zotero_Shards::getByLibraryID($libraryID);
$sql = Zotero_Tags::getPrimaryDataSQL();
if ($id) {
$sql .= "tagID=?";
$stmt = Zotero_DB::getStatement($sql, false, $shardID);
$data = Zotero_DB::rowQueryFromStatement($stmt, $id);
} else {
$sql .= "libraryID=? AND `key`=?";
$stmt = Zotero_DB::getStatement($sql, false, $shardID);
$data = Zotero_DB::rowQueryFromStatement($stmt, array($libraryID, $key));
}
$this->loaded = true;
if (!$data) {
return;
}
if ($data['libraryID'] != $libraryID) {
throw new Exception("libraryID {$data['libraryID']} != {$libraryID}");
}
foreach ($data as $k => $v) {
$this->{$k} = $v;
}
}
}