当前位置: 首页>>代码示例>>PHP>>正文


PHP Zotero_DB::getStatement方法代码示例

本文整理汇总了PHP中Zotero_DB::getStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP Zotero_DB::getStatement方法的具体用法?PHP Zotero_DB::getStatement怎么用?PHP Zotero_DB::getStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zotero_DB的用法示例。


在下文中一共展示了Zotero_DB::getStatement方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadCreators

	protected function loadCreators($reload = false) {
		if ($this->loaded['creators'] && !$reload) return;
		
		if (!$this->id) {
			trigger_error('Item ID not set for item before attempting to load creators', E_USER_ERROR);
		}
		
		if (!is_numeric($this->id)) {
			trigger_error("Invalid itemID '$this->id'", E_USER_ERROR);
		}
		
		if ($this->cacheEnabled) {
			$cacheVersion = 1;
			$cacheKey = $this->getCacheKey("itemCreators", $cacheVersion);
			$creators = Z_Core::$MC->get($cacheKey);
		}
		else {
			$creators = false;
		}
		if ($creators === false) {
			$sql = "SELECT creatorID, creatorTypeID, orderIndex FROM itemCreators
					WHERE itemID=? ORDER BY orderIndex";
			$stmt = Zotero_DB::getStatement($sql, true, Zotero_Shards::getByLibraryID($this->libraryID));
			$creators = Zotero_DB::queryFromStatement($stmt, $this->id);
			
			if ($this->cacheEnabled) {
				Z_Core::$MC->set($cacheKey, $creators ? $creators : array());
			}
		}
		
		$this->creators = [];
		$this->loaded['creators'] = true;
		$this->clearChanged('creators');
		
		if (!$creators) {
			return;
		}
		
		foreach ($creators as $creator) {
			$creatorObj = Zotero_Creators::get($this->libraryID, $creator['creatorID'], true);
			if (!$creatorObj) {
				Z_Core::$MC->delete($cacheKey);
				throw new Exception("Creator {$creator['creatorID']} not found");
			}
			$this->creators[$creator['orderIndex']] = array(
				'creatorTypeID' => $creator['creatorTypeID'],
				'ref' => $creatorObj
			);
		}
	}
开发者ID:kskod,项目名称:dataserver,代码行数:50,代码来源:Item.inc.php

示例2: loadItems

 private static function loadItems($libraryID, $itemIDs = array())
 {
     $shardID = Zotero_Shards::getByLibraryID($libraryID);
     $sql = self::getPrimaryDataSQL() . "1";
     // TODO: optimize
     if ($itemIDs) {
         foreach ($itemIDs as $itemID) {
             if (!is_int($itemID)) {
                 throw new Exception("Invalid itemID {$itemID}");
             }
         }
         $sql .= ' AND itemID IN (' . implode(',', array_fill(0, sizeOf($itemIDs), '?')) . ')';
     }
     $stmt = Zotero_DB::getStatement($sql, "loadItems_" . sizeOf($itemIDs), $shardID);
     $itemRows = Zotero_DB::queryFromStatement($stmt, $itemIDs);
     $loadedItemIDs = array();
     if ($itemRows) {
         foreach ($itemRows as $row) {
             if ($row['libraryID'] != $libraryID) {
                 throw new Exception("Item {$itemID} isn't in library {$libraryID}", Z_ERROR_OBJECT_LIBRARY_MISMATCH);
             }
             $itemID = $row['id'];
             $loadedItemIDs[] = $itemID;
             // Item isn't loaded -- create new object and stuff in array
             if (!isset(self::$objectCache[$itemID])) {
                 $item = new Zotero_Item();
                 $item->loadFromRow($row, true);
                 self::$objectCache[$itemID] = $item;
             } else {
                 self::$objectCache[$itemID]->loadFromRow($row, true);
             }
         }
     }
     if (!$itemIDs) {
         // If loading all items, remove old items that no longer exist
         $ids = array_keys(self::$objectCache);
         foreach ($ids as $id) {
             if (!in_array($id, $loadedItemIDs)) {
                 throw new Exception("Unimplemented");
                 //$this->unload($id);
             }
         }
     }
 }
开发者ID:ergo70,项目名称:dataserver,代码行数:44,代码来源:Items.inc.php

示例3: loadLinkedItems

 private function loadLinkedItems()
 {
     Z_Core::debug("Loading linked items for tag {$this->id}");
     if (!$this->id && !$this->key) {
         $this->linkedItemsLoaded = true;
         return;
     }
     if (!$this->loaded) {
         $this->load();
     }
     if (!$this->id) {
         $this->linkedItemsLoaded = true;
         return;
     }
     $sql = "SELECT itemID FROM itemTags WHERE tagID=?";
     $stmt = Zotero_DB::getStatement($sql, true, Zotero_Shards::getByLibraryID($this->libraryID));
     $ids = Zotero_DB::columnQueryFromStatement($stmt, $this->id);
     $this->linkedItems = array();
     if ($ids) {
         $this->linkedItems = Zotero_Items::get($this->libraryID, $ids);
     }
     $this->linkedItemsLoaded = true;
 }
开发者ID:robinpaulson,项目名称:dataserver,代码行数:23,代码来源:Tag.inc.php

示例4: loadRelatedItems

 private function loadRelatedItems()
 {
     if (!$this->id) {
         return;
     }
     Z_Core::debug("Loading related items for item {$this->id}");
     if ($this->loaded['relatedItems']) {
         trigger_error("Related items for item {$this->id} already loaded", E_USER_ERROR);
     }
     if (!$this->loaded['primaryData']) {
         $this->loadPrimaryData(true);
     }
     // TODO: use a prepared statement
     if (!is_numeric($this->id)) {
         trigger_error("Invalid itemID '{$this->id}'", E_USER_ERROR);
     }
     $cacheKey = $this->getCacheKey("itemRelated");
     //$ids = Z_Core::$MC->get($cacheKey);
     $ids = false;
     if ($ids === false) {
         $sql = "SELECT linkedItemID FROM itemRelated WHERE itemID=?";
         $stmt = Zotero_DB::getStatement($sql, true, Zotero_Shards::getByLibraryID($this->libraryID));
         $ids = Zotero_DB::columnQueryFromStatement($stmt, $this->id);
         Z_Core::$MC->set($cacheKey, $ids ? $ids : array());
     }
     $this->relatedItems = $ids ? $ids : array();
     $this->loaded['relatedItems'] = true;
 }
开发者ID:robinpaulson,项目名称:dataserver,代码行数:28,代码来源:Item.inc.php

示例5: save

 public function save($fixGaps = false)
 {
     if (!$this->libraryID) {
         throw new Exception("Library ID must be set before saving");
     }
     Zotero_Searches::editCheck($this);
     if (!$this->changed) {
         Z_Core::debug("Search {$this->id} has not changed");
         return false;
     }
     if (!isset($this->name) || $this->name === '') {
         throw new Exception("Name not provided for saved search");
     }
     $shardID = Zotero_Shards::getByLibraryID($this->libraryID);
     Zotero_DB::beginTransaction();
     $isNew = !$this->id || !$this->exists();
     try {
         $searchID = $this->id ? $this->id : Zotero_ID::get('savedSearches');
         Z_Core::debug("Saving search {$this->id}");
         if (!$isNew) {
             $sql = "DELETE FROM savedSearchConditions WHERE searchID=?";
             Zotero_DB::query($sql, $searchID, $shardID);
         }
         $key = $this->key ? $this->key : $this->generateKey();
         $fields = "searchName=?, libraryID=?, `key`=?, dateAdded=?, dateModified=?,\n\t\t\t\t\t\tserverDateModified=?";
         $timestamp = Zotero_DB::getTransactionTimestamp();
         $params = array($this->name, $this->libraryID, $key, $this->dateAdded ? $this->dateAdded : $timestamp, $this->dateModified ? $this->dateModified : $timestamp, $timestamp);
         $shardID = Zotero_Shards::getByLibraryID($this->libraryID);
         if ($isNew) {
             $sql = "INSERT INTO savedSearches SET searchID=?, {$fields}";
             $stmt = Zotero_DB::getStatement($sql, true, $shardID);
             Zotero_DB::queryFromStatement($stmt, array_merge(array($searchID), $params));
             Zotero_Searches::cacheLibraryKeyID($this->libraryID, $key, $searchID);
             // Remove from delete log if it's there
             $sql = "DELETE FROM syncDeleteLogKeys WHERE libraryID=? AND objectType='search' AND `key`=?";
             Zotero_DB::query($sql, array($this->libraryID, $key), $shardID);
         } else {
             $sql = "UPDATE savedSearches SET {$fields} WHERE searchID=?";
             $stmt = Zotero_DB::getStatement($sql, true, $shardID);
             Zotero_DB::queryFromStatement($stmt, array_merge($params, array($searchID)));
         }
         // Close gaps in savedSearchIDs
         $saveConditions = array();
         $i = 1;
         foreach ($this->conditions as $id => $condition) {
             if (!$fixGaps && $id != $i) {
                 trigger_error('searchConditionIDs not contiguous and |fixGaps| not set in save() of saved search ' . $this->id, E_USER_ERROR);
             }
             $saveConditions[$i] = $condition;
             $i++;
         }
         $this->conditions = $saveConditions;
         // TODO: use proper bound parameters once DB class is updated
         foreach ($this->conditions as $searchConditionID => $condition) {
             $sql = "INSERT INTO savedSearchConditions (searchID,\n\t\t\t\t\t\tsearchConditionID, `condition`, mode, operator,\n\t\t\t\t\t\tvalue, required) VALUES (?,?,?,?,?,?,?)";
             $sqlParams = array($searchID, $searchConditionID, $condition['condition'], $condition['mode'] ? $condition['mode'] : '', $condition['operator'] ? $condition['operator'] : '', $condition['value'] ? $condition['value'] : '', $condition['required'] ? 1 : 0);
             try {
                 Zotero_DB::query($sql, $sqlParams, $shardID);
             } catch (Exception $e) {
                 $msg = $e->getMessage();
                 if (strpos($msg, "Data too long for column 'value'") !== false) {
                     throw new Exception("=Value '" . mb_substr($condition['value'], 0, 75) . "…' too long in saved search '" . $this->name . "'");
                 }
                 throw $e;
             }
         }
         Zotero_DB::commit();
     } catch (Exception $e) {
         Zotero_DB::rollback();
         throw $e;
     }
     // If successful, set values in object
     if (!$this->id) {
         $this->id = $searchID;
     }
     if (!$this->key) {
         $this->key = $key;
     }
     return $this->id;
 }
开发者ID:robinpaulson,项目名称:dataserver,代码行数:80,代码来源:Search.inc.php

示例6: save

 public function save($userID = false)
 {
     if (!$this->libraryID) {
         throw new Exception("Library ID must be set before saving");
     }
     Zotero_Searches::editCheck($this, $userID);
     if (!$this->changed) {
         Z_Core::debug("Search {$this->id} has not changed");
         return false;
     }
     if (!isset($this->name) || $this->name === '') {
         throw new Exception("Name not provided for saved search");
     }
     $shardID = Zotero_Shards::getByLibraryID($this->libraryID);
     Zotero_DB::beginTransaction();
     $isNew = !$this->id || !$this->exists();
     try {
         $searchID = $this->id ? $this->id : Zotero_ID::get('savedSearches');
         Z_Core::debug("Saving search {$this->id}");
         if (!$isNew) {
             $sql = "DELETE FROM savedSearchConditions WHERE searchID=?";
             Zotero_DB::query($sql, $searchID, $shardID);
         }
         $key = $this->key ? $this->key : Zotero_ID::getKey();
         $fields = "searchName=?, libraryID=?, `key`=?, dateAdded=?, dateModified=?,\n\t\t\t\t\t\tserverDateModified=?, version=?";
         $timestamp = Zotero_DB::getTransactionTimestamp();
         $params = array($this->name, $this->libraryID, $key, $this->dateAdded ? $this->dateAdded : $timestamp, $this->dateModified ? $this->dateModified : $timestamp, $timestamp, Zotero_Libraries::getUpdatedVersion($this->libraryID));
         $shardID = Zotero_Shards::getByLibraryID($this->libraryID);
         if ($isNew) {
             $sql = "INSERT INTO savedSearches SET searchID=?, {$fields}";
             $stmt = Zotero_DB::getStatement($sql, true, $shardID);
             Zotero_DB::queryFromStatement($stmt, array_merge(array($searchID), $params));
             // Remove from delete log if it's there
             $sql = "DELETE FROM syncDeleteLogKeys WHERE libraryID=? AND objectType='search' AND `key`=?";
             Zotero_DB::query($sql, array($this->libraryID, $key), $shardID);
         } else {
             $sql = "UPDATE savedSearches SET {$fields} WHERE searchID=?";
             $stmt = Zotero_DB::getStatement($sql, true, $shardID);
             Zotero_DB::queryFromStatement($stmt, array_merge($params, array($searchID)));
         }
         foreach ($this->conditions as $searchConditionID => $condition) {
             $sql = "INSERT INTO savedSearchConditions (searchID,\n\t\t\t\t\t\tsearchConditionID, `condition`, mode, operator,\n\t\t\t\t\t\tvalue, required) VALUES (?,?,?,?,?,?,?)";
             $sqlParams = array($searchID, $searchConditionID + 1, $condition['condition'], $condition['mode'] ? $condition['mode'] : '', $condition['operator'] ? $condition['operator'] : '', $condition['value'] ? $condition['value'] : '', !empty($condition['required']) ? 1 : 0);
             try {
                 Zotero_DB::query($sql, $sqlParams, $shardID);
             } catch (Exception $e) {
                 $msg = $e->getMessage();
                 if (strpos($msg, "Data too long for column 'value'") !== false) {
                     throw new Exception("=Value '" . mb_substr($condition['value'], 0, 75) . "…' too long in saved search '" . $this->name . "'");
                 }
                 throw $e;
             }
         }
         Zotero_DB::commit();
     } catch (Exception $e) {
         Zotero_DB::rollback();
         throw $e;
     }
     if (!$this->id) {
         $this->id = $searchID;
     }
     if (!$this->key) {
         $this->key = $key;
     }
     return $this->id;
 }
开发者ID:juego11,项目名称:dataserver,代码行数:66,代码来源:Search.inc.php

示例7: save

 public function save()
 {
     if (!$this->libraryID) {
         trigger_error("Library ID must be set before saving", E_USER_ERROR);
     }
     Zotero_Creators::editCheck($this);
     // If empty, move on
     if ($this->firstName === '' && $this->lastName === '') {
         throw new Exception('First and last name are empty');
     }
     if ($this->fieldMode == 1 && $this->firstName !== '') {
         throw new Exception('First name must be empty in single-field mode');
     }
     if (!$this->hasChanged()) {
         Z_Core::debug("Creator {$this->id} has not changed");
         return false;
     }
     Zotero_DB::beginTransaction();
     try {
         $creatorID = $this->id ? $this->id : Zotero_ID::get('creators');
         $isNew = !$this->id;
         Z_Core::debug("Saving creator {$this->id}");
         $key = $this->key ? $this->key : $this->generateKey();
         $timestamp = Zotero_DB::getTransactionTimestamp();
         $dateAdded = $this->dateAdded ? $this->dateAdded : $timestamp;
         $dateModified = $this->changed['dateModified'] ? $this->dateModified : $timestamp;
         $fields = "firstName=?, lastName=?, fieldMode=?,\n\t\t\t\t\t\tlibraryID=?, `key`=?, dateAdded=?, dateModified=?, serverDateModified=?";
         $params = array($this->firstName, $this->lastName, $this->fieldMode, $this->libraryID, $key, $dateAdded, $dateModified, $timestamp);
         $shardID = Zotero_Shards::getByLibraryID($this->libraryID);
         try {
             if ($isNew) {
                 $sql = "INSERT INTO creators SET creatorID=?, {$fields}";
                 $stmt = Zotero_DB::getStatement($sql, true, $shardID);
                 Zotero_DB::queryFromStatement($stmt, array_merge(array($creatorID), $params));
                 // Remove from delete log if it's there
                 $sql = "DELETE FROM syncDeleteLogKeys WHERE libraryID=? AND objectType='creator' AND `key`=?";
                 Zotero_DB::query($sql, array($this->libraryID, $key), $shardID);
             } else {
                 $sql = "UPDATE creators SET {$fields} WHERE creatorID=?";
                 $stmt = Zotero_DB::getStatement($sql, true, $shardID);
                 Zotero_DB::queryFromStatement($stmt, array_merge($params, array($creatorID)));
             }
         } catch (Exception $e) {
             if (strpos($e->getMessage(), " too long") !== false) {
                 if (strlen($this->firstName) > 255) {
                     throw new Exception("=First name '" . mb_substr($this->firstName, 0, 50) . "…' too long");
                 }
                 if (strlen($this->lastName) > 255) {
                     if ($this->fieldMode == 1) {
                         throw new Exception("=Last name '" . mb_substr($this->lastName, 0, 50) . "…' too long");
                     } else {
                         throw new Exception("=Name '" . mb_substr($this->lastName, 0, 50) . "…' too long");
                     }
                 }
             }
             throw $e;
         }
         // The client updates the mod time of associated items here, but
         // we don't, because either A) this is from syncing, where appropriate
         // mod times come from the client or B) the change is made through
         // $item->setCreator(), which updates the mod time.
         //
         // If the server started to make other independent creator changes,
         // linked items would need to be updated.
         Zotero_DB::commit();
         Zotero_Creators::cachePrimaryData(array('id' => $creatorID, 'libraryID' => $this->libraryID, 'key' => $key, 'dateAdded' => $dateAdded, 'dateModified' => $dateModified, 'firstName' => $this->firstName, 'lastName' => $this->lastName, 'fieldMode' => $this->fieldMode));
     } catch (Exception $e) {
         Zotero_DB::rollback();
         throw $e;
     }
     // If successful, set values in object
     if (!$this->id) {
         $this->id = $creatorID;
     }
     if (!$this->key) {
         $this->key = $key;
     }
     $this->init();
     if ($isNew) {
         Zotero_Creators::cache($this);
         Zotero_Creators::cacheLibraryKeyID($this->libraryID, $key, $creatorID);
     }
     // TODO: invalidate memcache?
     return $this->id;
 }
开发者ID:robinpaulson,项目名称:dataserver,代码行数:85,代码来源:Creator.inc.php

示例8: loadItems

    private static function loadItems($libraryID, $itemIDs = array())
    {
        $shardID = Zotero_Shards::getByLibraryID($libraryID);
        $sql = 'SELECT I.*,
				(SELECT COUNT(*) FROM itemNotes INo
					WHERE sourceItemID=I.itemID AND INo.itemID NOT IN
					(SELECT itemID FROM deletedItems)) AS numNotes,
				(SELECT COUNT(*) FROM itemAttachments IA
					WHERE sourceItemID=I.itemID AND IA.itemID NOT IN
					(SELECT itemID FROM deletedItems)) AS numAttachments	
			FROM items I WHERE 1';
        // TODO: optimize
        if ($itemIDs) {
            foreach ($itemIDs as $itemID) {
                if (!is_int($itemID)) {
                    throw new Exception("Invalid itemID {$itemID}");
                }
            }
            $sql .= ' AND I.itemID IN (' . implode(',', array_fill(0, sizeOf($itemIDs), '?')) . ')';
        }
        $stmt = Zotero_DB::getStatement($sql, "loadItems_" . sizeOf($itemIDs), $shardID);
        $itemRows = Zotero_DB::queryFromStatement($stmt, $itemIDs);
        $loadedItemIDs = array();
        if ($itemRows) {
            foreach ($itemRows as $row) {
                if ($row['libraryID'] != $libraryID) {
                    throw new Exception("Item {$itemID} isn't in library {$libraryID}", Z_ERROR_OBJECT_LIBRARY_MISMATCH);
                }
                $itemID = $row['itemID'];
                $loadedItemIDs[] = $itemID;
                // Item isn't loaded -- create new object and stuff in array
                if (!isset(self::$itemsByID[$itemID])) {
                    $item = new Zotero_Item();
                    $item->loadFromRow($row, true);
                    self::$itemsByID[$itemID] = $item;
                } else {
                    self::$itemsByID[$itemID]->loadFromRow($row, true);
                }
            }
        }
        if (!$itemIDs) {
            // If loading all items, remove old items that no longer exist
            $ids = array_keys(self::$itemsByID);
            foreach ($ids as $id) {
                if (!in_array($id, $loadedItemIDs)) {
                    throw new Exception("Unimplemented");
                    //$this->unload($id);
                }
            }
            /*
            _cachedFields = ['itemID', 'itemTypeID', 'dateAdded', 'dateModified',
            	'numNotes', 'numAttachments', 'numChildren'];
            */
            //this._reloadCache = false;
        }
    }
开发者ID:robinpaulson,项目名称:dataserver,代码行数:56,代码来源:Items.inc.php

示例9: testPreparedStatement

 public function testPreparedStatement()
 {
     Zotero_DB::query("CREATE TABLE test (foo INTEGER NULL, foo2 INTEGER NULL DEFAULT NULL)");
     $stmt = Zotero_DB::getStatement("INSERT INTO test (foo) VALUES (?)");
     $stmt->execute(array(1));
     $stmt->execute(array(2));
     $result = Zotero_DB::columnQuery("SELECT foo FROM test");
     $this->assertEquals($result[0], 1);
     $this->assertEquals($result[1], 2);
 }
开发者ID:selenus,项目名称:dataserver,代码行数:10,代码来源:DBTest.php


注:本文中的Zotero_DB::getStatement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。