sql parser: support "SELECT 'a' 'b'" syntax (MSSQL)

git-svn-id: trunk@46472 -
This commit is contained in:
ondrej 2020-08-17 13:56:14 +00:00
parent b5c8ac7769
commit 0b440758ea
2 changed files with 20 additions and 2 deletions

View File

@ -501,11 +501,11 @@ begin
F:=TSQLSelectField(CreateElement(TSQLSelectField,AParent));
AList.Add(F);
F.Expression:=Expression;
If CurrentToken in [tsqlAs,Tsqlidentifier] then
If CurrentToken in [tsqlAs,Tsqlidentifier,tsqlString] then
begin
If currentToken=tsqlAs then
GetNextToken;
Expect(tsqlIdentifier);
Expect([tsqlIdentifier,tsqlString]);
F.AliasName:=CreateIdentifier(F,CurrentTokenString);
GetNextToken;
end;

View File

@ -419,6 +419,7 @@ type
procedure TestSelectTwoFieldsThreeBracketTablesJoin;
procedure TestSelectTableWithSchema;
procedure TestSelectFieldWithSchema;
procedure TestSelectFieldAsStringLiteral;
procedure TestSelectFirst;
procedure TestSelectFirstSkip;
procedure TestSelectTop;
@ -3839,6 +3840,23 @@ begin
AssertException(ESQLParser,@TestParseError);
end;
procedure TTestSelectParser.TestSelectFieldAsStringLiteral;
Var
F : TSQLSelectField;
L : TSQLStringLiteral;
begin
TestSelect('SELECT ''B'' ''C'''); // 'B' as 'C'
AssertEquals('One field',1,Select.Fields.Count);
F:=TSQLSelectField(CheckClass(Select.Fields[0],TSQLSelectField));
AssertNotNull('Have field expresssion,',F.Expression);
L:=TSQLStringLiteral(AssertLiteralExpr('Field is a literal',F.Expression,TSQLStringLiteral));
AssertEquals('Field literal is B','B',L.Value);
AssertEquals('Field alias is C','C',F.AliasName.Name);
AssertEquals('No table',0,Select.Tables.Count);
end;
procedure TTestSelectParser.TestSelectFieldWithSchema;
Var