示例#1
0
 /**
  * Handle PDOException
  *
  * @access public
  * @param  PDOException $e
  * @return bool
  * @throws SQLException
  */
 public function handleSqlError(PDOException $e)
 {
     $this->cleanup();
     $this->db->cancelTransaction();
     $this->db->setLogMessage($e->getMessage());
     if ($this->db->getDriver()->isDuplicateKeyError($e->getCode())) {
         return false;
     }
     throw new SQLException('SQL error' . ($this->logQueries ? ': ' . $e->getMessage() : ''));
 }
示例#2
0
 /**
  * Migrate the schema to one version to another
  *
  * @access public
  * @param  integer  $current_version
  * @param  integer  $next_version
  * @return boolean
  */
 public function migrateTo($current_version, $next_version)
 {
     try {
         $this->db->startTransaction();
         $this->db->getDriver()->disableForeignKeys();
         for ($i = $current_version + 1; $i <= $next_version; $i++) {
             $function_name = '\\Schema\\version_' . $i;
             if (function_exists($function_name)) {
                 call_user_func($function_name, $this->db->getConnection());
             }
         }
         $this->db->getDriver()->setSchemaVersion($i - 1);
         $this->db->getDriver()->enableForeignKeys();
         $this->db->closeTransaction();
     } catch (PDOException $e) {
         $this->db->setLogMessage($function_name . ' => ' . $e->getMessage());
         $this->db->cancelTransaction();
         $this->db->getDriver()->enableForeignKeys();
         return false;
     }
     return true;
 }
示例#3
0
 /**
  * ILIKE condition
  *
  * @access public
  * @param  string   $column
  * @param  mixed    $value
  */
 public function ilike($column, $value)
 {
     $this->addCondition($this->db->escapeIdentifier($column) . ' ' . $this->db->getDriver()->getOperator('ILIKE') . ' ?');
     $this->values[] = $value;
 }
示例#4
0
 /**
  * Get current database version
  *
  * @static
  * @access public
  * @param  Database $db
  * @return int
  */
 public static function getSchemaVersion(Database $db)
 {
     return $db->getDriver()->getSchemaVersion();
 }