insertBlob() 공개 메소드

Inserts a row including BLOBs into a table.
public insertBlob ( string $table, array $fields, string $pk = null, integer $idValue = null ) : integer
$table string The table name.
$fields array A hash of column names and values. BLOB columns must be provided as Horde_Db_Value_Binary objects.
$pk string The primary key column.
$idValue integer The primary key value. This parameter is required if the primary key is inserted manually.
리턴 integer Last inserted ID.
예제 #1
0
파일: Sql.php 프로젝트: horde/horde
 /**
  */
 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. */
     $values = array('session_data' => new Horde_Db_Value_Binary($session_data), 'session_lastmodified' => time());
     try {
         if ($exists) {
             $this->_db->updateBlob($this->_params['table'], $values, array('session_id = ?', array($id)));
         } else {
             $this->_db->insertBlob($this->_params['table'], array_merge(array('session_id' => $id), $values));
         }
         $this->_db->commitDbTransaction();
     } catch (Horde_Db_Exception $e) {
         try {
             $this->_db->rollbackDbTransaction();
         } catch (Horde_Db_Exception $e) {
         }
         return false;
     }
     return true;
 }
예제 #2
0
파일: Sql.php 프로젝트: horde/horde
 /**
  * Save the current state to storage
  *
  * @throws Horde_ActiveSync_Exception
  */
 public function save()
 {
     // Prepare state and pending data
     if ($this->_type == Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) {
         $data = isset($this->_folder) ? serialize($this->_folder) : '';
         $pending = '';
     } elseif ($this->_type == Horde_ActiveSync::REQUEST_TYPE_SYNC) {
         $pending = isset($this->_changes) ? serialize(array_values($this->_changes)) : '';
         $data = isset($this->_folder) ? serialize($this->_folder) : '';
     } else {
         $pending = '';
         $data = '';
     }
     // If we are setting the first synckey iteration, do not save the
     // syncstamp/mod, otherwise we will never get the initial set of data.
     $params = array('sync_key' => $this->_syncKey, 'sync_data' => new Horde_Db_Value_Binary($data), 'sync_devid' => $this->_deviceInfo->id, 'sync_mod' => self::getSyncKeyCounter($this->_syncKey) == 1 ? 0 : $this->_thisSyncStamp, 'sync_folderid' => !empty($this->_collection['id']) ? $this->_collection['id'] : Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC, 'sync_user' => $this->_deviceInfo->user, 'sync_pending' => $pending, 'sync_timestamp' => time());
     $this->_logger->info(sprintf('[%s] Saving state: %s', $this->_procid, serialize(array($params['sync_key'], $params['sync_data'], $params['sync_devid'], $params['sync_mod'], $params['sync_folderid'], $params['sync_user'], count($this->_changes), time()))));
     try {
         $this->_db->insertBlob($this->_syncStateTable, $params);
     } catch (Horde_Db_Exception $e) {
         // Might exist already if the last sync attempt failed.
         $this->_logger->notice(sprintf('[%s] Previous request processing for synckey %s failed to be accepted by the client, removing previous state and trying again.', $this->_procid, $this->_syncKey));
         $this->_db->delete('DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_key = ?', array($this->_syncKey));
         $this->_db->insertBlob($this->_syncStateTable, $params);
     }
 }
예제 #3
0
파일: Sql.php 프로젝트: horde/horde
 /**
  */
 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. */
     $values = array('cache_id' => $key, 'cache_timestamp' => $timestamp, 'cache_expiration' => $expiration, 'cache_data' => new Horde_Db_Value_Binary($data));
     try {
         $this->_db->insertBlob($this->_params['table'], $values);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Cache_Exception($e);
     }
 }
예제 #4
0
파일: Db.php 프로젝트: horde/horde
 /**
  */
 public function setMetaData($mailbox, $data)
 {
     if (!($uid = $this->_getUid($mailbox))) {
         $uid = $this->_createUid($mailbox);
     }
     $query = sprintf('SELECT field FROM %s where messageid = ?', self::MD_TABLE);
     $values = array($uid);
     try {
         $fields = $this->_db->selectValues($query, $values);
     } catch (Horde_Db_Exception $e) {
         return;
     }
     foreach ($data as $key => $val) {
         $val = new Horde_Db_Value_Binary($key == 'uidvalid' ? $val : serialize($val));
         if (in_array($key, $fields)) {
             /* Update */
             try {
                 $this->_db->updateBlob(self::MD_TABLE, array('data' => $val), array('field = ? AND messageid = ?', array($key, $uid)));
             } catch (Horde_Db_Exception $e) {
             }
         } else {
             /* Insert */
             try {
                 $this->_db->insertBlob(self::MD_TABLE, array('data' => $val, 'field' => $key, 'messageid' => $uid));
             } catch (Horde_Db_Exception $e) {
             }
         }
     }
 }
예제 #5
0
파일: Sql.php 프로젝트: raz0rsdge/horde
 /**
  * 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);
     try {
         $this->_db->insertBlob($this->_params['table'], array_combine($fields, $values));
     } catch (Horde_Db_Exception $e) {
         throw new Turba_Exception(_("Server error when adding data."));
     }
 }
예제 #6
0
파일: Sql.php 프로젝트: horde/horde
 /**
  * Adds an alarm hash to the backend.
  *
  * @param array $alarm  An alarm hash.
  *
  * @throws Horde_Alarm_Exception
  */
 protected function _add(array $alarm)
 {
     $values = array('alarm_id' => $alarm['id'], 'alarm_uid' => isset($alarm['user']) ? $alarm['user'] : '', 'alarm_start' => $alarm['start']->setTimezone('UTC')->format(Horde_Date::DATE_DEFAULT), 'alarm_end' => empty($alarm['end']) ? null : $alarm['end']->setTimezone('UTC')->format(Horde_Date::DATE_DEFAULT), 'alarm_methods' => serialize($alarm['methods']), 'alarm_params' => new Horde_Db_Value_Text(base64_encode(serialize($alarm['params']))), 'alarm_title' => $this->_toDriver($alarm['title']), 'alarm_text' => empty($alarm['text']) ? null : new Horde_Db_Value_Text($this->_toDriver($alarm['text'])), 'alarm_snooze' => null, 'alarm_instanceid' => empty($alarm['instanceid']) ? null : $alarm['instanceid']);
     try {
         $this->_db->insertBlob($this->_params['table'], $values);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Alarm_Exception(Horde_Alarm_Translation::t("Server error when querying database."));
     }
 }
예제 #7
0
파일: SplitRead.php 프로젝트: horde/horde
 /**
  * Inserts a row including BLOBs into a table.
  *
  * @since Horde_Db 2.1.0
  *
  * @param string $table     The table name.
  * @param array $fields     A hash of column names and values. BLOB columns
  *                          must be provided as Horde_Db_Value_Binary
  *                          objects.
  * @param string $pk        The primary key column.
  * @param integer $idValue  The primary key value. This parameter is
  *                          required if the primary key is inserted
  *                          manually.
  *
  * @return integer  Last inserted ID.
  * @throws Horde_Db_Exception
  */
 public function insertBlob($table, $fields, $pk = null, $idValue = null)
 {
     $result = $this->_write->insertBlob($table, $fields, $pk, $idValue);
     $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;
 }
예제 #8
0
파일: Sql.php 프로젝트: horde/horde
 /**
  */
 public function store($scope_ob)
 {
     if (!$this->_db->isActive()) {
         $this->_db->reconnect();
     }
     $charset = $this->_db->getOption('charset');
     // For each preference, check for an existing table row and
     // update it if it's there, or create a new one if it's not.
     foreach ($scope_ob->getDirty() as $name) {
         $value = $scope_ob->get($name);
         if (is_null($value)) {
             $this->remove($scope_ob->scope, $name);
         } else {
             $values = array($this->_params['user'], $name, $scope_ob->scope);
             // Does a row already exist for this preference?
             $query = 'SELECT 1 FROM ' . $this->_params['table'] . ' WHERE pref_uid = ? AND pref_name = ?' . ' AND pref_scope = ?';
             try {
                 $check = $this->_db->selectValue($query, $values);
             } catch (Horde_Db_Exception $e) {
                 throw new Horde_Prefs_Exception($e);
             }
             /* Driver has no support for storing locked status. */
             $value = Horde_String::convertCharset($value, 'UTF-8', $charset);
             $value = new Horde_Db_Value_Binary($value);
             if (empty($check)) {
                 // Insert a new row.
                 $values = array('pref_uid' => $this->_params['user'], 'pref_scope' => $scope_ob->scope, 'pref_name' => $name, 'pref_value' => $value);
                 try {
                     $this->_db->insertBlob($this->_params['table'], $values);
                 } catch (Horde_Db_Exception $e) {
                     throw new Horde_Prefs_Exception($e);
                 }
             } else {
                 // Update the existing row.
                 try {
                     $this->_db->updateBlob($this->_params['table'], array('pref_value' => $value), array('pref_uid = ? AND pref_name = ? AND pref_scope = ?', array($this->_params['user'], $name, $scope_ob->scope)));
                 } catch (Horde_Db_Exception $e) {
                     throw new Horde_Prefs_Exception($e);
                 }
             }
         }
     }
 }