You are here

private function FrxOracle::oracle_xml in Forena Reports 8

Generate xml from sql using the provided f_forena

Parameters

string $sql: SQL statement to executee

Return value

SimpleXMLElement XML representation of data

1 call to FrxOracle::oracle_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 137
Oracle specific driver that takes advantage of oracles native XML support

Class

FrxOracle
Class FrxOracle

Namespace

Drupal\forena\FrxPlugin\Driver

Code

private function oracle_xml($sql, $block) {
  $db = $this->db;

  //$rs->debugDumpParams();
  $fsql = 'declare x XMLTYPE; begin x := f_forena_xml(:p1); :ret_val := x.getClobVal();  end; ';
  $stmt = oci_parse($db, $fsql);
  $ret = oci_new_descriptor($db, OCI_D_LOB);
  oci_bind_by_name($stmt, ':ret_val', $ret, -1, OCI_B_CLOB);
  oci_bind_by_name($stmt, ':p1', $sql);
  $r = oci_execute($stmt, OCI_DEFAULT);

  // Report errors
  if (!$r) {
    $e = oci_error($stmt);

    // For oci_execute errors pass the statement handle
    $msg = htmlentities($e['message']);
    $msg .= "\n<pre>\n";
    $msg .= htmlentities($e['sqltext']);

    //printf("\n%".($e['offset']+1)."s", "^");
    $msg .= "\n</pre>\n";
    $this
      ->app()
      ->error('Database error in ' . $this->block_name . ' see logs for info', $msg);
    return NULL;
  }
  $xml_text = $ret
    ->load();
  if ($xml_text) {
    $xml = new \SimpleXMLElement($xml_text);
    if ($xml
      ->getName() == 'error') {
      if (!$this->block_name) {
        $short = t('%e.', array(
          '%e' => (string) $xml,
        ));
      }
      else {
        $short = t('%e in %b.sql', array(
          '%e' => (string) $xml,
          '%b' => $this->block_name,
        ));
      }
      $msg = (string) $xml . ' in ' . $this->block_name . '.sql. ';
      $this
        ->app()
        ->error($short, $msg . ' in <pre> ' . $sql . '</pre>');
    }
  }
  oci_free_statement($stmt);
  return $xml;
}