public function query($query)
{
$this->logger->log($query);
$query_type = $this->determine_query_type($query);
$data = array();
if ($query_type == SQL_SELECT || $query_type == SQL_SHOW) {
$res = pg_query($this->conn, $query);
if ($this->isError($res)) {
throw new Ruckusing_Exception(sprintf("Error executing 'query' with:\n%s\n\nReason: %s\n\n", $query, pg_last_error($this->conn)), Ruckusing_Exception::QUERY_ERROR);
}
while ($row = pg_fetch_assoc($res)) {
$data[] = $row;
}
return $data;
} else {
// INSERT, DELETE, etc...
$res = pg_query($this->conn, $query);
if ($this->isError($res)) {
throw new Ruckusing_Exception(sprintf("Error executing 'query' with:\n%s\n\nReason: %s\n\n", $query, pg_last_error($this->conn)), Ruckusing_Exception::QUERY_ERROR);
}
// if the query contained a 'RETURNING' class then grab its value
$returning_regex = '/ RETURNING \\"(.+)\\"$/';
$matches = array();
if (preg_match($returning_regex, $query, $matches)) {
if (count($matches) == 2) {
$returning_column_value = pg_fetch_result($res, 0, $matches[1]);
return $returning_column_value;
}
}
return true;
}
}