Verified Commit 75d0486a authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Manage current

parent b413a146
......@@ -68,6 +68,8 @@ class Lexer
'UNIQUE' => LAABS_T_UNIQUE,
'COUNT' => LAABS_T_COUNT,
'SUMMARISE'=> LAABS_T_SUMMARISE,
'NEXT' => LAABS_T_NEXT,
'CURRENT' => LAABS_T_CURRENT,
);
/**
......
......@@ -27,6 +27,8 @@ class Parser
LAABS_T_DELETE => 'LAABS_T_DELETE',
LAABS_T_COUNT => 'LAABS_T_COUNT',
LAABS_T_SUMMARISE => 'LAABS_T_SUMMARISE',
LAABS_T_NEXT => 'LAABS_T_NEXT',
LAABS_T_CURRENT => 'LAABS_T_CURRENT',
LAABS_T_OPEN_PARENTHESIS => 'LAABS_T_OPEN_PARENTHESIS',
LAABS_T_CLOSE_PARENTHESIS => 'LAABS_T_CLOSE_PARENTHESIS',
......@@ -85,6 +87,8 @@ class Parser
LAABS_T_DELETE,
LAABS_T_COUNT,
LAABS_T_SUMMARISE,
LAABS_T_NEXT,
LAABS_T_CURRENT,
),
'operand' => array(
LAABS_T_VAR,
......@@ -197,6 +201,11 @@ class Parser
case LAABS_T_SUMMARISE:
$this->parseSummariseQuery();
break;
case LAABS_T_NEXT:
case LAABS_T_CURRENT:
$this->parseSequenceQuery();
break;
}
// RETURN INTO
......@@ -354,6 +363,32 @@ class Parser
}
}
protected function parseSequenceQuery()
{
// Parse class (schema/class)
$this->next();
$this->expect($this->tokenTypes['name']);
if ($this->isNext(LAABS_T_NS_SEPARATOR)) {
$schemaName = $this->value();
// Skip NS separator
$this->next();
// Move to class name
$this->next();
$this->expect($this->tokenTypes['name']);
$className = $this->value();
} elseif ($this->schema) {
$className = $this->value();
$schemaName = $this->schema;
} else {
throw new \Exception("Invalid qualified class name: no schema provided for class '$className'");
}
$this->query->setClass($schemaName.'/'.$className);
}
protected function parseCountQuery()
{
// Parse class (schema/class)
......
......@@ -146,6 +146,7 @@ const LAABS_T_UPDATE = "T_UPDATE";
const LAABS_T_DELETE = "T_DELETE";
const LAABS_T_COUNT = "T_COUNT";
const LAABS_T_NEXT = "T_NEXT";
const LAABS_T_CURRENT = "T_CURRENT";
const LAABS_T_SUMMARISE = "T_SUMMARISE";
// Switches
......
......@@ -65,7 +65,8 @@ abstract class AbstractCompiler
break;
case strtolower(LAABS_T_NEXT):
$queryString = $this->getNextStatement($query);
case strtolower(LAABS_T_CURRENT):
$queryString = $this->getSequenceStatement($query);
break;
}
......@@ -222,7 +223,7 @@ abstract class AbstractCompiler
*
* @return string the SQL query string
*/
protected function getNextStatement($query)
protected function getSequenceStatement($query)
{
$selectStatement = $this->getSelectClause($query);
......@@ -296,6 +297,10 @@ abstract class AbstractCompiler
$selectClause .= ' NEXTVAL('.$this->getString($this->getNameExpression($this->getBinding($query->getClass()))).')';
break;
case LAABS_T_CURRENT:
$selectClause .= ' CURRVAL('.$this->getString($this->getNameExpression($this->getBinding($query->getClass()))).')';
break;
default:
$selectClause .= ' ' . $this->getSelectList($query);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment