You are here

public function FrxDrupal::query in Forena Reports 7.5

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

File

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

Class

FrxDrupal

Namespace

Drupal\forena\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 (PDOException $e) {
    watchdog_exception('error', $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,
      ));
    }
    drupal_set_message($short, 'error', FALSE);
    if ($this->database != 'default') {
      db_set_active();
    }
    return;
  }
  if ($this->database != 'default') {
    db_set_active();
  }
  return $rs;
}