33
44use Vimeo \MysqlEngine \TokenType ;
55use Vimeo \MysqlEngine \Query \Expression \ConstantExpression ;
6- use Vimeo \MysqlEngine \Query \Expression \ParameterExpression ;
6+ use Vimeo \MysqlEngine \Query \Expression \NamedPlaceholderExpression ;
7+ use Vimeo \MysqlEngine \Query \Expression \QuestionMarkPlaceholderExpression ;
78use Vimeo \MysqlEngine \Query \LimitClause ;
89
910final class LimitParser
@@ -45,7 +46,13 @@ public function parse()
4546 if ($ next ->type === TokenType::NUMERIC_CONSTANT ) {
4647 $ limit = new ConstantExpression ($ next );
4748 } elseif ($ next ->type === TokenType::IDENTIFIER && $ next ->value === '? ' ) {
48- $ limit = new ParameterExpression ($ next , $ next ->parameterName );
49+ if ($ next ->parameterOffset !== null ) {
50+ $ limit = new QuestionMarkPlaceholderExpression ($ next , $ next ->parameterOffset );
51+ } elseif ($ next ->parameterName !== null ) {
52+ $ limit = new NamedPlaceholderExpression ($ next , $ next ->parameterName );
53+ } else {
54+ throw new ParserException ('? encountered with unknown offset ' );
55+ }
4956 } else {
5057 throw new ParserException ("Expected integer or parameter after OFFSET " );
5158 }
@@ -64,7 +71,7 @@ public function parse()
6471 if ($ next ->type === TokenType::NUMERIC_CONSTANT ) {
6572 $ offset = new ConstantExpression ($ next );
6673 } elseif ($ next ->type === TokenType::IDENTIFIER && $ next ->value === '? ' ) {
67- $ offset = new ParameterExpression ($ next , $ next ->parameterName );
74+ $ offset = new NamedPlaceholderExpression ($ next , $ next ->parameterName );
6875 } else {
6976 throw new ParserException ("Expected integer or parameter after OFFSET " );
7077 }
@@ -81,7 +88,7 @@ public function parse()
8188 if ($ next ->type === TokenType::NUMERIC_CONSTANT ) {
8289 $ limit = new ConstantExpression ($ next );
8390 } elseif ($ next ->type === TokenType::IDENTIFIER && $ next ->value === '? ' ) {
84- $ limit = new ParameterExpression ($ next , $ next ->parameterName );
91+ $ limit = new NamedPlaceholderExpression ($ next , $ next ->parameterName );
8592 } else {
8693 throw new ParserException ("Expected integer or parameter after OFFSET " );
8794 }
0 commit comments