public function testGetNotSetDatabase() { phpillowCustomConnection::createInstance(); try { phpillowConnection::getDatabase(); $this->fail('Expected phpillowBackendCouchNoDatabaseException.'); } catch (phpillowNoDatabaseException $e) { /* Expected exception */ } }
/** * Query a view * * Query the specified view to get a set of results. You may optionally use * the view query options as additional parameters to limit the returns * values, specified at: * http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options * * @param string $view * @param array $options * @return phpillowResultArray */ public function query($view, array $options = array()) { // Build query string, just as a normal HTTP GET query string $url = phpillowConnection::getDatabase() . '_design/' . $this->getViewName() . '/_view/' . $view; $url .= $this->buildViewQuery($options); // Get database connection, because we directly execute a query here. $db = phpillowConnection::getInstance(); try { // Try to execute query, a failure most probably means, the view // has not been added, yet. $response = $db->get($url); } catch (phpillowResponseErrorException $e) { // Ensure view has been created properly and then try to execute // the query again. If it still fails, there is most probably a // real problem. $this->verifyView(); $response = $db->get($url); } return $response; }
function couchDelete($id, $rev) { // phpillowConnection::__call("delete",""); $db = phpillowConnection::getInstance(); $response = $db->__call("delete", array(0 => phpillowConnection::getDatabase() . urlencode($id) . "?rev=" . $rev)); }
/** * Get file contents * * Get the contents of an attached file as a phpillowDataResponse. * * @param string $fileName * @return phpillowDataResponse */ public function getFile($fileName) { if (!isset($this->storage->_attachments[$fileName])) { throw new phpillowNoSuchPropertyException($fileName); } $db = phpillowConnection::getInstance(); $response = $db->get(phpillowConnection::getDatabase() . urlencode($this->_id) . '/' . $fileName, null, true); return $response; }
/** * Return used database * * This should always used within a document instead of * phpillowConnection::getDatabase() * * @return phpillowConnection */ public function getDatabase() { if ($this->database === null) { return phpillowConnection::getDatabase(); } return $this->database; }