示例#1
0
文件: Sql.php 项目: raz0rsdge/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.
                 $query = 'INSERT INTO ' . $this->_params['table'] . ' ' . '(pref_uid, pref_scope, pref_name, pref_value) VALUES' . '(?, ?, ?, ?)';
                 $values = array($this->_params['user'], $scope_ob->scope, $name, $value);
                 try {
                     $this->_db->insert($query, $values);
                 } catch (Horde_Db_Exception $e) {
                     throw new Horde_Prefs_Exception($e);
                 }
             } else {
                 // Update the existing row.
                 $query = 'UPDATE ' . $this->_params['table'] . ' SET pref_value = ?' . ' WHERE pref_uid = ?' . ' AND pref_name = ?' . ' AND pref_scope = ?';
                 $values = array($value, $this->_params['user'], $name, $scope_ob->scope);
                 try {
                     $this->_db->update($query, $values);
                 } catch (Horde_Db_Exception $e) {
                     throw new Horde_Prefs_Exception($e);
                 }
             }
         }
     }
 }
示例#2
0
文件: Sql.php 项目: raz0rsdge/horde
 /**
  * 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;
 }
示例#3
0
文件: Sql.php 项目: jubinpatel/horde
 /**
  * Converts a value from the default charset to the driver's charset.
  *
  * @param mixed $value  A value to convert.
  *
  * @return mixed  The converted value.
  */
 protected function _convertToDriver($value)
 {
     return Horde_String::convertCharset($value, 'UTF-8', $this->_db->getOption('charset'));
 }
示例#4
0
文件: Tagger.php 项目: horde/horde
 public function toDriver($value)
 {
     return $this->_db->quoteString(Horde_String::convertCharset($value, 'UTF-8', $this->_db->getOption('charset')));
 }
示例#5
0
文件: Sql.php 项目: jubinpatel/horde
 /**
  * Returns the charset used by the backend.
  *
  * @return string  The backend's charset
  */
 public function getCharset()
 {
     return $this->_db->getOption('charset');
 }