function query($q, $result_format = '', $src = '', $keep_bnode_ids = 0)
{
/* Parse query */
ARC2::inc('SPARQLPlusParser');
$p =& new ARC2_SPARQLPlusParser($this->a, $this);
$p->parse($q, $src);
$infos = $p->getQueryInfos();
$infos['result_format'] = $result_format;
if (!$p->getErrors()) {
/* Check and execute query */
$qt = $infos['query']['type'];
if (!in_array($qt, array('select', 'ask', 'describe', 'construct', 'load', 'insert', 'delete'))) {
return $this->addError('Unsupported query type "' . $qt . '"');
}
$t1 = ARC2::mtime();
$r = array('result' => $this->runQuery($qt, $q));
$t2 = ARC2::mtime();
$r['query_time'] = $t2 - $t1;
if ($result_format == 'raw') {
return $r['result'];
}
if ($result_format == 'rows') {
return $r['result']['rows'] ? $r['result']['rows'] : array();
}
if ($result_format == 'row') {
return $r['result']['rows'] ? $r['result']['rows'][0] : array();
}
return $r;
}
return 0;
}