You are here

private function FrxOracle::php_xml in Forena Reports 8

1 call to FrxOracle::php_xml()
FrxOracle::sqlData in src/FrxPlugin/Driver/FrxOracle.php
Get data based on file data block in the repository.

File

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

Class

FrxOracle
Class FrxOracle

Namespace

Drupal\forena\FrxPlugin\Driver

Code

private function php_xml($sql, $options = array()) {
  $db = $this->db;
  $raw_rows = array();
  $xml = new \SimpleXMLElement('<table/>');

  //$rs->debugDumpParams();
  $stmt = oci_parse($db, $sql);
  @oci_execute($stmt);
  $raw = @$options['return_type'] == 'raw';
  $e = oci_error($stmt);

  // For oci_execute errors pass the statement handle

  //drupal_set_message(e_display_array($e));
  if ($e) {
    if ($e['code'] != '1403') {
      if (!$this->block_name) {
        $short = t('%e at offset %o', array(
          '%e' => $e['message'],
          '%o' => $e['offset'],
        ));
      }
      else {
        $short = t('%e in %b.sql line %o', array(
          '%e' => $e['message'],
          '%b' => $this->block_name,
          '%o' => $e['offset'],
        ));
      }
      $msg = htmlentities($e['message']);
      $msg .= "\n<pre>\n";
      $msg .= htmlentities($e['sqltext']);
      $msg .= "\n</pre>\n";
      $this
        ->app()
        ->error($short, $msg);
      return '';
    }
  }
  $use_limit = isset($options['limit']);
  if ($use_limit) {
    $limit = $options['limit'];
  }
  $rownum = 0;
  while (($row = oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS)) && (!$use_limit || $row < $limit)) {
    $rownum++;
    if ($raw) {
      $raw_rows[] = (object) array_change_key_case($row);
    }
    else {
      $row_node = $xml
        ->addChild('row');
      $row_node['num'] = $rownum;
      foreach ($row as $key => $value) {
        $row_node
          ->addChild(strtolower($key), @htmlspecialchars($value));
      }
    }
  }
  oci_free_statement($stmt);
  if ($raw) {
    return $raw_rows;
  }
  return $xml;
}