public function getMany($num = 50) { $tasks = array(); $values = array(); $query = 'SELECT * FROM horde_queue_tasks where task_queue = ? ORDER BY task_id LIMIT ?'; $values[] = $this->_queue; $values[] = $num; try { $rows = $this->_db->select($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Queue_Exception($e); } $query = 'DELETE FROM horde_queue_tasks WHERE task_id = ?'; foreach ($rows as $row) { $tasks[] = unserialize($row['task_fields']); // TODO: Evaluate if a single call for all IDs is faster for // various scenarios try { $this->_db->delete($query, array($row['task_id'])); } catch (Horde_Db_Exception $e) { throw new Horde_Queue_Exception($e); } } return $tasks; }
/** * Retrieves the foos from the database. * * @throws Kolab_Exception */ public function retrieve() { /* Build the SQL query. */ $query = 'SELECT * FROM ' . $this->_params['table'] . ' WHERE foo = ?'; $values = array($this->_params['bar']); /* Execute the query. */ try { $rows = $this->_db->selectAll($query, $values); } catch (Horde_Db_Exception $e) { throw new Kolab_Exception($e); } /* Store the retrieved values in the foo variable. */ $this->_foo = array_merge($this->_foo, $rows); }
/** * Reset the sync state for this device, for the specified collection. * * @param string $id The collection to reset. * * @return void * @throws Horde_ActiveSync_Exception */ protected function _resetDeviceState($id) { $this->_logger->info(sprintf('[%s] Resetting device state for device: %s, user: %s, and collection: %s.', $this->_procid, $this->_deviceInfo->id, $this->_deviceInfo->user, $id)); $state_query = 'DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; $map_query = 'DELETE FROM ' . $this->_syncMapTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; $mailmap_query = 'DELETE FROM ' . $this->_syncMailMapTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; try { $this->_db->delete($state_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); $this->_db->delete($map_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); $this->_db->delete($mailmap_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } // Remove the collection data from the synccache as well. $cache = new Horde_ActiveSync_SyncCache($this, $this->_deviceInfo->id, $this->_deviceInfo->user, $this->_logger); if ($id != Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) { $cache->removeCollection($id, false); } else { $this->_logger->notice(sprintf('[%s] Clearing foldersync state from synccache.', $this->_procid)); $cache->clearFolders(); $cache->clearCollections(); $cache->hierarchy = '0'; } $cache->save(); }
/** * Modifies a SQL password record for a user. * * @param string $user The user whose record we will udpate. * @param string $newpass The new password value to set. * * @throws Passwd_Exception */ protected function _modify($user, $newpass) { /* Only split up username if domain is set in backend. */ if ($this->_params['domain']) { list($name, $domain) = explode('@', $user); } else { $name = $user; } /* Encrypt the password. */ $clear_password = $newpass; $newpass = $this->_encryptPassword($newpass); /* Build the SQL query. */ $sql = 'UPDATE ' . $this->_params['table'] . ' SET ' . $this->_params['passwd'] . ' = ?'; $values = array($newpass); if ($this->_params['use_clear_passwd']) { $sql .= ', ' . $this->_params['clear_passwd'] . ' = ?'; $values[] = $clear_password; } $sql .= ' WHERE ' . $this->_params['name'] . ' = ?'; $values[] = $name; if ($this->_params['domain']) { $sql .= ' AND ' . $this->_params['domain'] . ' = ?'; $values[] = $domain; } /* Execute the query. */ try { $this->_db->update($sql, $values); } catch (Horde_Db_Exception $e) { throw new Passwd_Exception($e); } }
/** * Constructor. * * @param Horde_Db_Adapter $connection A DB connection object. * @param Horde_Log_Logger $logger A logger object. * @param array $options Additional options for the migrator: * - migrationsPath: directory with the * migration files. * - schemaTableName: table for storing * the schema version. * * @throws Horde_Db_Migration_Exception */ public function __construct(Horde_Db_Adapter $connection, Horde_Log_Logger $logger = null, array $options = array()) { if (!$connection->supportsMigrations()) { throw new Horde_Db_Migration_Exception('This database does not yet support migrations'); } $this->_connection = $connection; $this->_logger = $logger ? $logger : new Horde_Support_Stub(); $this->_inflector = new Horde_Support_Inflector(); if (isset($options['migrationsPath'])) { $this->_migrationsPath = $options['migrationsPath']; } if (isset($options['schemaTableName'])) { $this->_schemaTableName = $options['schemaTableName']; } $this->_initializeSchemaInformation(); }
/** * Returns an Amavisd-new policy for storage and retrieval. * * @return string The results of the of the policy lookup. Can be the ID * of the policy, false if not found. * @throws Sam_Exception */ protected function _lookupPolicyID() { try { return $this->_db->selectValue(sprintf('SELECT %s FROM %s WHERE %s = ?', $this->_mapAttributeToField('policies', 'id'), $this->_mapNameToTable('policies'), $this->_mapAttributeToField('policies', 'name')), array($this->_user)); } catch (Horde_Db_Exception $e) { return false; } }
/** * Deletes an ID map from the backend storage. * * @param string $external An external collection ID. * @param string $interface The collection's application. * * @throws Horde_Dav_Exception */ public function deleteExternalCollectionId($external, $interface) { try { $this->_db->delete('DELETE FROM horde_dav_collections ' . 'WHERE id_external = ? AND id_interface = ?', array($external, $interface)); } catch (Horde_Db_Exception $e) { throw new Horde_Dav_Exception($e); } }
/** * Get a list of all known styleHashes. * * @return array An array of style hashes. */ public function getHashes() { try { return $this->_db->selectValues('SELECT style_hash FROM ansel_hashes'); } catch (Horde_Db_Exception $e) { throw new Ansel_Exception($e); } }
/** * Searches for group names. * * @param string $name A search string. * * @return array A list of matching groups, with IDs as keys and names as * values. * @throws Horde_Group_Exception */ public function search($name) { try { return $this->_db->selectAssoc('SELECT group_uid, group_name FROM horde_groups WHERE group_name LIKE ?', array('%' . $name . '%')); } catch (Horde_Db_Exception $e) { throw new Horde_Group_Exception($e); } }
/** * Gets the next field order position within a form. * * @param integer $form_id * * @return integer * @throws Ulaform_Exception */ protected function _nextFieldOrder($form_id) { $sql = 'SELECT MAX(field_order) FROM ulaform_fields WHERE form_id = ?'; try { return $this->_db->selectValue($sql, array($form_id)) + 1; } catch (Horde_Db_Exception $e) { throw new Ulaform_Exception($e->getMessage); } }
/** * 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); }
/** * Lists all available scopes. * * @return array The list of scopes stored in the backend. */ public function listScopes() { $query = 'SELECT ' . $this->_db->distinct('pref_scope') . ' FROM ' . $this->_params['table']; try { return $this->_db->selectValues($query); } catch (Horde_Db_Exception $e) { throw new Horde_Prefs_Exception($e); } }
/** * Deletes an entry from storage * * @see Kronolith_Geo_Base#removeLocation() * * @param string $event_id * * @throws Kronolith_Exception */ public function deleteLocation($event_id) { $sql = 'DELETE FROM kronolith_events_geo WHERE event_id = ?'; try { $this->_db->delete($sql, array($event_id)); } catch (Horde_Db_Exception $e) { throw new Horde_Exception($e); } }
/** */ public function clear() { $query = 'DELETE FROM ' . $this->_params['table']; try { $this->_db->delete($query); } catch (Horde_Db_Exception $e) { throw new Horde_Cache_Exception($e); } }
/** */ protected function _deleteOldEntries($before) { /* Build the SQL query. */ $query = sprintf('DELETE FROM %s WHERE sentmail_ts < ?', $this->_params['table']); /* Execute the query. */ try { $this->_db->delete($query, array($before)); } catch (Horde_Db_Exception $e) { } }
/** * Stores a foo in the database. * * @throws Sms_Exception */ public function store($data) { $query = 'INSERT INTO skeleton_items' . ' (item_owner, item_data)' . ' VALUES (?, ?)'; $values = array($GLOBALS['registry']->getAuth(), $data); try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Sms_Exception($e->getMessage()); } }
/** * Stores user preferences and default values in the backend. * * @param boolean $defaults Whether to store the global defaults instead * of user options. * * @throws Sam_Exception */ public function store($defaults = false) { if ($defaults) { $store = $this->_defaults; $user = $this->_params['global_user']; } else { $store = $this->_options; $user = $this->_user; } foreach ($store as $attribute => $value) { $option = $this->_mapAttributeToOption($attribute); /* Delete the option if it is the same as the default */ if (!$defaults && isset($this->_defaults[$attribute]) && $this->_defaults[$attribute] === $value) { try { $this->_db->delete('DELETE FROM ' . $this->_params['table'] . ' WHERE username = ? AND preference = ?', array($user, $option)); } catch (Horde_Db_Exception $e) { throw new Sam_Exception($e); } continue; } if (is_array($value)) { try { $this->_db->delete('DELETE FROM ' . $this->_params['table'] . ' WHERE username = ? AND preference = ?', array($user, $option)); } catch (Horde_Db_Exception $e) { throw new Sam_Exception($e); } foreach ($value as $address) { /* Don't save email addresses already in defaults. */ if (!$defaults && isset($this->_defaults[$attribute]) && (is_array($this->_defaults[$attribute]) && in_array($address, $this->_defaults[$attribute]) || $this->_defaults[$attribute] === $address)) { continue; } try { $this->_db->insert('INSERT INTO ' . $this->_params['table'] . ' (username, preference, value)' . ' VALUES (?, ?, ?)', array($user, $option, $address)); } catch (Horde_Db_Exception $e) { throw new Sam_Exception($e); } } } else { try { $result = $this->_db->selectValue('SELECT 1 FROM ' . $this->_params['table'] . ' WHERE username = ? AND preference = ?', array($user, $option)); } catch (Horde_Db_Exception $e) { throw new Sam_Exception($e); } try { if (!$result) { $this->_db->insert('INSERT INTO ' . $this->_params['table'] . ' (username, preference, value)' . ' VALUES (?, ?, ?)', array($user, $option, $value)); } else { $this->_db->insert('UPDATE ' . $this->_params['table'] . ' SET value = ?' . ' WHERE username = ? AND preference = ?', array($value, $user, $option)); } } catch (Horde_Db_Exception $e) { throw new Sam_Exception($e); } } } }
/** * Implementation of the rewind() method for iterator. */ public function rewind() { if ($this->_result) { unset($this->_result); } $this->_current = null; $this->_index = null; $this->_eof = true; $this->_result = $this->_adapter->execute($this->_sql, $this->_arg1, $this->_arg2); $this->next(); }
/** * Add a token ID. * * @param string $tokenID Token ID to add. * * @throws Horde_Token_Exception */ public function add($tokenID) { /* Build SQL query. */ $query = 'INSERT INTO ' . $this->_params['table'] . ' (token_address, token_id, token_timestamp)' . ' VALUES (?, ?, ?)'; $values = array($this->_encodeRemoteAddress(), $tokenID, time()); try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Token_Exception($e); } }
/** * Returns all permissions of the system in a tree format. * * @return array A hash with all permissions in a tree format. * @throws Horde_Perms_Exception */ public function getTree() { $query = 'SELECT perm_id, perm_name FROM ' . $this->_params['table'] . ' ORDER BY perm_name ASC'; try { $tree = $this->_db->selectAssoc($query); } catch (Horde_Db_Exception $e) { throw new Horde_Perms_Exception($e); } $tree[Horde_Perms::ROOT] = Horde_Perms::ROOT; return $tree; }
/** * Checks if a userId exists in the system. * * @param string $userId User ID for which to check * * @return boolean Whether or not the userId already exists. */ public function exists($userId) { /* Build the SQL query. */ $query = sprintf('SELECT 1 FROM %s WHERE %s = ?', $this->_params['table'], $this->_params['username_field']); $values = array($userId); try { return (bool) $this->_db->selectValue($query, $values); } catch (Horde_Db_Exception $e) { return false; } }
/** * Utility function to convert TO the SQL server's charset. * * @see Horde_Share#toDriverCharset */ public function toDriverCharset($data) { if (!is_array($data)) { return $data; } foreach ($data as $key => &$value) { if (substr($key, 0, 9) == 'attribute') { $value = Horde_String::convertCharset($value, 'UTF-8', $this->_db->getOption('charset')); } } return $data; }
/** * Store the freebusy information for a given email address. * * @param string $email The email address to store fb info for. * @param Horde_Icalendar_Vfreebusy $vfb TODO * @param boolean $private_only (optional) TODO * * @throws Kronolith_Exception */ public function store($email, $vfb, $public = false) { /* Build the SQL query. */ $query = sprintf('INSERT INTO %s (vfb_owner, vfb_email, vfb_serialized) VALUES (?, ?, ?)', $this->_params['table']); $values = array($public ? '' : $this->_user, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC)); /* Execute the query. */ try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Kronolith_Exception($e); } }
/** * 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'); }
/** */ public function getSessionIDs() { $this->open(); /* Build the SQL query. */ $query = sprintf('SELECT session_id FROM %s' . ' WHERE session_lastmodified >= ?', $this->_params['table']); $values = array(time() - ini_get('session.gc_maxlifetime')); /* Execute the query. */ try { return $this->_db->selectValues($query, $values); } catch (Horde_Db_Exception $e) { return array(); } }
/** * Do garbage collection needed for the driver. */ public function doGC() { $now = time(); $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE ' . 'lock_expiry_timestamp < ? AND lock_expiry_timestamp != ?'; $values = array($now, Horde_Lock::PERMANENT); try { $result = $this->_db->delete($query, $values); if ($this->_logger) { $this->_logger->log(sprintf('Lock garbage collection cleared %d locks.', $result), 'DEBUG'); } } catch (Horde_Db_Exception $e) { } }
/** * Initialization tasks. * * @throws Horde_Alarm_Exception */ public function initialize() { /* Handle any database specific initialization code to run. */ switch ($this->_db->adapterName()) { case 'PDO_Oci': $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"; $this->_db->select($query); break; case 'PDO_PostgreSQL': $query = "SET datestyle TO 'iso'"; $this->_db->select($query); break; } }
/** * Gets the latest entry of $guid * * @param string $guid The name of the history entry to retrieve. * @param boolean $use_ts If false we use the 'modseq' field to determine * the latest entry. If true we use the timestamp * instead of modseq to determine the latest entry. * Note: Only 'modseq' can give a definitive answer. * * @return array|boolean The latest history entry, or false if $guid does not exist. * * @throws Horde_History_Exception If the input parameters are not of type string. * @since 2.2.0 */ public function getLatestEntry($guid, $use_ts = false) { $query = 'SELECT * from horde_histories WHERE object_uid = ? ORDER BY '; if ($use_ts) { $query .= 'history_ts '; } else { $query .= 'history_modseq '; } $query .= 'DESC LIMIT 1'; $row = $this->_db->selectOne($query, array($guid)); if (empty($row['history_id'])) { return false; } $log = new Horde_History_Log($guid, array($row)); return $log[0]; }
/** */ public function sort($rules) { $old = $this->_filters; parent::sort($rules); $query = sprintf('UPDATE %s SET rule_order = ? WHERE rule_id = ?', $this->_params['table_rules']); $this->_db->beginDbTransaction(); try { foreach ($this->_filters as $key => $val) { $this->_db->update($query, array($key, $val['id'])); } } catch (Horde_Db_Exception $e) { $this->_db->rollbackDbTransaction(); $this->_filters = $old; throw new Ingo_Exception($e); } $this->_db->commitDbTransaction(); }
/** * Modifies a SQL password record for a user. * * @param string $user The user whose record we will udpate. * @param string $newpass The new password value to set. * * @throws Passwd_Exception */ protected function _modify($user, $newpass) { if (!empty($this->_params['query_modify'])) { list($sql, $values) = $this->_parseQuery($this->_params['query_modify'], $user, $newpass); } else { /* Encrypt the password. */ $newpass = $this->_encryptPassword($newpass); /* Build the SQL query. */ $sql = 'UPDATE ' . $this->_params['table'] . ' SET ' . $this->_params['pass_col'] . ' = ?' . ' WHERE ' . $this->_params['user_col'] . ' = ?'; $values = array($newpass, $user); } /* Execute the query. */ try { $this->_db->update($sql, $values); } catch (Horde_Db_Exception $e) { throw new Passwd_Exception($e); } }