You are here

public function DataManager::sqlData in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/DataManager.php \Drupal\forena\DataManager::sqlData()

Execute sql on a provider

Parameters

$provider String Data provider index to reference:

$sql String sql command to execute:

Return value

\SimpleXMLElement | array Data returned by executed sql query.

File

src/DataManager.php, line 246
DataManager.inc Enter description here ... @author davidmetzler

Class

DataManager

Namespace

Drupal\forena

Code

public function sqlData($provider, $sql, $parms = array()) {
  $xml = '';

  //Intstantiate the provider

  /** @var \Drupal\forena\FrxPlugin\Driver\DriverBase $o */
  $o = $this
    ->repository($provider);
  $repos = @$this->repositories[$provider];
  if (isset($repos['enabled']) && !$repos['enabled']) {
    return '';
  }

  //Populate user callback.
  if (isset($repos['user callback'])) {
    $user_fn = $repos['user callback'];
    if (is_callable($user_fn)) {
      $current_user = $user_fn();
      $parms['current_user'] = $current_user;
    }
  }
  if ($o && $sql) {
    $this->dataSvc
      ->push($parms, 'parm');

    // Parse the sql file
    $data = $o
      ->parseSQLFile($sql);

    //now get the built SQL back
    $sql = $data['source'];
    $xml = $o
      ->sqlData($sql, @$data['options']);
    $this->dataSvc
      ->pop();
  }
  return $xml;
}