Example #1
0
 public function execute($bindValues = array(), $additionalParameters = array())
 {
     $query = $this->getQuery();
     if (empty($bindValues)) {
         if (empty($this->bindValues)) {
             $bindValues = array();
         } else {
             $bindValues = $this->escape($this->bindValues);
             foreach ($bindValues as $k => $v) {
                 $bindValues["@{$k}@"] = $v;
                 unset($bindValues[$k]);
             }
         }
     }
     if (!empty($this->binaries)) {
         for ($i = 0, $c = count($this->binaries); $i < $c; $i++) {
             $query = str_replace(self::BINARY_IDENTIFIER . ($i + 1), $this->binaries[$i]->getData(), $query);
         }
     }
     $start = microtime(true);
     $result = $this->driver->execute($query, $bindValues, $additionalParameters);
     self::$queries[] = array("sql" => $query, "time" => microtime(true) - $start, "binds" => $bindValues);
     if ($this->isInsert()) {
         return $this->seqColumn === null ? null : $this->driver->getLastInsertId();
     } elseif ($this->isUpdate() || $this->isDelete()) {
         return $this->driver->getAffectedRows();
     } else {
         return $result;
     }
 }
Example #2
0
 /**
  * @param Sabel_Db_Driver $driver
  *
  * @throws Sabel_Db_Exception_Transaction
  * @return void
  */
 public static function begin(Sabel_Db_Driver $driver)
 {
     switch (self::$isolationLevel) {
         case self::READ_UNCOMMITTED:
             $iLevel = Sabel_Db_Driver::TRANS_READ_UNCOMMITTED;
             break;
         case self::READ_COMMITTED:
             $iLevel = Sabel_Db_Driver::TRANS_READ_COMMITTED;
             break;
         case self::REPEATABLE_READ:
             $iLevel = Sabel_Db_Driver::TRANS_REPEATABLE_READ;
             break;
         case self::SERIALIZABLE:
             $iLevel = Sabel_Db_Driver::TRANS_SERIALIZABLE;
             break;
         default:
             $iLevel = null;
     }
     $connectionName = $driver->getConnectionName();
     try {
         self::$transactions[$connectionName]["conn"] = $driver->begin($iLevel);
         self::$transactions[$connectionName]["driver"] = $driver;
         self::$active = true;
     } catch (Exception $e) {
         throw new Sabel_Db_Exception_Transaction($e->getMessage());
     }
 }
Example #3
0
 public function execute($bindValues = array(), $additionalParameters = array(), $query = null)
 {
     if ($query === null) {
         $query = $this->getQuery();
     }
     if (empty($bindValues)) {
         $bindValues = empty($this->bindValues) ? array() : $this->escape($this->bindValues);
     }
     $start = microtime(true);
     $result = $this->driver->execute($query, $bindValues, $additionalParameters);
     self::$queries[] = array("sql" => $query, "time" => microtime(true) - $start, "binds" => $bindValues);
     if ($this->isInsert()) {
         return $this->seqColumn === null ? null : $this->driver->getLastInsertId();
     } elseif ($this->isUpdate() || $this->isDelete()) {
         return $this->driver->getAffectedRows();
     } else {
         return $result;
     }
 }
Example #4
0
 /**
  * @param Sabel_Db_Driver $driver
  *
  * @throws Sabel_Db_Exception_Connection
  * @return Sabel_Db_Driver
  */
 protected static function _connect(Sabel_Db_Driver $driver)
 {
     $connectionName = $driver->getConnectionName();
     $names = Sabel_Db_Config::getConnectionNamesOfSameSetting($connectionName);
     foreach ($names as $name) {
         if (isset(self::$connections[$name])) {
             $driver->setConnection(self::$connections[$name]);
             return $driver;
         }
     }
     if (!isset(self::$connections[$connectionName])) {
         $result = $driver->connect(Sabel_Db_Config::get($connectionName));
         if (is_string($result)) {
             throw new Sabel_Db_Exception_Connection($result);
         } else {
             self::$connections[$connectionName] = $result;
         }
     }
     $driver->setConnection(self::$connections[$connectionName]);
     return $driver;
 }