Example #1
0
 /**
  * Truncate a given table.
  *
  * @param \Zend\Db\Adapter\AbstractAdapter $db
  * @param string $tableName
  * @return void
  */
 protected function _truncate(\Zend\Db\Adapter\AbstractAdapter $db, $tableName)
 {
     $tableName = $db->quoteIdentifier($tableName);
     if ($db instanceof \Zend\Db\Adapter\Pdo\Sqlite) {
         $db->query('DELETE FROM ' . $tableName);
     } else {
         if ($db instanceof \Zend\Db\Adapter\Db2) {
             /*if(strstr(PHP_OS, "WIN")) {
                   $file = tempnam(sys_get_temp_dir(), "zendtestdbibm_");
                   file_put_contents($file, "");
                   $db->query('IMPORT FROM '.$file.' OF DEL REPLACE INTO '.$tableName);
                   unlink($file);
               } else {
                   $db->query('IMPORT FROM /dev/null OF DEL REPLACE INTO '.$tableName);
               }*/
             throw \Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException("IBM Db2 TRUNCATE not supported.");
         } else {
             if ($this->_isMssqlOrOracle($db)) {
                 $db->query('TRUNCATE TABLE ' . $tableName);
             } else {
                 if ($db instanceof \Zend\Db\Adapter\Pdo\PgSql) {
                     $db->query('TRUNCATE ' . $tableName . ' CASCADE');
                 } else {
                     $db->query('TRUNCATE ' . $tableName);
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Drops the database table for session data
  *
  * @return void
  */
 protected function _dropTable()
 {
     if (!$this->_db instanceof AbstractAdapter) {
         return;
     }
     $this->_db->query('DROP TABLE Sessions');
 }
Example #3
0
 /**
  * Executes a prepared statement.
  *
  * @param array $params OPTIONAL Values to bind to parameter placeholders.
  * @return bool
  */
 public function execute(array $params = null)
 {
     /*
      * Simple case - no query profiler to manage.
      */
     if ($this->_queryId === null) {
         return $this->_execute($params);
     }
     /*
      * Do the same thing, but with query profiler
      * management before and after the execute.
      */
     $prof = $this->_adapter->getProfiler();
     $qp = $prof->getQueryProfile($this->_queryId);
     if ($qp->hasEnded()) {
         $this->_queryId = $prof->queryClone($qp);
         $qp = $prof->getQueryProfile($this->_queryId);
     }
     if ($params !== null) {
         $qp->bindParams($params);
     } else {
         $qp->bindParams($this->_bindParam);
     }
     $qp->start($this->_queryId);
     $retval = $this->_execute($params);
     $prof->queryEnd($this->_queryId);
     return $retval;
 }
Example #4
0
 /**
  * _authenticateValidateResult() - This method attempts to validate that
  * the record in the resultset is indeed a record that matched the
  * identity provided to this adapter.
  *
  * @param  array $resultIdentity
  * @return Zend\Authentication\Result
  */
 protected function _authenticateValidateResult($resultIdentity)
 {
     $zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match');
     if ($resultIdentity[$zendAuthCredentialMatchColumn] != '1') {
         $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID;
         $this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.';
         return $this->_authenticateCreateAuthResult();
     }
     unset($resultIdentity[$zendAuthCredentialMatchColumn]);
     $this->_resultRow = $resultIdentity;
     $this->_authenticateResultInfo['code'] = AuthenticationResult::SUCCESS;
     $this->_authenticateResultInfo['messages'][] = 'Authentication successful.';
     return $this->_authenticateCreateAuthResult();
 }
Example #5
0
 /**
  * Write a message to the log.
  *
  * @param  array  $event  event data
  * @throws Exception\RuntimeException
  * @return void
  */
 protected function _write($event)
 {
     if ($this->_db === null) {
         throw new Exception\RuntimeException('Database adapter is null');
     }
     if ($this->_columnMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_columnMap as $columnName => $fieldKey) {
             $dataToInsert[$columnName] = $event[$fieldKey];
         }
     }
     $this->_db->insert($this->_table, $dataToInsert);
 }
Example #6
0
 /**
  * Render LIMIT OFFSET clause
  *
  * @param string   $sql SQL query
  * @return string
  */
 protected function _renderLimitoffset($sql)
 {
     $count = 0;
     $offset = 0;
     if (!empty($this->_parts[self::LIMIT_OFFSET])) {
         $offset = (int) $this->_parts[self::LIMIT_OFFSET];
         $count = PHP_INT_MAX;
     }
     if (!empty($this->_parts[self::LIMIT_COUNT])) {
         $count = (int) $this->_parts[self::LIMIT_COUNT];
     }
     /*
      * Add limits clause
      */
     if ($count > 0) {
         $sql = trim($this->_adapter->limit($sql, $count, $offset));
     }
     return $sql;
 }
Example #7
0
 /**
  * Ids-specific sequence id value
  *
  *  @param string $sequenceName
  *  @return integer
  */
 public function nextSequenceId($sequenceName)
 {
     $sql = 'SELECT ' . $this->_adapter->quoteIdentifier($sequenceName) . '.NEXTVAL FROM ' . 'systables WHERE tabid = 1';
     $value = $this->_adapter->fetchOne($sql);
     return $value;
 }
Example #8
0
 /**
  * Returns a quoted schema object. (table name, column name, etc)
  *
  * @param string $object
  * @return string
  */
 public function quoteSchemaObject($object)
 {
     return $this->_connection->quoteIdentifier($object);
 }
Example #9
0
 /**
  * Db2-specific sequence id value
  *
  *  @param string $sequenceName
  *  @return integer
  */
 public function nextSequenceId($sequenceName)
 {
     $sql = 'SELECT NEXTVAL FOR ' . $this->_adapter->quoteIdentifier($sequenceName) . ' AS VAL FROM SYSIbm.SYSDUMMY1';
     $value = $this->_adapter->fetchOne($sql);
     return $value;
 }
Example #10
0
 /**
  * Support method for fetching rows.
  *
  * @param  \Zend\DB\Table\Select\Select $select  query options.
  * @return array An array containing the row results in FETCH_ASSOC mode.
  */
 protected function _fetch(Select\Select $select)
 {
     $stmt = $this->_db->query($select);
     $data = $stmt->fetchAll(\Zend\DB\DB::FETCH_ASSOC);
     return $data;
 }
Example #11
0
 /**
  * Used by:
  * - testAdapterOptionCaseFoldingNatural()
  * - testAdapterOptionCaseFoldingUpper()
  * - testAdapterOptionCaseFoldingLower()
  */
 protected function _testAdapterOptionCaseFoldingSetup(\Zend\DB\Adapter\AbstractAdapter $db)
 {
     $db->getConnection();
     $this->_util->setUp($db);
 }
Example #12
0
 /**
  * Used by _testAdapterOptionCaseFoldingNatural()
  * SQLite needs to do metadata setup,
  * because it uses the in-memory database,
  * so that test suite will override this method.
  */
 protected function _testAdapterOptionCaseFoldingSetup(\Zend\DB\Adapter\AbstractAdapter $db)
 {
     $db->getConnection();
 }
Example #13
0
 /**
  * Quote a raw string.
  *
  * @param string $value     Raw string
  * @return string           Quoted string
  */
 protected function _quote($value)
 {
     if (is_int($value) || is_float($value)) {
         return $value;
     }
     /**
      * Use db2_escape_string() if it is present in the Ibm Db2 extension.
      * But some supported versions of PHP do not include this function,
      * so fall back to default quoting in the parent class.
      */
     if (function_exists('db2_escape_string')) {
         return "'" . db2_escape_string($value) . "'";
     }
     return parent::_quote($value);
 }
Example #14
0
 /**
  * Close this connection.
  *
  * @return void
  */
 public function close()
 {
     $this->_connection->closeConnection();
 }
Example #15
0
    /**
     * Special handling for Pdo query().
     * All bind parameter names must begin with ':'
     *
     * @param string|\Zend\Db\Select $sql The SQL statement with placeholders.
     * @param array $bind An array of data to bind to the placeholders.
     * @return \Zend\Db\Statement\Pdo
     * @throws \Zend\Db\Adapter\Exception To re-throw PdoException.
     */
    public function query($sql, $bind = array())
    {
        if (empty($bind) && $sql instanceof Select) {
            $bind = $sql->getBind();
        }

        if (is_array($bind)) {
            foreach ($bind as $name => $value) {
                if (!is_int($name) && !preg_match('/^:/', $name)) {
                    $newName = ":$name";
                    unset($bind[$name]);
                    $bind[$newName] = $value;
                }
            }
        }

        try {
            return parent::query($sql, $bind);
        } catch (\PDOException $e) {
            throw new \Zend\Db\Statement\Exception($e->getMessage(), $e->getCode(), $e);
        }
    }