You are here

public function FrxOracle::sqlData in Forena Reports 8

Get data based on file data block in the repository.

Parameters

string $sql: Query to execute

array $options: key value pairs containing type information for parameters.

Return value

SimpleXMLElement | array Data from executed SQL query.

File

src/FrxPlugin/Driver/FrxOracle.php, line 84
Oracle specific driver that takes advantage of oracles native XML support

Class

FrxOracle
Class FrxOracle

Namespace

Drupal\forena\FrxPlugin\Driver

Code

public function sqlData($sql, $options = array()) {

  // Load the block from the file
  $db = $this->db;
  $xml = '';

  // Load the types array based on data
  $this->types = isset($options['type']) ? $options['type'] : array();
  if ($sql && $db) {

    // See if this block matches a declare begin end; syntax.
    if (stripos($sql, 'end;') >= stripos($sql, 'begin') && stripos($sql, 'begin') !== FALSE) {
      $params = $this
        ->currentDataContextArray();
      $this
        ->call($sql, $params, array(
        'return' => 'clob',
      ));
      $xml = $params['return'];
      if (trim($xml)) {
        $xml = new \SimpleXMLElement($xml);
      }
    }
    else {
      $sql = $this->te
        ->replace($sql);
      if ($this->use_oracle_xml && @$options['return_type'] != 'raw') {
        $xml = $this
          ->oracle_xml($sql, 'table');
      }
      else {
        $xml = $this
          ->php_xml($sql, $options);
      }
    }
    if ($this->debug) {
      if (is_object($xml) && method_exists($xml, 'asXML')) {
        $d = $xml ? htmlspecialchars($xml
          ->asXML()) : '';
      }
      else {
        $d = $xml ? htmlspecialchars(print_r($xml, 1)) : '';
      }
      $this
        ->app()
        ->debug('SQL: ' . $sql, '<pre> SQL:' . $sql . "\n XML: " . $d . "\n</pre>");
    }
    return $xml;
  }
  else {
    return NULL;
  }
}