public function FrxPDO::sqlData in Forena Reports 7.4
Same name and namespace in other branches
- 7.3 plugins/FrxPDO.inc \FrxPDO::sqlData()
Get data based on file data block in the repository.
Parameters
String $block_name:
Array $parm_data:
Query $subQuery:
Overrides FrxDataSource::sqlData
File
- plugins/
FrxPDO.inc, line 95 - General database engine used to do sql queries.
Class
- FrxPDO
- @file General database engine used to do sql queries.
Code
public function sqlData($sql, $options = array()) {
// Load the block from the file
$db = $this->db;
$xml = '';
// Load the types array based on data
$this->types = isset($options['type']) ? $options['type'] : array();
if ($sql && $db) {
$time_start = microtime(true);
$sql = $this->te
->replace($sql);
try {
$rs = $db
->query($sql);
} catch (PDOException $e) {
watchdog_exception('error', $e);
$line = $e
->getLine();
$text = $e
->getMessage();
drupal_set_message($short, 'error', FALSE);
return;
}
if (@$options['return_type'] == 'raw') {
return $rs;
}
$xml = new SimpleXMLElement('<table/>');
$e = $db
->errorCode();
if ($e != '00000') {
$i = $db
->errorInfo();
$text = $i[0] . ':' . $i[2];
//if (user_access('build forena sql blocks')) {
if (!$this->block_name) {
$short = t('%e', array(
'%e' => $text,
));
}
else {
$short = t('SQL Error in %b.sql', array(
'%b' => $this->block_name,
));
}
$this
->error($short, $text);
}
else {
if ($rs && $rs
->columnCount()) {
if (@$options['return_type'] == 'raw') {
return $rs;
}
$rownum = 0;
foreach ($rs as $data) {
$rownum++;
$row_node = $xml
->addChild('row');
$row_node['num'] = $rownum;
foreach ($data as $key => $value) {
$row_node
->addChild($key, htmlspecialchars($value));
}
}
}
}
$time_end = microtime(true);
if ($this->debug) {
$d = '';
if ($xml) {
$d = htmlspecialchars($xml
->asXML());
}
$elapsed = (int) (($time_end - $time_start) * 1000.0);
$this
->debug("SQL ({$elapsed}ms): " . $sql, '<pre> SQL:' . $sql . "\n XML: " . $d . "/n</pre>");
}
return $xml;
}
}