You are here

public function FrxDrupal::query in Forena Reports 8

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

File

src/FrxPlugin/Driver/FrxDrupal.php, line 84
Provides data blocks for native drupal connections using the default drupal connections.

Class

FrxDrupal
Class FrxDrupal

Namespace

Drupal\forena\FrxPlugin\Driver

Code

public function query($sql, $options = array()) {
  if ($this->database != 'default') {
    db_set_active($this->database);
  }

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

  // Load the block from the file
  $xml = '';
  $sql = $this->te
    ->replace($sql);
  try {
    if (@(int) $options['limit']) {
      $rs = db_query_range($sql, 0, (int) $options['limit']);
    }
    else {
      $rs = db_query($sql);
    }
  } catch (DatabaseExceptionWrapper $e) {
    $line = $e
      ->getLine();
    $text = $e
      ->getMessage();

    //if (user_access('build forena sql blocks')) {
    if (!$this->block_name) {
      $short = t('%e', array(
        '%e' => $text,
        '%l' => $line,
      ));
    }
    else {
      $short = t('SQL Error in %b.sql', array(
        '%b' => $this->block_name,
      ));
    }
    $this
      ->app()
      ->error($short, $text);
    if ($this->database != 'default') {
      db_set_active();
    }
  }
  if ($this->database != 'default') {
    db_set_active();
  }
  return $rs;
}