|
@@ -59,8 +59,10 @@ Type
|
|
procedure Expect(aToken: TSQLToken);
|
|
procedure Expect(aToken: TSQLToken);
|
|
// Verify that current token is one of the expected tokens; raise error if not
|
|
// Verify that current token is one of the expected tokens; raise error if not
|
|
procedure Expect(aTokens: TSQLTokens);
|
|
procedure Expect(aTokens: TSQLTokens);
|
|
- // Expects aToken as current token and eats it
|
|
|
|
|
|
+ // Expects aToken as current token and eats it by calling GetNextToken
|
|
procedure Consume(aToken: TSQLToken);
|
|
procedure Consume(aToken: TSQLToken);
|
|
|
|
+ // Expects aTokens tokens and eats the token by calling GetNextToken
|
|
|
|
+ procedure Consume(aTokens: TSQLTokens);
|
|
procedure Error(Msg : String);
|
|
procedure Error(Msg : String);
|
|
procedure Error(Fmt : String; Args : Array of const);
|
|
procedure Error(Fmt : String; Args : Array of const);
|
|
// Expression support
|
|
// Expression support
|
|
@@ -99,6 +101,7 @@ Type
|
|
function ParseCreateViewStatement(AParent: TSQLElement; IsAlter: Boolean): TSQLCreateOrAlterStatement;
|
|
function ParseCreateViewStatement(AParent: TSQLElement; IsAlter: Boolean): TSQLCreateOrAlterStatement;
|
|
function ParseCreateTriggerStatement(AParent: TSQLElement; IsAlter: Boolean): TSQLCreateOrAlterStatement;
|
|
function ParseCreateTriggerStatement(AParent: TSQLElement; IsAlter: Boolean): TSQLCreateOrAlterStatement;
|
|
function ParseSetGeneratorStatement(AParent: TSQLElement) : TSQLSetGeneratorStatement;
|
|
function ParseSetGeneratorStatement(AParent: TSQLElement) : TSQLSetGeneratorStatement;
|
|
|
|
+ function ParseSetTermStatement(AParent: TSQLElement) : TSQLSetTermStatement;
|
|
function ParseCreateDatabaseStatement(AParent: TSQLElement; IsAlter: Boolean ): TSQLCreateDatabaseStatement;
|
|
function ParseCreateDatabaseStatement(AParent: TSQLElement; IsAlter: Boolean ): TSQLCreateDatabaseStatement;
|
|
function ParseCreateShadowStatement(AParent: TSQLElement; IsAlter: Boolean ): TSQLCreateShadowStatement;
|
|
function ParseCreateShadowStatement(AParent: TSQLElement; IsAlter: Boolean ): TSQLCreateShadowStatement;
|
|
function ParseAlterDatabaseStatement(AParent: TSQLElement; IsAlter: Boolean ): TSQLAlterDatabaseStatement;
|
|
function ParseAlterDatabaseStatement(AParent: TSQLElement; IsAlter: Boolean ): TSQLAlterDatabaseStatement;
|
|
@@ -146,6 +149,7 @@ Type
|
|
Function ParseUpdateStatement(AParent : TSQLElement) : TSQLUpdateStatement;
|
|
Function ParseUpdateStatement(AParent : TSQLElement) : TSQLUpdateStatement;
|
|
Function ParseInsertStatement(AParent : TSQLElement) : TSQLInsertStatement;
|
|
Function ParseInsertStatement(AParent : TSQLElement) : TSQLInsertStatement;
|
|
Function ParseDeleteStatement(AParent : TSQLElement) : TSQLDeleteStatement;
|
|
Function ParseDeleteStatement(AParent : TSQLElement) : TSQLDeleteStatement;
|
|
|
|
+ // Parses both create and alter statements
|
|
Function ParseCreateStatement(AParent : TSQLElement; IsAlter : Boolean = False) : TSQLCreateOrAlterStatement;
|
|
Function ParseCreateStatement(AParent : TSQLElement; IsAlter : Boolean = False) : TSQLCreateOrAlterStatement;
|
|
Function ParseDropStatement(AParent : TSQLElement) : TSQLDropStatement;
|
|
Function ParseDropStatement(AParent : TSQLElement) : TSQLDropStatement;
|
|
Function ParseRollbackStatement(AParent : TSQLElement) : TSQLRollbackStatement;
|
|
Function ParseRollbackStatement(AParent : TSQLElement) : TSQLRollbackStatement;
|
|
@@ -156,6 +160,12 @@ Type
|
|
Function ParseRevokeStatement(AParent: TSQLElement): TSQLGrantStatement;
|
|
Function ParseRevokeStatement(AParent: TSQLElement): TSQLGrantStatement;
|
|
Function Parse : TSQLElement;
|
|
Function Parse : TSQLElement;
|
|
Function ParseScript(AllowPartial : Boolean = False) : TSQLElementList;
|
|
Function ParseScript(AllowPartial : Boolean = False) : TSQLElementList;
|
|
|
|
+ // Gets statement terminator (as e.g. used in SET TERM) so statements like
|
|
|
|
+ // EXECUTE BLOCK or CREATE PROCEDURE that contain semicolons can be parsed
|
|
|
|
+ function GetStatementTerminator: string;
|
|
|
|
+ // Sets statement terminator (as e.g. used in SET TERM) so statements like
|
|
|
|
+ // EXECUTE BLOCK or CREATE PROCEDURE that contain semicolons can be parsed
|
|
|
|
+ procedure SetStatementTerminator(AValue: string);
|
|
// Auxiliary stuff
|
|
// Auxiliary stuff
|
|
Function CurrentToken : TSQLToken;
|
|
Function CurrentToken : TSQLToken;
|
|
Function CurrentTokenString : String;
|
|
Function CurrentTokenString : String;
|
|
@@ -253,6 +263,12 @@ begin
|
|
GetNextToken;
|
|
GetNextToken;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TSQLParser.Consume(aTokens: TSQLTokens);
|
|
|
|
+begin
|
|
|
|
+ Expect(aTokens);
|
|
|
|
+ GetNextToken;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TSQLParser.CurSource: String;
|
|
function TSQLParser.CurSource: String;
|
|
begin
|
|
begin
|
|
Result:=FScanner.CurFilename;
|
|
Result:=FScanner.CurFilename;
|
|
@@ -304,7 +320,8 @@ begin
|
|
Result.SourcePos:=CurPos;
|
|
Result.SourcePos:=CurPos;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseTableRef(AParent : TSQLSelectStatement) : TSQLTableReference;
|
|
|
|
|
|
+function TSQLParser.ParseTableRef(AParent: TSQLSelectStatement
|
|
|
|
+ ): TSQLTableReference;
|
|
Var
|
|
Var
|
|
T : TSQLSimpleTablereference;
|
|
T : TSQLSimpleTablereference;
|
|
J : TSQLJoinTableReference;
|
|
J : TSQLJoinTableReference;
|
|
@@ -362,7 +379,8 @@ begin
|
|
until Not (CurrentToken in [tsqlInner,tsqlJoin,tsqlOuter,tsqlLeft,tsqlRight]);
|
|
until Not (CurrentToken in [tsqlInner,tsqlJoin,tsqlOuter,tsqlLeft,tsqlRight]);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseFromClause(AParent : TSQLSelectStatement; AList : TSQLElementList);
|
|
|
|
|
|
+procedure TSQLParser.ParseFromClause(AParent: TSQLSelectStatement;
|
|
|
|
+ AList: TSQLElementList);
|
|
|
|
|
|
Var
|
|
Var
|
|
T : TSQLTableReference;
|
|
T : TSQLTableReference;
|
|
@@ -380,7 +398,8 @@ begin
|
|
until Done;
|
|
until Done;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseSelectFieldList(AParent : TSQLSelectStatement; AList : TSQLElementList; Singleton : Boolean);
|
|
|
|
|
|
+procedure TSQLParser.ParseSelectFieldList(AParent: TSQLSelectStatement;
|
|
|
|
+ AList: TSQLElementList; Singleton: Boolean);
|
|
Var
|
|
Var
|
|
F : TSQLSelectField;
|
|
F : TSQLSelectField;
|
|
B : Boolean;
|
|
B : Boolean;
|
|
@@ -429,7 +448,8 @@ begin
|
|
until (CurrentToken=tsqlFROM);
|
|
until (CurrentToken=tsqlFROM);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseGroupBy(AParent : TSQLSelectStatement; AList : TSQLElementList);
|
|
|
|
|
|
+procedure TSQLParser.ParseGroupBy(AParent: TSQLSelectStatement;
|
|
|
|
+ AList: TSQLElementList);
|
|
|
|
|
|
Var
|
|
Var
|
|
N : TSQLStringType;
|
|
N : TSQLStringType;
|
|
@@ -455,7 +475,8 @@ begin
|
|
until (CurrentToken<>tsqlComma);
|
|
until (CurrentToken<>tsqlComma);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseForUpdate(AParent : TSQLSelectStatement) : TSQLElementList;
|
|
|
|
|
|
+function TSQLParser.ParseForUpdate(AParent: TSQLSelectStatement
|
|
|
|
+ ): TSQLElementList;
|
|
|
|
|
|
begin
|
|
begin
|
|
// On entry we're on the FOR token.
|
|
// On entry we're on the FOR token.
|
|
@@ -474,7 +495,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseOrderBy(AParent : TSQLSelectStatement; AList : TSQLElementList);
|
|
|
|
|
|
+procedure TSQLParser.ParseOrderBy(AParent: TSQLSelectStatement;
|
|
|
|
+ AList: TSQLElementList);
|
|
|
|
|
|
Var
|
|
Var
|
|
O : TSQLOrderByElement;
|
|
O : TSQLOrderByElement;
|
|
@@ -525,7 +547,7 @@ begin
|
|
until (CurrentToken<>tsqlComma);
|
|
until (CurrentToken<>tsqlComma);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseSelectPlan(AParent : TSQLElement) : TSQLSelectPlan;
|
|
|
|
|
|
+function TSQLParser.ParseSelectPlan(AParent: TSQLElement): TSQLSelectPlan;
|
|
|
|
|
|
Var
|
|
Var
|
|
E : TSQLSelectPlanExpr;
|
|
E : TSQLSelectPlanExpr;
|
|
@@ -789,7 +811,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseTableFieldDef(AParent : TSQLElement) : TSQLTableFieldDef;
|
|
|
|
|
|
+function TSQLParser.ParseTableFieldDef(AParent: TSQLElement): TSQLTableFieldDef;
|
|
begin
|
|
begin
|
|
// on entry, we're on the field name
|
|
// on entry, we're on the field name
|
|
Result:=TSQLTableFieldDef(CreateElement(TSQLTableFieldDef,AParent));
|
|
Result:=TSQLTableFieldDef(CreateElement(TSQLTableFieldDef,AParent));
|
|
@@ -1163,7 +1185,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseProcedureParamList(AParent: TSQLElement; AList : TSQLElementList);
|
|
|
|
|
|
+procedure TSQLParser.ParseProcedureParamList(AParent: TSQLElement;
|
|
|
|
+ AList: TSQLElementList);
|
|
|
|
|
|
Var
|
|
Var
|
|
P : TSQLProcedureParamDef;
|
|
P : TSQLProcedureParamDef;
|
|
@@ -1187,7 +1210,8 @@ begin
|
|
Consume(tsqlBraceClose);
|
|
Consume(tsqlBraceClose);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseCreateProcedureVariableList(AParent: TSQLElement; AList : TSQLElementList);
|
|
|
|
|
|
+procedure TSQLParser.ParseCreateProcedureVariableList(AParent: TSQLElement;
|
|
|
|
+ AList: TSQLElementList);
|
|
|
|
|
|
Var
|
|
Var
|
|
P : TSQLProcedureParamDef;
|
|
P : TSQLProcedureParamDef;
|
|
@@ -1212,7 +1236,7 @@ begin
|
|
Until (CurrentToken<>tsqlDeclare);
|
|
Until (CurrentToken<>tsqlDeclare);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseIfStatement(AParent : TSQLElement) : TSQLIFStatement;
|
|
|
|
|
|
+function TSQLParser.ParseIfStatement(AParent: TSQLElement): TSQLIFStatement;
|
|
|
|
|
|
Var
|
|
Var
|
|
Pt : TSQLToken;
|
|
Pt : TSQLToken;
|
|
@@ -1261,7 +1285,7 @@ begin
|
|
Until (CurrentToken<>tsqlComma);
|
|
Until (CurrentToken<>tsqlComma);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseForStatement(AParent : TSQLElement) : TSQLForStatement;
|
|
|
|
|
|
+function TSQLParser.ParseForStatement(AParent: TSQLElement): TSQLForStatement;
|
|
|
|
|
|
begin
|
|
begin
|
|
// On Entry, we're on the FOR token
|
|
// On Entry, we're on the FOR token
|
|
@@ -1280,7 +1304,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExceptionStatement(AParent : TSQLElement) : TSQLExceptionStatement;
|
|
|
|
|
|
+function TSQLParser.ParseExceptionStatement(AParent: TSQLElement
|
|
|
|
+ ): TSQLExceptionStatement;
|
|
|
|
|
|
begin
|
|
begin
|
|
// On Entry, we're on the EXCEPTION token
|
|
// On Entry, we're on the EXCEPTION token
|
|
@@ -1296,7 +1321,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseAssignStatement(AParent : TSQLElement) : TSQLAssignStatement;
|
|
|
|
|
|
+function TSQLParser.ParseAssignStatement(AParent: TSQLElement
|
|
|
|
+ ): TSQLAssignStatement;
|
|
|
|
|
|
Var
|
|
Var
|
|
N : TSQLStringType;
|
|
N : TSQLStringType;
|
|
@@ -1324,7 +1350,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParsePostEventStatement(AParent : TSQLElement) : TSQLPostEventStatement;
|
|
|
|
|
|
+function TSQLParser.ParsePostEventStatement(AParent: TSQLElement
|
|
|
|
+ ): TSQLPostEventStatement;
|
|
|
|
|
|
begin
|
|
begin
|
|
// On Entry, we're on the POST_EVENT token
|
|
// On Entry, we're on the POST_EVENT token
|
|
@@ -1344,7 +1371,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseWhileStatement(AParent : TSQLElement) : TSQLWhileStatement;
|
|
|
|
|
|
+function TSQLParser.ParseWhileStatement(AParent: TSQLElement
|
|
|
|
+ ): TSQLWhileStatement;
|
|
|
|
|
|
begin
|
|
begin
|
|
// On entry, we're on the WHILE Token
|
|
// On entry, we're on the WHILE Token
|
|
@@ -1362,7 +1390,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseWhenStatement(AParent : TSQLElement) : TSQLWhenStatement;
|
|
|
|
|
|
+function TSQLParser.ParseWhenStatement(AParent: TSQLElement): TSQLWhenStatement;
|
|
|
|
|
|
Var
|
|
Var
|
|
E : TSQLWhenException;
|
|
E : TSQLWhenException;
|
|
@@ -1420,7 +1448,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseProcedureStatement(AParent : TSQLElement) : TSQLStatement;
|
|
|
|
|
|
+function TSQLParser.ParseProcedureStatement(AParent: TSQLElement
|
|
|
|
+ ): TSQLStatement;
|
|
|
|
|
|
begin
|
|
begin
|
|
Result:=Nil;
|
|
Result:=Nil;
|
|
@@ -1455,7 +1484,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseStatementBlock(AParent: TSQLElement; Statements : TSQLElementList);
|
|
|
|
|
|
+procedure TSQLParser.ParseStatementBlock(AParent: TSQLElement;
|
|
|
|
+ Statements: TSQLElementList);
|
|
|
|
|
|
Var
|
|
Var
|
|
S: TSQLStatement;
|
|
S: TSQLStatement;
|
|
@@ -1467,7 +1497,7 @@ begin
|
|
S:=ParseProcedureStatement(AParent);
|
|
S:=ParseProcedureStatement(AParent);
|
|
Statements.Add(S);
|
|
Statements.Add(S);
|
|
if not (PreviousToken=tsqlEnd) then
|
|
if not (PreviousToken=tsqlEnd) then
|
|
- Consume(tsqlSemicolon);
|
|
|
|
|
|
+ Consume([tsqlSemicolon,tsqlStatementTerminator]);
|
|
end;
|
|
end;
|
|
Consume(tsqlEnd);
|
|
Consume(tsqlEnd);
|
|
end;
|
|
end;
|
|
@@ -1538,7 +1568,8 @@ begin
|
|
GetNextToken; // Comma;
|
|
GetNextToken; // Comma;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseCharTypeDefinition(Out DT : TSQLDataType; Out Len : Integer; Out ACharset : TSQLStringType);
|
|
|
|
|
|
+procedure TSQLParser.ParseCharTypeDefinition(out DT: TSQLDataType; out
|
|
|
|
+ Len: Integer; out ACharset: TSQLStringType);
|
|
|
|
|
|
begin
|
|
begin
|
|
Len:=0;
|
|
Len:=0;
|
|
@@ -1592,7 +1623,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Procedure TSQLParser.ParseBlobDefinition(Var ASegmentSize,ABlobType : Integer; Var ACharset : TSQLStringType);
|
|
|
|
|
|
+procedure TSQLParser.ParseBlobDefinition(var ASegmentSize, ABlobType: Integer;
|
|
|
|
+ var ACharset: TSQLStringType);
|
|
|
|
|
|
begin
|
|
begin
|
|
// On entry, we are on the blob token.
|
|
// On entry, we are on the blob token.
|
|
@@ -1647,7 +1679,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseForeignKeyDefinition(AParent : TSQLElement) : TSQLForeignKeyDefinition;
|
|
|
|
|
|
+function TSQLParser.ParseForeignKeyDefinition(AParent: TSQLElement
|
|
|
|
+ ): TSQLForeignKeyDefinition;
|
|
|
|
|
|
// On entry, we're on ON Return true if On delete
|
|
// On entry, we're on ON Return true if On delete
|
|
Function ParseForeignKeyAction (Out Res : TForeignKeyAction) : Boolean;
|
|
Function ParseForeignKeyAction (Out Res : TForeignKeyAction) : Boolean;
|
|
@@ -1723,7 +1756,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseFieldConstraint(AParent : TSQLElement) : TSQLFieldConstraint;
|
|
|
|
|
|
+function TSQLParser.ParseFieldConstraint(AParent: TSQLElement
|
|
|
|
+ ): TSQLFieldConstraint;
|
|
|
|
|
|
Var
|
|
Var
|
|
N : TSQLStringType;
|
|
N : TSQLStringType;
|
|
@@ -1800,7 +1834,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseTypeDefinition(AParent : TSQLElement; Flags : TParseTypeFlags) : TSQLTypeDefinition;
|
|
|
|
|
|
+function TSQLParser.ParseTypeDefinition(AParent: TSQLElement;
|
|
|
|
+ Flags: TParseTypeFlags): TSQLTypeDefinition;
|
|
|
|
|
|
Var
|
|
Var
|
|
TN : String;
|
|
TN : String;
|
|
@@ -2047,7 +2082,8 @@ begin
|
|
Error('Unexpected end of command');
|
|
Error('Unexpected end of command');
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExprLevel1(AParent : TSQLElement; EO : TExpressionOptions) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprLevel1(AParent: TSQLElement; EO: TExpressionOptions
|
|
|
|
+ ): TSQLExpression;
|
|
|
|
|
|
var
|
|
var
|
|
tt: TSQLToken;
|
|
tt: TSQLToken;
|
|
@@ -2098,7 +2134,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseInoperand(AParent : TSQLElement) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseInoperand(AParent: TSQLElement): TSQLExpression;
|
|
|
|
|
|
Var
|
|
Var
|
|
S : TSQLSelectExpression;
|
|
S : TSQLSelectExpression;
|
|
@@ -2133,7 +2169,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExprLevel2(AParent : TSQLElement; EO : TExpressionOptions) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprLevel2(AParent: TSQLElement; EO: TExpressionOptions
|
|
|
|
+ ): TSQLExpression;
|
|
var
|
|
var
|
|
tt: TSQLToken;
|
|
tt: TSQLToken;
|
|
Right : TSQLExpression;
|
|
Right : TSQLExpression;
|
|
@@ -2141,7 +2178,7 @@ var
|
|
T : TSQLTernaryExpression;
|
|
T : TSQLTernaryExpression;
|
|
O : TSQLBinaryOperation;
|
|
O : TSQLBinaryOperation;
|
|
U : TSQLUnaryExpression;
|
|
U : TSQLUnaryExpression;
|
|
- I,bw,doin : Boolean;
|
|
|
|
|
|
+ Inverted,bw,doin : Boolean;
|
|
|
|
|
|
begin
|
|
begin
|
|
{$ifdef debugexpr} Writeln('Level 2 ',TokenInfos[CurrentToken],': ',CurrentTokenString);{$endif debugexpr}
|
|
{$ifdef debugexpr} Writeln('Level 2 ',TokenInfos[CurrentToken],': ',CurrentTokenString);{$endif debugexpr}
|
|
@@ -2150,11 +2187,11 @@ begin
|
|
if (CurrentToken in sqlComparisons) then
|
|
if (CurrentToken in sqlComparisons) then
|
|
begin
|
|
begin
|
|
tt:=CurrentToken;
|
|
tt:=CurrentToken;
|
|
- I:=CurrentToken=tsqlnot;
|
|
|
|
|
|
+ Inverted:=CurrentToken=tsqlnot;
|
|
CheckEOF;
|
|
CheckEOF;
|
|
GetNextToken;
|
|
GetNextToken;
|
|
CheckEOF;
|
|
CheckEOF;
|
|
- if I then
|
|
|
|
|
|
+ if Inverted then
|
|
begin
|
|
begin
|
|
tt:=CurrentToken;
|
|
tt:=CurrentToken;
|
|
if Not (tt in sqlInvertableComparisons) then
|
|
if Not (tt in sqlInvertableComparisons) then
|
|
@@ -2174,12 +2211,13 @@ begin
|
|
GetNextToken;
|
|
GetNextToken;
|
|
if not (tt=tsqlis) then
|
|
if not (tt=tsqlis) then
|
|
UnexpectedToken;
|
|
UnexpectedToken;
|
|
- I:=true;
|
|
|
|
|
|
+ Inverted:=true;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
bw:=False;
|
|
bw:=False;
|
|
doin:=false;
|
|
doin:=false;
|
|
|
|
+ B:=nil; //needed for test later
|
|
Case tt of
|
|
Case tt of
|
|
tsqlLT : O:=boLT;
|
|
tsqlLT : O:=boLT;
|
|
tsqlLE : O:=boLE;
|
|
tsqlLE : O:=boLE;
|
|
@@ -2237,8 +2275,8 @@ begin
|
|
B.Right:=Right;
|
|
B.Right:=Right;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
- If I then
|
|
|
|
- if B.Operation=boIs then
|
|
|
|
|
|
+ If Inverted then
|
|
|
|
+ if (Assigned(B)) and (B.Operation=boIs) then
|
|
B.Operation:=boIsNot
|
|
B.Operation:=boIsNot
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
@@ -2254,7 +2292,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExprLevel3(AParent : TSQLElement; EO : TExpressionOptions) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprLevel3(AParent: TSQLElement; EO: TExpressionOptions
|
|
|
|
+ ): TSQLExpression;
|
|
|
|
|
|
Function NegativeNumber : Boolean; inline;
|
|
Function NegativeNumber : Boolean; inline;
|
|
|
|
|
|
@@ -2302,7 +2341,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExprLevel4(AParent : TSQLElement; EO : TExpressionOptions) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprLevel4(AParent: TSQLElement; EO: TExpressionOptions
|
|
|
|
+ ): TSQLExpression;
|
|
|
|
|
|
var
|
|
var
|
|
tt : TSQLToken;
|
|
tt : TSQLToken;
|
|
@@ -2333,7 +2373,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExprLevel5(AParent : TSQLElement; EO : TExpressionOptions) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprLevel5(AParent: TSQLElement; EO: TExpressionOptions
|
|
|
|
+ ): TSQLExpression;
|
|
|
|
|
|
Var
|
|
Var
|
|
tt : tsqltoken;
|
|
tt : tsqltoken;
|
|
@@ -2365,7 +2406,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExprLevel6(AParent : TSQLElement ; EO : TExpressionOptions ) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprLevel6(AParent: TSQLElement; EO: TExpressionOptions
|
|
|
|
+ ): TSQLExpression;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2399,7 +2441,8 @@ begin
|
|
Result:=ParseExprPrimitive(AParent,EO);
|
|
Result:=ParseExprPrimitive(AParent,EO);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseIdentifierList(AParent : TSQLElement; AList : TSQLelementList) : integer;
|
|
|
|
|
|
+function TSQLParser.ParseIdentifierList(AParent: TSQLElement;
|
|
|
|
+ AList: TSQLelementList): integer;
|
|
|
|
|
|
Var
|
|
Var
|
|
Done : Boolean;
|
|
Done : Boolean;
|
|
@@ -2420,7 +2463,8 @@ begin
|
|
GetNextToken;
|
|
GetNextToken;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseValueList(AParent : TSQLElement; EO : TExpressionOptions) : TSQLElementList;
|
|
|
|
|
|
+function TSQLParser.ParseValueList(AParent: TSQLElement; EO: TExpressionOptions
|
|
|
|
+ ): TSQLElementList;
|
|
|
|
|
|
Var
|
|
Var
|
|
E : TSQLExpression;
|
|
E : TSQLExpression;
|
|
@@ -2467,15 +2511,16 @@ begin
|
|
Error(SErrUnexpectedTokenOf,[CurrentTokenString,S]);
|
|
Error(SErrUnexpectedTokenOf,[CurrentTokenString,S]);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TSQLParser.CreateIdentifier(AParent : TSQLElement; Const AName: TSQLStringType
|
|
|
|
- ): TSQLIdentifierName;
|
|
|
|
|
|
+function TSQLParser.CreateIdentifier(AParent: TSQLElement;
|
|
|
|
+ const AName: TSQLStringType): TSQLIdentifierName;
|
|
begin
|
|
begin
|
|
Result:=TSQLIdentifierName(CreateElement(TSQLIdentifierName,AParent));
|
|
Result:=TSQLIdentifierName(CreateElement(TSQLIdentifierName,AParent));
|
|
Result.Name:=AName;
|
|
Result.Name:=AName;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function TSQLParser.ParseExprAggregate(AParent : TSQLElement; EO : TExpressionOptions) : TSQLAggregateFunctionExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprAggregate(AParent: TSQLElement;
|
|
|
|
+ EO: TExpressionOptions): TSQLAggregateFunctionExpression;
|
|
begin
|
|
begin
|
|
Result:=TSQLAggregateFunctionExpression(CreateElement(TSQLAggregateFunctionExpression,AParent));
|
|
Result:=TSQLAggregateFunctionExpression(CreateElement(TSQLAggregateFunctionExpression,AParent));
|
|
try
|
|
try
|
|
@@ -2514,7 +2559,8 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseExprPrimitive(AParent : TSQLElement; EO : TExpressionOptions) : TSQLExpression;
|
|
|
|
|
|
+function TSQLParser.ParseExprPrimitive(AParent: TSQLElement;
|
|
|
|
+ EO: TExpressionOptions): TSQLExpression;
|
|
|
|
|
|
Var
|
|
Var
|
|
L : TSQLElementList;
|
|
L : TSQLElementList;
|
|
@@ -2900,6 +2946,38 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TSQLParser.ParseSetTermStatement(AParent: TSQLElement
|
|
|
|
+ ): TSQLSetTermStatement;
|
|
|
|
+var
|
|
|
|
+ ExistingStatTerm: string;
|
|
|
|
+begin
|
|
|
|
+ // On entry, we're on the 'TERM' token
|
|
|
|
+ Consume(tsqlTerm) ;
|
|
|
|
+ try
|
|
|
|
+ Result:=TSQLSetTermStatement(CreateElement(TSQLSetTermStatement,AParent));
|
|
|
|
+ expect([tsqlSemiColon,tsqlStatementTerminator,tsqlSymbolLiteral,tsqlString]);
|
|
|
|
+ // Already set the expression's new value to the new terminator, but do not
|
|
|
|
+ // change tSQLStatementTerminator as GetNextToken etc need the old one to
|
|
|
|
+ // detect the closing terminator
|
|
|
|
+ case CurrentToken of
|
|
|
|
+ tsqlSemiColon, tsqlStatementTerminator: Result.NewValue:=TokenInfos[CurrentToken];
|
|
|
|
+ tsqlSymbolLiteral, tsqlString: Result.NewValue:=CurrentTokenString;
|
|
|
|
+ end;
|
|
|
|
+ // Expect the old terminator...
|
|
|
|
+ GetNextToken;
|
|
|
|
+ // Parser will give tsqlSemicolon rather than tsqlStatementTerminator:
|
|
|
|
+ if TokenInfos[tsqlStatementTerminator]=TokenInfos[tsqlSEMICOLON] then
|
|
|
|
+ Expect(tsqlSEMICOLON)
|
|
|
|
+ else
|
|
|
|
+ Expect(tsqlStatementTerminator);
|
|
|
|
+ //... and now set the new terminator:
|
|
|
|
+ TokenInfos[tsqlStatementTerminator]:=Result.NewValue; //process new terminator value
|
|
|
|
+ except
|
|
|
|
+ FreeAndNil(Result);
|
|
|
|
+ Raise;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TSQLParser.ParseSecondaryFile(AParent: TSQLElement) : TSQLDatabaseFileInfo;
|
|
function TSQLParser.ParseSecondaryFile(AParent: TSQLElement) : TSQLDatabaseFileInfo;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -3163,7 +3241,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
function TSQLParser.ParseRollbackStatement(AParent: TSQLElement
|
|
function TSQLParser.ParseRollbackStatement(AParent: TSQLElement
|
|
- ): TSQLRollBackStatement;
|
|
|
|
|
|
+ ): TSQLRollbackStatement;
|
|
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
@@ -3302,7 +3380,8 @@ begin
|
|
// On Entry, we're on the SET statement
|
|
// On Entry, we're on the SET statement
|
|
Consume(tsqlSet);
|
|
Consume(tsqlSet);
|
|
Case CurrentToken of
|
|
Case CurrentToken of
|
|
- tsqlGenerator : Result:=ParseSetGeneratorStatement(AParent)
|
|
|
|
|
|
+ tsqlGenerator : Result:=ParseSetGeneratorStatement(AParent);
|
|
|
|
+ tsqlTerm : Result:=ParseSetTermStatement(AParent);
|
|
else
|
|
else
|
|
// For the time being
|
|
// For the time being
|
|
UnexpectedToken;
|
|
UnexpectedToken;
|
|
@@ -3375,7 +3454,8 @@ begin
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseDeclareFunctionStatement(AParent : TSQLElement) : TSQLDeclareExternalFunctionStatement;
|
|
|
|
|
|
+function TSQLParser.ParseDeclareFunctionStatement(AParent: TSQLElement
|
|
|
|
+ ): TSQLDeclareExternalFunctionStatement;
|
|
|
|
|
|
begin
|
|
begin
|
|
// On entry, we're on the EXTERNAL token
|
|
// On entry, we're on the EXTERNAL token
|
|
@@ -3410,7 +3490,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TSQLParser.ParseDeclareStatement(AParent : TSQLElement) : TSQLStatement;
|
|
|
|
|
|
+function TSQLParser.ParseDeclareStatement(AParent: TSQLElement): TSQLStatement;
|
|
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
@@ -3818,7 +3898,7 @@ begin
|
|
else
|
|
else
|
|
UnexpectedToken;
|
|
UnexpectedToken;
|
|
end;
|
|
end;
|
|
- if Not (CurrentToken in [tsqlEOF,tsqlSemicolon]) then
|
|
|
|
|
|
+ if Not (CurrentToken in [tsqlEOF,tsqlSemicolon,tsqlStatementTerminator]) then
|
|
begin
|
|
begin
|
|
FreeAndNil(Result);
|
|
FreeAndNil(Result);
|
|
if (CurrentToken=tsqlBraceClose) then
|
|
if (CurrentToken=tsqlBraceClose) then
|
|
@@ -3850,6 +3930,16 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TSQLParser.GetStatementTerminator: string;
|
|
|
|
+begin
|
|
|
|
+ result:=TokenInfos[tsqlStatementTerminator];
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TSQLParser.SetStatementTerminator(AValue: string);
|
|
|
|
+begin
|
|
|
|
+ TokenInfos[tsqlStatementTerminator]:=AValue;;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TSQLParser.CurrentToken: TSQLToken;
|
|
function TSQLParser.CurrentToken: TSQLToken;
|
|
begin
|
|
begin
|
|
Result:=FCurrent;
|
|
Result:=FCurrent;
|
|
@@ -3863,13 +3953,14 @@ end;
|
|
function TSQLParser.GetNextToken: TSQLToken;
|
|
function TSQLParser.GetNextToken: TSQLToken;
|
|
begin
|
|
begin
|
|
FPrevious:=FCurrent;
|
|
FPrevious:=FCurrent;
|
|
|
|
+ // Set if not already peeked; otherwise fetch and look
|
|
If (FPeekToken<>tsqlUnknown) then
|
|
If (FPeekToken<>tsqlUnknown) then
|
|
- begin
|
|
|
|
- FCurrent:=FPeekToken;
|
|
|
|
- FCurrentString:=FPeekTokenString;
|
|
|
|
- FPeekToken:=tsqlUnknown;
|
|
|
|
- FPeekTokenString:='';
|
|
|
|
- end
|
|
|
|
|
|
+ begin
|
|
|
|
+ FCurrent:=FPeekToken;
|
|
|
|
+ FCurrentString:=FPeekTokenString;
|
|
|
|
+ FPeekToken:=tsqlUnknown;
|
|
|
|
+ FPeekTokenString:='';
|
|
|
|
+ end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
FCurrent:=FScanner.FetchToken;
|
|
FCurrent:=FScanner.FetchToken;
|