Inserts a row into a table.
public insert ( string $sql, array | string $arg1 = null, string $arg2 = null, string $pk = null, integer $idValue = null, string $sequenceName = null ) : integer | ||
$sql | string | SQL statement. |
$arg1 | array | string | Either an array of bound parameters or a query name. |
$arg2 | string | If $arg1 contains bound parameters, the query name. |
$pk | string | The primary key column. |
$idValue | integer | The primary key value. This parameter is required if the primary key is inserted manually. |
$sequenceName | string | The sequence name. |
리턴 | integer | Last inserted ID. |
/** * Ensure that an array of types exist in storage. Create any that don't, * return type_ids for all. * * @param mixed $types An array of types or single type value. Values typed * as an integer are assumed to already be an type_id. * * @return array An array of type_ids. * @throws Content_Exception */ public function ensureTypes($types) { if (!is_array($types)) { $types = array($types); } $typeIds = array(); $typeName = array(); // Anything already typed as an integer is assumed to be a type id. foreach ($types as $typeIndex => $type) { if (is_int($type)) { $typeIds[$typeIndex] = $type; } else { $typeName[$type] = $typeIndex; } } try { // Get the ids for any types that already exist. if (count($typeName)) { $rows = $this->_db->selectAssoc('SELECT type_id, type_name FROM ' . $this->_t('types') . ' WHERE type_name IN (' . implode(',', array_map(array($this->_db, 'quoteString'), array_keys($typeName))) . ')'); foreach ($rows as $id => $type) { $typeIndex = $typeName[$type]; unset($typeName[$type]); $typeIds[$typeIndex] = (int) $id; } } // Create any types that didn't already exist foreach ($typeName as $type => $typeIndex) { $typeIds[$typeIndex] = intval($this->_db->insert('INSERT INTO ' . $this->_t('types') . ' (type_name) VALUES (' . $this->_db->quoteString($type) . ')')); } } catch (Horde_Db_Exception $e) { throw new Content_Exception($e); } return $typeIds; }
/** * Ensure that an array of users exist in storage. Create any that don't, * return user_ids for all. * * @param array $users An array of users. Values typed as an integer * are assumed to already be an user_id. * * @return array An array of user_ids. */ public function ensureUsers($users) { if (!is_array($users)) { $users = array($users); } $userIds = array(); $userName = array(); // Anything already typed as an integer is assumed to be a user id. foreach ($users as $userIndex => $user) { if (is_int($user)) { $userIds[$userIndex] = $user; } else { $userName[$user] = $userIndex; } } // Get the ids for any users that already exist. try { if (count($userName)) { $userName; $sql = 'SELECT user_id, user_name FROM ' . $this->_t('users') . ' WHERE user_name IN (' . implode(',', array_map(array($this, 'toDriver'), array_keys($userName))) . ')'; foreach ($this->_db->selectAll($sql) as $row) { $userIndex = $userName[$row['user_name']]; unset($userName[$row['user_name']]); $userIds[$userIndex] = $row['user_id']; } } // Create any users that didn't already exist foreach ($userName as $user => $userIndex) { $userIds[$userIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('users') . ' (user_name) VALUES (' . $this->toDriver($user) . ')'); } } catch (Horde_Db_Exception $e) { throw new Content_Exception($e); } return $userIds; }
/** * Set the location of the specified event _id * * @see Kronolith_Geo_Base#setLocation() * @throws Kronolith_Exception */ public function setLocation($event_id, $point) { /* First make sure it doesn't already exist */ $sql = 'SELECT COUNT(*) FROM kronolith_events_geo WHERE event_id = ?'; try { $count = $this->_db->selectValue($sql, array($event_id)); } catch (Horde_Db_Exception $e) { throw new Kronolith_Exception($e); } /* Do we actually have data? If not, see if we are deleting an * existing entry. */ if ((empty($point['lat']) || empty($point['lon'])) && $count) { // Delete the record. $this->deleteLocation($event_id); return; } elseif (empty($point['lat']) || empty($point['lon'])) { return; } if (empty($point['zoom'])) { $point['zoom'] = 0; } /* INSERT or UPDATE */ $params = array($point['lat'], $point['lon'], $point['zoom'], $event_id); try { if ($count) { $sql = 'UPDATE kronolith_events_geo SET event_lat = ?, event_lon = ?, event_zoom = ? WHERE event_id = ?'; $this->_db->update($sql, $params); } else { $sql = 'INSERT into kronolith_events_geo (event_lat, event_lon, event_zoom, event_id) VALUES(?, ?, ?, ?)'; $this->_db->insert($sql, $params); } } catch (Horde_Db_Exception $e) { throw new Horde_Exception($e); } }
/** * Adds a collection ID map to the backend storage. * * @param string $internal An internal collection ID. * @param string $external An external collection ID. * @param string $interface The collection's application. * * @throws Horde_Dav_Exception */ public function addCollectionMap($internal, $external, $interface) { try { $this->_db->insert('INSERT INTO horde_dav_collections (id_internal, id_external, id_interface) ' . 'VALUES (?, ?, ?)', array($internal, $external, $interface)); } catch (Horde_Db_Exception $e) { throw new Horde_Dav_Exception($e); } }
/** * Serialize a task to the database * @param Horde_Queue_Task $task A task to serialize * @throws Horde_Queue_Exception */ public function add(Horde_Queue_Task $task) { $values = array($this->_queue, serialize($task)); $query = 'INSERT INTO horde_queue_tasks (task_queue, task_fields) VALUES(?, ?)'; try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Queue_Exception($e); } }
/** */ protected function _log($action, $message_id, $recipient, $success) { /* Build the SQL query. */ $query = sprintf('INSERT INTO %s (sentmail_who, sentmail_ts, sentmail_messageid, sentmail_action, sentmail_recipient, sentmail_success) VALUES (?, ?, ?, ?, ?, ?)', $this->_params['table']); $values = array($GLOBALS['registry']->getAuth(), time(), $message_id, $action, $recipient, intval($success)); /* Execute the query. */ try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { } }
/** */ public function set($key, $data, $lifetime = 0) { $okey = $key; $key = hash('md5', $key); $timestamp = time(); // 0 lifetime indicates the object should not be GC'd. $expiration = $lifetime === 0 ? 0 : $lifetime + $timestamp; if ($this->_logger) { $this->_logger->log(sprintf('Cache set: %s (Id %s set at %d expires at %d)', $okey, $key, $timestamp, $expiration), 'DEBUG'); } // Remove any old cache data and prevent duplicate keys $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE cache_id=?'; $values = array($key); try { $this->_db->delete($query, $values); } catch (Horde_Db_Exception $e) { } /* Build SQL query. */ $query = 'INSERT INTO ' . $this->_params['table'] . ' (cache_id, cache_timestamp, cache_expiration, cache_data)' . ' VALUES (?, ?, ?, ?)'; $values = array($key, $timestamp, $expiration, $data); try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Cache_Exception($e); } }
/** */ public function write($id, $session_data) { if (!$this->_db->isActive()) { $this->_db->reconnect(); $this->_db->beginDbTransaction(); } /* Check if session exists. */ try { $exists = $this->_db->selectValue(sprintf('SELECT 1 FROM %s WHERE session_id = ?', $this->_params['table']), array($id)); } catch (Horde_Db_Exception $e) { return false; } /* Update or insert session data. */ $session_data = new Horde_Db_Value_Binary($session_data); try { if ($exists) { $query = sprintf('UPDATE %s ' . 'SET session_data = ?, session_lastmodified = ? ' . 'WHERE session_id = ?', $this->_params['table']); $values = array($session_data, time(), $id); $this->_db->update($query, $values); } else { $query = sprintf('INSERT INTO %s ' . '(session_id, session_data, session_lastmodified) ' . 'VALUES (?, ?, ?)', $this->_params['table']); $values = array($id, $session_data, time()); $this->_db->insert($query, $values); } $this->_db->commitDbTransaction(); } catch (Horde_Db_Exception $e) { try { $this->_db->rollbackDbTransaction(); } catch (Horde_Db_Exception $e) { } return false; } return true; }
/** * Check if tags exists, optionally create them if they don't and return ids * for all that exist (including those that are optionally created). * * @param string|array $tags The tag names to check. * @param boolean $create If true, create the tag in the tags table. * * @return array A hash of tag_name => tag_id values. */ protected function _checkTags($tags, $create = true) { if (empty($tags)) { return array(); } if (!is_array($tags)) { $tags = is_int($tags) ? array($tags) : $this->splitTags($tags); } $tagIds = array(); // Anything already typed as an integer is assumed to be a tag id. foreach ($tags as $tag) { if (is_int($tag)) { $tagIds[$tag] = $tag; continue; } // Don't attempt to tag with an empty value if (!strlen(trim($tag))) { continue; } // Get the ids for any tags that already exist. $sql = 'SELECT tag_id FROM ' . $this->_t('tags') . ' WHERE LOWER(tag_name) = LOWER(' . $this->toDriver($tag) . ')'; if ($id = $this->_db->selectValue($sql)) { $tagIds[$tag] = (int) $id; } elseif ($create) { // Create any tags that didn't already exist $tagIds[$tag] = (int) $this->_db->insert('INSERT INTO ' . $this->_t('tags') . ' (tag_name) VALUES (' . $this->toDriver($tag) . ')'); } } return $tagIds; }
/** * Adds a permission to the permissions system. The permission must first * be created with newPermission(), and have any initial users added to * it, before this function is called. * * @param Horde_Perms_Permission_Sql $perm The perm object. * * @return integer Permission ID in the database. * @throws Horde_Perms_Exception */ public function addPermission(Horde_Perms_Permission $perm) { $name = $perm->getName(); if (empty($name)) { throw new Horde_Perms_Exception('Permission name must be non-empty.'); } $this->_cache->expire('perm_sql_' . $this->_cacheVersion . $name); $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name); // remove root from the name $root = Horde_Perms::ROOT . ':'; if (substr($name, 0, strlen($root)) == $root) { $name = substr($name, strlen($root)); } // build parents $parents = ''; if (($pos = strrpos($name, ':')) !== false) { $parent_name = substr($name, 0, $pos); $query = 'SELECT perm_id, perm_parents FROM ' . $this->_params['table'] . ' WHERE perm_name = ?'; $result = $this->_db->selectOne($query, array($parent_name)); if (empty($result)) { throw new Horde_Perms_Exception(Horde_Perms_Translation::t("Trying to create sub permission of non-existent parent permission. Create parent permission(s) first.")); } $parents = $result['perm_parents'] . ':' . $result['perm_id']; } $query = 'INSERT INTO ' . $this->_params['table'] . ' (perm_name, perm_parents) VALUES (?, ?)'; try { $id = $this->_db->insert($query, array($name, $parents)); } catch (Horde_Db_Exception $e) { throw new Horde_Perms_Exception($e); } $perm->setId($id); $perm->save(); return $id; }
/** * Save the provided sync_cache. * * @param array $cache The cache to save. * @param string $devid The device id. * @param string $user The user id. * @param array $dirty An array of dirty properties. @since 2.9.0 * * @throws Horde_ActiveSync_Exception */ public function saveSyncCache(array $cache, $devid, $user, array $dirty = null) { $cache['timestamp'] = strval($cache['timestamp']); $sql = 'SELECT count(*) FROM ' . $this->_syncCacheTable . ' WHERE cache_devid = ? AND cache_user = ?'; try { $have = $this->_db->selectValue($sql, array($devid, $user)); } catch (Horde_Db_Exception $e) { $this->_logger->err(sprintf('[%s] %s', $this->_procid, $e->getMessage())); throw new Horde_ActiveSync_Exception($e); } $cache = serialize($cache); if ($have) { $this->_logger->info(sprintf('[%s] Replacing SYNC_CACHE entry for user %s and device %s: %s', $this->_procid, $user, $devid, $cache)); $sql = 'UPDATE ' . $this->_syncCacheTable . ' SET cache_data = ? WHERE cache_devid = ? AND cache_user = ?'; try { $this->_db->update($sql, array($cache, $devid, $user)); } catch (Horde_Db_Exception $e) { $this->_logger->err(sprintf('[%s] %s', $this->_procid, $e->getMessage())); throw new Horde_ActiveSync_Exception($e); } } else { $this->_logger->info(sprintf('[%s] Adding new SYNC_CACHE entry for user %s and device %s: %s', $this->_procid, $user, $devid, $cache)); $sql = 'INSERT INTO ' . $this->_syncCacheTable . ' (cache_data, cache_devid, cache_user) VALUES (?, ?, ?)'; try { $this->_db->insert($sql, array($cache, $devid, $user)); } catch (Horde_Db_Exception $e) { $this->_logger->err(sprintf('[%s] %s', $this->_procid, $e->getMessage())); throw new Horde_ActiveSync_Exception($e); } } }
/** * Sets a lock on the requested principal and returns the generated lock * ID. * * @see Horde_Lock_Base::setLock() */ public function setLock($requestor, $scope, $principal, $lifetime = 1, $type = Horde_Lock::TYPE_SHARED) { $oldlocks = $this->getLocks($scope, $principal, $type == Horde_Lock::TYPE_SHARED ? Horde_Lock::TYPE_EXCLUSIVE : null); if (count($oldlocks) != 0) { // A lock exists. Deny the new request. if ($this->_logger) { $this->_logger->log(sprintf('Lock requested for %s denied due to existing lock.', $principal), 'NOTICE'); } return false; } $lockid = (string) new Horde_Support_Uuid(); $now = time(); $expiration = $lifetime == Horde_Lock::PERMANENT ? Horde_Lock::PERMANENT : $now + $lifetime; $sql = 'INSERT INTO ' . $this->_params['table'] . ' (lock_id, lock_owner, lock_scope, lock_principal, lock_origin_timestamp, lock_update_timestamp, lock_expiry_timestamp, lock_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; $values = array($lockid, $requestor, $scope, $principal, $now, $now, $expiration, $type); try { $this->_db->insert($sql, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Lock_Exception($e); } if ($this->_logger) { $this->_logger->log(sprintf('Lock %s set successfully by %s in scope %s on "%s"', $lockid, $requestor, $scope, $principal), 'DEBUG'); } return $lockid; }
/** * Ensure that an array of objects exist in storage. Create any that don't, * return object_ids for all. All objects in the $objects array must be * of the same content type. * * @param mixed $objects An array of objects (or single obejct value). * Values typed as an integer are assumed to already * be an object_id. * @param mixed $type Either a string type_name or integer type_id * * @return array An array of object_ids. */ public function ensureObjects($objects, $type) { if (!is_array($objects)) { $objects = array($objects); } $objectIds = array(); $objectName = array(); $type = current($this->_typeManager->ensureTypes($type)); // Anything already typed as an integer is assumed to be an object id. foreach ($objects as $objectIndex => $object) { if (is_int($object)) { $objectIds[$objectIndex] = $object; } else { $objectName[$object] = $objectIndex; } } // Get the ids for any objects that already exist. try { if (count($objectName)) { $rows = $this->_db->selectAll('SELECT object_id, object_name FROM ' . $this->_t('objects') . ' WHERE object_name IN (' . implode(',', array_map(array($this->_db, 'quoteString'), array_keys($objectName))) . ') AND type_id = ' . $type); foreach ($rows as $row) { $objectIndex = $objectName[$row['object_name']]; unset($objectName[$row['object_name']]); $objectIds[$objectIndex] = $row['object_id']; } } // Create any objects that didn't already exist foreach ($objectName as $object => $objectIndex) { $objectIds[$objectIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('objects') . ' (object_name, type_id) VALUES (' . $this->_db->quoteString($object) . ', ' . $type . ')'); } } catch (Horde_Db_Exception $e) { throw new Content_Exception($e); } return $objectIds; }
/** * @TODO * * @param <type> $clientID * @param <type> $enterDescription * @param string $exportID * @return <type> */ public function updateClientSettings($clientID, $enterDescription = 1, $exportID = null) { if (empty($exportID)) { $exportID = null; } $sql = 'SELECT clientjob_id FROM hermes_clientjobs WHERE clientjob_id = ?'; $values = array($clientID); if ($this->_db->selectValue($sql, $values) !== $clientID) { $sql = 'INSERT INTO hermes_clientjobs (clientjob_id,' . ' clientjob_enterdescription, clientjob_exportid)' . ' VALUES (?, ?, ?)'; $values = array($clientID, (int) $enterDescription, $this->_convertToDriver($exportID)); try { return $this->_db->insert($sql, $values); } catch (Horde_Db_Exception $e) { throw new Hermes_Exception($e); } } else { $sql = 'UPDATE hermes_clientjobs SET' . ' clientjob_exportid = ?, clientjob_enterdescription = ?' . ' WHERE clientjob_id = ?'; $values = array($this->_convertToDriver($exportID), (int) $enterDescription, $clientID); try { return $this->_db->update($sql, $values); } catch (Horde_Db_Exception $e) { throw new Hermes_Exception($e); } } }
/** * Add a user to a group. * * @param mixed $gid A group ID. * @param string $user A user name. * * @throws Horde_Group_Exception */ public function addUser($gid, $user) { try { $this->_db->insert('INSERT INTO horde_groups_members (group_uid, user_uid) VALUES (?, ?)', array($gid, $user)); } catch (Horde_Db_Exception $e) { throw new Horde_Group_Exception($e); } }
/** * Returns the last auto-generated ID from the affected table. * * @param string $sql SQL statement. * @param mixed $arg1 Either an array of bound parameters or a * query name. * @param string $arg2 If $arg1 contains bound parameters, the * query name. * @param string $pk TODO * @param integer $idValue TODO * @param string $sequenceName TODO * * @return integer Last inserted ID. * @throws Horde_Db_Exception */ public function insert($sql, $arg1 = null, $arg2 = null, $pk = null, $idValue = null, $sequenceName = null) { $result = $this->_write->insert($sql, $arg1, $arg2, $pk, $idValue, $sequenceName); $this->_lastQuery = $this->_write->getLastQuery(); // Once doing writes, keep using the write backend even for reads // at least during the same request, to help against stale data. $this->_read = $this->_write; return $result; }
/** * Increment, and return, the modseq value. * * @return integer The new modseq value. */ protected function _nextModSeq() { try { $result = $this->_db->insert('INSERT INTO horde_histories_modseq (history_modseqempty) VALUES(0)'); $this->_db->delete('DELETE FROM horde_histories_modseq WHERE history_modseq <> ?', array($result)); } catch (Horde_Db_Exception $e) { throw new Horde_History_Exception($e); } return $result; }
/** * 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()); } }
/** * Adds an alarm hash to the backend. * * @param array $alarm An alarm hash. * * @throws Horde_Alarm_Exception */ protected function _add(array $alarm) { $query = sprintf('INSERT INTO %s (alarm_id, alarm_uid, alarm_start, alarm_end, alarm_methods, alarm_params, alarm_title, alarm_text, alarm_snooze, alarm_instanceid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table']); $values = array($alarm['id'], isset($alarm['user']) ? $alarm['user'] : '', $alarm['start']->setTimezone('UTC')->format(Horde_Date::DATE_DEFAULT), empty($alarm['end']) ? null : $alarm['end']->setTimezone('UTC')->format(Horde_Date::DATE_DEFAULT), serialize($alarm['methods']), base64_encode(serialize($alarm['params'])), $this->_toDriver($alarm['title']), empty($alarm['text']) ? null : $this->_toDriver($alarm['text']), null, empty($alarm['instanceid']) ? null : $alarm['instanceid']); try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Alarm_Exception(Horde_Alarm_Translation::t("Server error when querying database.")); } }
/** * Adds the specified object to the SQL database. * * @param array $attributes The attribute values of the contact. * @param array $blob_fields Fields that represent binary data. * @param array $date_fields Fields that represent dates. @since 4.2.0 * * @throws Turba_Exception */ protected function _add(array $attributes, array $blob_fields = array(), array $date_fields = array()) { list($fields, $values) = $this->_prepareWrite($attributes, $blob_fields, $date_fields); $query = 'INSERT INTO ' . $this->_params['table'] . ' (' . implode(', ', $fields) . ')' . ' VALUES (' . str_repeat('?, ', count($values) - 1) . '?)'; try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Turba_Exception(_("Server error when adding data.")); } }
/** * Creates an Amavisd-new recipient for policy, whitelist and blacklist * storage and retrieval. * * @return string The id of the newly created recipient. * @throws Sam_Exception */ protected function _createUserID() { try { $this->_db->insert(sprintf('INSERT INTO %s (%s) VALUES (?)', $this->_mapNameToTable('recipients'), $this->_mapAttributeToField('recipients', 'email')), array($this->_user)); } catch (Horde_Db_Exception $e) { throw new Sam_Exception(sprintf(_("Cannot create recipient %s: %s"), $this->_user, $e->getMessage())); } $GLOBALS['notification']->push(sprintf(_("Recipient created: %s"), $this->_user), 'horde.success'); return $this->_lookupUserID(); }
/** * 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); } } } }
/** * 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); } }
/** * Increments, and returns, the modseq value. * * @return integer The new modseq value. * @throws Horde_History_Exception */ protected function _nextModSeq() { try { $result = $this->_db->insert('INSERT INTO horde_histories_modseq (history_modseqempty) VALUES(0)'); // Don't completely empty the table to prevent sequence from being reset // when using certain RDBMS, like postgres (see Bug #13876). $this->_db->delete('DELETE FROM horde_histories_modseq WHERE history_modseq < (? - 25)', array($result)); } catch (Horde_Db_Exception $e) { throw new Horde_History_Exception($e); } return $result; }
/** * Adds a note to the backend storage. * * @param string $noteId The ID of the new note. * @param string $desc The first line of the note. * @param string $body The whole note body. * @param string $tags The tags of the note. * * @return string The unique ID of the new note. * @throws Mnemo_Exception */ protected function _add($noteId, $desc, $body, $tags) { $uid = strval(new Horde_Support_Uuid()); $query = 'INSERT INTO ' . $this->_table . ' (memo_owner, memo_id, memo_desc, memo_body, memo_uid)' . ' VALUES (?, ?, ?, ?, ?)'; $values = array($this->_notepad, $noteId, Horde_String::convertCharset($desc, 'UTF-8', $this->_charset), Horde_String::convertCharset($body, 'UTF-8', $this->_charset), Horde_String::convertCharset($uid, 'UTF-8', $this->_charset)); try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Mnemo_Exception($e); } return $uid; }
/** * 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); } }
/** * Creates a new forum. * * @param string $forum_name Forum name. * @param string $forum_owner Forum owner. * * @return integer ID of the new generated forum. * @throws Agora_Exception */ public function newForum($forum_name, $owner) { if (empty($forum_name)) { throw new Agora_Exception(_("Cannot create a forum with an empty name.")); } $sql = 'INSERT INTO ' . $this->_forums_table . ' (scope, forum_name, active, author) VALUES (?, ?, ?, ?)'; $values = array($this->_scope, $this->convertToDriver($forum_name), 1, $owner); try { $forum_id = $this->_db->insert($sql, $values); } catch (Horde_Db_Exception $e) { throw new Agora_Exception($e->getMessage()); } return $forum_id; }
/** * Adds a task to the backend storage. * * @param array $task A hash with the following possible properties: * - name: (string) The name (short) of the task. * - desc: (string) The description (long) of the task. * - start: (OPTIONAL, integer) The start date of the task. * - due: (OPTIONAL, integer) The due date of the task. * - priority: (OPTIONAL, integer) The priority of the task. * - estimate: (OPTIONAL, float) The estimated time to complete the * task. * - completed: (OPTIONAL, integer) The completion state of the task. * - tags: (OPTIONAL, array) The task tags. * - alarm: (OPTIONAL, integer) The alarm associated with the task. * - methods: (OPTIONAL, array) The overridden alarm notification * methods. * - uid: (OPTIONAL, string) A Unique Identifier for the task. * - parent: (OPTIONAL, string) The parent task. * - private: (OPTIONAL, boolean) Whether the task is private. * - owner: (OPTIONAL, string) The owner of the event. * - assignee: (OPTIONAL, string) The assignee of the event. * - recurrence: (OPTIONAL, Horde_Date_Recurrence|array) Recurrence * information. * * @return string The Nag ID of the new task. * @throws Nag_Exception */ protected function _add(array $task) { $taskId = strval(new Horde_Support_Randomid()); $query = sprintf('INSERT INTO %s (task_owner, task_creator, task_assignee, ' . 'task_id, task_name, task_uid, task_desc, task_start, task_due, ' . 'task_priority, task_estimate, task_completed, ' . 'task_alarm, task_alarm_methods, task_private, task_parent, ' . 'task_recurtype, task_recurinterval, task_recurenddate, ' . 'task_recurcount, task_recurdays, task_exceptions, ' . 'task_completions) ' . 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table']); $values = array($this->_tasklist, $task['owner'], $task['assignee'], $taskId, Horde_String::convertCharset($task['name'], 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($task['uid'], 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($task['desc'], 'UTF-8', $this->_params['charset']), (int) $task['start'], (int) $task['due'], (int) $task['priority'], number_format(floatval($task['estimate']), 2), (int) $task['completed'], (int) $task['alarm'], serialize(Horde_String::convertCharset($task['methods'], 'UTF-8', $this->_params['charset'])), (int) $task['private'], $task['parent']); $this->_addRecurrenceFields($values, $task); try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Nag_Exception($e); } $this->_addTags($task); return $taskId; }
/** * Ensure the style hash is recorded in the database. * * @param string $hash The hash to record. */ public function ensureHash($hash) { $query = 'SELECT COUNT(*) FROM ansel_hashes WHERE style_hash = ?'; try { $results = $this->_db->selectValue($query, array($hash)); } catch (Horde_Db_Exception $e) { throw new Ansel_Exception($e); } if (!$results) { try { $this->_db->insert('INSERT INTO ansel_hashes (style_hash) VALUES(?)', array($hash)); } catch (Horde_Db_Exception $e) { throw new Ansel_Exception($e); } } }
/** * Adds a rule hash to the filters list. * * @param array $rule A rule hash. * @param boolean $default If true merge the rule hash with default rule * values. */ public function addRule(array $rule, $default = true) { if ($default) { $rule = array_merge($this->getDefaultRule(), $rule); } $query = sprintf('INSERT INTO %s (rule_owner, rule_name, rule_action, rule_value, rule_flags, rule_conditions, rule_combine, rule_stop, rule_active, rule_order) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table_rules']); $order = key(array_reverse($this->_filters, true)) + 1; $values = array_merge(array(Ingo::getUser()), $this->_ruleToBackend($rule), array($order)); try { $result = $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $rule['id'] = $result; $this->_filters[$order] = $rule; }