Beispiel #1
0
 /**
  * Execute the SQL statement.
  *
  * @return  mixed  A database cursor resource on success, boolean false on failure.
  *
  * @since   11.1
  * @throws  DatabaseException
  */
 public function query()
 {
     if (!is_resource($this->connection)) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  11.3
         if (JError::$legacy) {
             if ($this->debug) {
                 JError::raiseError(500, 'JDatabaseDriverSQLAzure::query: ' . $this->errorNum . ' - ' . $this->errorMsg);
             }
             return false;
         } else {
             JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'database');
             throw new DatabaseException();
         }
     }
     // Take a local copy so that we don't modify the original query and cause issues later
     $sql = $this->replacePrefix((string) $this->sql);
     if ($this->limit > 0 || $this->offset > 0) {
         $sql = $this->_limit($sql, $this->limit, $this->offset);
     }
     // If debugging is enabled then let's log the query.
     if ($this->debug) {
         // Increment the query counter and add the query to the object queue.
         $this->count++;
         $this->log[] = $sql;
         JLog::add($sql, JLog::DEBUG, 'databasequery');
     }
     // Reset the error values.
     $this->errorNum = 0;
     $this->errorMsg = '';
     // sqlsrv_num_rows requires a static or keyset cursor.
     if (JString::startsWith(ltrim(strtoupper($sql)), 'SELECT')) {
         $array = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
     } else {
         $array = array();
     }
     // Execute the query.
     $this->cursor = sqlsrv_query($this->connection, $sql, array(), $array);
     // If an error occurred handle it.
     if (!$this->cursor) {
         // Populate the errors.
         $errors = sqlsrv_errors();
         $this->errorNum = $errors[0]['SQLSTATE'];
         $this->errorMsg = $errors[0]['message'] . 'SQL=' . $sql;
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  11.3
         if (JError::$legacy) {
             if ($this->debug) {
                 JError::raiseError(500, 'JDatabaseDriverSQLAzure::query: ' . $this->errorNum . ' - ' . $this->errorMsg);
             }
             return false;
         } else {
             JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'databasequery');
             throw new DatabaseException();
         }
     }
     return $this->cursor;
 }