You are here

private function FrxOracle::php_xml in Forena Reports 7.4

Same name and namespace in other branches
  1. 6.2 plugins/FrxOracle.inc \FrxOracle::php_xml()
  2. 6 plugins/FrxOracle.inc \FrxOracle::php_xml()
  3. 7 plugins/FrxOracle.inc \FrxOracle::php_xml()
  4. 7.2 plugins/FrxOracle.inc \FrxOracle::php_xml()
  5. 7.3 plugins/FrxOracle.inc \FrxOracle::php_xml()
1 call to FrxOracle::php_xml()
FrxOracle::sqlData in plugins/FrxOracle.inc
Get data based on file data block in the repository.

File

plugins/FrxOracle.inc, line 161
Oracle specific driver that takes advantage of oracles native XML support

Class

FrxOracle
@file Oracle specific driver that takes advantage of oracles native XML support

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'], NULL, 'UTF-8');
      $msg .= "\n<pre>\n";
      $msg .= htmlentities($e['sqltext'], NULL, 'UTF-8');
      $msg .= "\n</pre>\n";
      $this
        ->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;
}