public function FrxPostgres::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: Value to be formatted
string $key: the token being replaced.
bool $raw: TRUE implies that the value should not be formatted for human consumption.
Return value
Formatted value
File
- src/
FrxPlugin/ Driver/ FrxPostgres.php, line 188 - Postgres specific driver that takes advantage of native XML support
Class
- FrxPostgres
- Class FrxPostgres
Namespace
Drupal\forena\FrxPlugin\DriverCode
public function format($value, $key, $raw = FALSE) {
if ($raw) {
return $value;
}
$value = $this
->parmConvert($key, $value);
if ($value === '' || $value === NULL) {
$value = 'NULL';
}
else {
if (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 .= "'" . pg_escape_string($v) . "'";
}
$value = $val;
}
}
elseif (is_int($value)) {
$value = (int) $value;
$value = (string) $value;
}
elseif (is_float($value)) {
$value = (double) $value;
$value = (string) $value;
}
else {
$value = trim($value);
$value = "'" . pg_escape_string($value) . "'";
}
}
return $value;
}