/** */ public function get($key, $lifetime = 0) { $okey = $key; $key = hash('md5', $key); $timestamp = time(); $maxage = $timestamp - $lifetime; /* Build SQL query. */ $query = 'SELECT cache_data FROM ' . $this->_params['table'] . ' WHERE cache_id = ?'; $values = array($key); // 0 lifetime checks for objects which have no expiration if ($lifetime != 0) { $query .= ' AND cache_timestamp >= ?'; $values[] = $maxage; } try { $result = $this->_db->selectValue($query, $values); $columns = $this->_db->columns($this->_params['table']); } catch (Horde_Db_Exception $e) { return false; } if (!$result) { /* No rows were found - cache miss */ if ($this->_logger) { $this->_logger->log(sprintf('Cache miss: %s (Id %s newer than %d)', $okey, $key, $maxage), 'DEBUG'); } return false; } if ($this->_logger) { $this->_logger->log(sprintf('Cache hit: %s (Id %s newer than %d)', $okey, $key, $maxage), 'DEBUG'); } return $columns['cache_data']->binaryToString($result); }
/** */ public function getMetaData($mailbox, $uidvalid, $entries) { $query = $this->_baseSql($mailbox, self::MD_TABLE); $query[0] = 'SELECT t.field, t.data ' . $query[0]; if (!empty($entries)) { $entries[] = 'uidvalid'; $entry_query = array(); foreach (array_unique($entries) as $val) { $entry_query[] = 't.field = ?'; $query[1][] = $val; } $query[0] .= ' AND (' . implode(' OR ', $entry_query) . ')'; } try { if ($res = $this->_db->selectAssoc($query[0], $query[1])) { $columns = $this->_db->columns(self::MD_TABLE); foreach ($res as $key => $val) { switch ($key) { case 'uidvalid': $res[$key] = $columns['data']->binaryToString($val); break; default: $res[$key] = @unserialize($columns['data']->binaryToString($val)); break; } } if (is_null($uidvalid) || !isset($res['uidvalid']) || $res['uidvalid'] == $uidvalid) { return $res; } $this->deleteMailbox($mailbox); } } catch (Horde_Db_Exception $e) { } return array(); }
/** * Converts results from TEXT columns to strings. * * @param string $column A column name. * @param mixed $value A TEXT column value. * * @return string The column value as plain string. */ protected function _convertBinary($column, $value) { try { $columns = $this->_db->columns($this->_params['table']); } catch (Horde_Db_Exception $e) { throw new Horde_Alarm_Exception(Horde_Alarm_Translation::t("Server error when querying database.")); } return $columns[$column]->binaryToString($value); }
/** */ public function get($scope_ob) { $charset = $this->_db->getOption('charset'); $query = 'SELECT pref_name, pref_value FROM ' . $this->_params['table'] . ' ' . 'WHERE pref_uid = ? AND pref_scope = ?'; $values = array($this->_params['user'], $scope_ob->scope); try { $result = $this->_db->selectAll($query, $values); $columns = $this->_db->columns($this->_params['table']); } catch (Horde_Db_Exception $e) { throw new Horde_Prefs_Exception($e); } foreach ($result as $row) { $name = trim($row['pref_name']); $value = $columns['pref_value']->binaryToString($row['pref_value']); $scope_ob->set($name, Horde_String::convertCharset($value, $charset, 'UTF-8')); } return $scope_ob; }
/** * Convert clob data to string. * * @param array &$data An array of share data. */ protected function _convertClobs(&$data) { $columns = $this->_db->columns($this->_table); foreach ($data as $row => &$value) { if (in_array($row, $this->_getClobFields())) { $value = $columns[$row]->binaryToString($value); } } }
/** * Attempts to open a connection to the SQL server. * * @throws Kronolith_Exception */ public function initialize() { if (empty($this->_params['db'])) { throw new InvalidArgumentException('Missing required Horde_Db_Adapter instance'); } try { $this->_db = $this->_params['db']; } catch (Horde_Exception $e) { throw new Kronolith_Exception($e); } $this->_columns = $this->_db->columns('kronolith_events'); }
/** */ protected function _getHash(array $alarm) { try { $columns = $this->_db->columns($this->_params['table']); } catch (Horde_Db_Exception $e) { throw new Horde_Alarm_Exception(Horde_Alarm_Translation::t("Server error when querying database.")); } $alarm['alarm_params'] = $columns['alarm_params']->binaryToString($alarm['alarm_params']); $params = base64_decode($alarm['alarm_params']); if (!strlen($params) && strlen($alarm['alarm_params'])) { $params = $alarm['alarm_params']; } return array('id' => $alarm['alarm_id'], 'user' => $alarm['alarm_uid'], 'start' => new Horde_Date($alarm['alarm_start'], 'UTC'), 'end' => empty($alarm['alarm_end']) ? null : new Horde_Date($alarm['alarm_end'], 'UTC'), 'methods' => @unserialize($alarm['alarm_methods']), 'params' => @unserialize($params), 'title' => $this->_fromDriver($alarm['alarm_title']), 'text' => $this->_fromDriver($alarm['alarm_text']), 'snooze' => empty($alarm['alarm_snooze']) ? null : new Horde_Date($alarm['alarm_snooze'], 'UTC'), 'internal' => empty($alarm['alarm_internal']) ? null : @unserialize($alarm['alarm_internal'])); }
/** */ public function read($id) { /* Begin a transaction. */ // TODO: Rowlocking in Mysql if (!$this->_db->transactionStarted()) { $this->_db->beginDbTransaction(); } /* Build query. */ $query = sprintf('SELECT session_data FROM %s WHERE session_id = ?', $this->_params['table']); $values = array($id); /* Execute the query. */ try { $columns = $this->_db->columns($this->_params['table']); return $columns['session_data']->binaryToString($this->_db->selectValue($query, $values)); } catch (Horde_Db_Exception $e) { return ''; } }
/** * Return the sync cache. * * @param string $devid The device id. * @param string $user The user id. * @param array $fields An array of fields to return. Default is to return * the full cache. @since 2.9.0 * * @return array The current sync cache for the user/device combination. * @throws Horde_ActiveSync_Exception */ public function getSyncCache($devid, $user, array $fields = null) { $sql = 'SELECT cache_data FROM ' . $this->_syncCacheTable . ' WHERE cache_devid = ? AND cache_user = ?'; try { $data = $this->_db->selectValue($sql, array($devid, $user)); $columns = $this->_db->columns($this->_syncCacheTable); $data = $columns['cache_data']->binaryToString($data); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } if (!($data = unserialize($data))) { $data = array('confirmed_synckeys' => array(), 'lasthbsyncstarted' => false, 'lastsyncendnormal' => false, 'timestamp' => false, 'wait' => false, 'hbinterval' => false, 'folders' => array(), 'hierarchy' => false, 'collections' => array(), 'pingheartbeat' => false, 'synckeycounter' => array()); } if (!is_null($fields)) { $data = array_intersect_key($data, array_flip($fields)); } return $data; }
protected function _parseRead($blobFields, $result, $dateFields = array()) { $results = array(); foreach ($result as $row) { $entry = array(); foreach ($row as $field => $val) { if (isset($blobFields[$field])) { if (!isset($columns)) { $columns = $this->_db->columns($this->_params['table']); } $entry[$field] = $columns[$field]->binaryToString($val); } elseif (isset($dateFields[$field]) && !empty($val)) { $d = new Horde_Date($val); $entry[$field] = $this->_convertFromDriver($d->strftime($GLOBALS['attributes'][array_search($field, $this->map)]['params']['format_in'])); } else { $entry[$field] = $this->_convertFromDriver($val); } } $results[] = $entry; } return $results; }
/** * Returns a list of Ansel_Images of the most recently added images for the * current user. * * @param array $galleries An array of gallery ids to search in. If * left empty, will search all galleries * with Horde_Perms::SHOW. * @param integer $limit The maximum number of images to return * @param string $slugs An array of gallery slugs. * @param string $where Additional where clause * * @return array An array of Ansel_Image objects * @throws Ansel_Exception */ public function getRecentImages(array $galleries = array(), $limit = 10, array $slugs = array()) { $results = array(); if (!count($galleries) && !count($slugs)) { // Don't need the Ansel_Gallery object, so save some resources and // only query the share system. foreach ($this->_shares->listShares($GLOBALS['registry']->getAuth()) as $share) { $galleries[] = $share->getId(); } if (empty($galleries)) { return array(); } } if (!count($slugs)) { // Searching by gallery_id $sql = 'SELECT ' . $this->_getImageFields() . ' FROM ansel_images ' . 'WHERE gallery_id IN (' . str_repeat('?, ', count($galleries) - 1) . '?) '; $criteria = $galleries; } elseif (count($slugs)) { // Searching by gallery_slug so we need to join the share table $sql = 'SELECT ' . $this->_getImageFields() . ' FROM ansel_images LEFT JOIN ' . $this->_shares->getTable() . ' ON ansel_images.gallery_id = ' . $this->_shares->getTable() . '.share_id ' . 'WHERE attribute_slug IN (' . str_repeat('?, ', count($slugs) - 1) . '?) '; $criteria = $slugs; } $sql .= ' ORDER BY image_uploaded_date DESC'; if ($limit > 0) { $sql = $this->_db->addLimitOffset($sql, array('limit' => (int) $limit)); } try { $images = $this->_db->select($sql, $criteria); } catch (Horde_Db_Exception $e) { throw new Ansel_Exception($e); } $columns = $this->_db->columns('ansel_images'); foreach ($images as $image) { $image['image_filename'] = Horde_String::convertCharset($image['image_filename'], $GLOBALS['conf']['sql']['charset'], 'UTF-8'); $image['image_caption'] = Horde_String::convertCharset($columns['image_caption']->binaryToString($image['image_caption']), $GLOBALS['conf']['sql']['charset'], 'UTF-8'); $results[] = new Ansel_Image($image); } return $results; }