You are here

public function FrxPDO::format in Forena Reports 8

Implement custom SQL formatter to make sure that strings are properly escaped. Ideally we'd replace this with something that handles prepared statements, but it wouldn't work for

Parameters

string $value: The value being formatted.

string $key: The name of the token being replaced.

bool $raw: TRUE implies the value should not be formatted for human consumption.

Return value

string Formatted value.

File

src/FrxPlugin/Driver/FrxPDO.php, line 210
General database engine used to do sql queries.

Class

FrxPDO
Class FrxPDO

Namespace

Drupal\forena\FrxPlugin\Driver

Code

public function format($value, $key, $raw = FALSE) {
  if ($raw) {
    return $value;
  }
  $db = $this->db;
  $value = $this
    ->parmConvert($key, $value);
  if ($db) {
    if ($value === '' || $value === NULL || $value === array()) {
      $value = 'NULL';
    }
    elseif (is_int($value)) {
      $value = (int) $value;
      $value = (string) $value;
    }
    elseif (is_float($value)) {
      $value = (double) $value;
      $value = (string) $value;
    }
    elseif (is_array($value)) {
      if ($value == array()) {
        $value = 'NULL';
      }
      else {

        // Build a array of values string
        $i = 0;
        $val = '';
        foreach ($value as $v) {
          $i++;
          if ($i != 1) {
            $val .= ',';
          }
          $val .= $this
            ->quote($v);
        }
        $value = $val;
      }
    }
    else {
      $value = $this
        ->quote($value);
    }
  }
  return (string) $value;
}