Merge pull request #228 from joaoduarte19/rql_changes

Added Boolean type support in RQLParser
This commit is contained in:
Daniele Teti 2019-06-11 22:47:06 +02:00 committed by GitHub
commit f78953c83f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 4 deletions

View File

@ -83,6 +83,13 @@ var
begin
if aRQLFIlter.RightValueType = vtString then
lValue := aRQLFIlter.OpRight.QuotedString('''')
else if aRQLFIlter.RightValueType = vtBoolean then
begin
if SameText(aRQLFIlter.OpRight, 'true') then
lValue := '1'
else
lValue := '0';
end
else
lValue := aRQLFIlter.OpRight;

View File

@ -91,6 +91,13 @@ var
begin
if aRQLFIlter.RightValueType = vtString then
lValue := aRQLFIlter.OpRight.QuotedString('''')
else if aRQLFIlter.RightValueType = vtBoolean then
begin
if SameText(aRQLFIlter.OpRight, 'true') then
lValue := '1'
else
lValue := '0';
end
else
lValue := aRQLFIlter.OpRight;

View File

@ -82,6 +82,13 @@ var
begin
if aRQLFIlter.RightValueType = vtString then
lValue := aRQLFIlter.OpRight.QuotedString('''')
else if aRQLFIlter.RightValueType = vtBoolean then
begin
if SameText(aRQLFIlter.OpRight, 'true') then
lValue := '1'
else
lValue := '0';
end
else
lValue := aRQLFIlter.OpRight;

View File

@ -78,7 +78,7 @@ type
tkOpenPar, tkClosedPar, tkOpenBracket, tkCloseBracket, tkComma, tkSemicolon, tkPlus, tkMinus, tkDblQuote,
tkQuote, tkSpace, tkContains, tkIn, tkUnknown);
TRQLValueType = (vtInteger, vtString, vtIntegerArray, vtStringArray);
TRQLValueType = (vtInteger, vtString, vtBoolean, vtIntegerArray, vtStringArray);
TRQLCustom = class;
@ -187,6 +187,7 @@ type
function MatchFieldStringValue(out lFieldValue: string): Boolean;
function MatchFieldNumericValue(out lFieldValue: string): Boolean;
function MatchFieldArrayValue(out lFieldValue: string): Boolean;
function MatchFieldBooleanValue(out lFieldValue: string): Boolean;
function MatchSymbol(const Symbol: Char): Boolean;
procedure SaveCurPos;
procedure BackToLastPos;
@ -613,9 +614,13 @@ begin
else
begin
BackToLastPos;
if not MatchFieldNumericValue(lFieldValue) then
Error('Expected numeric value');
lValueType := vtInteger;
if MatchFieldBooleanValue(lFieldValue) then
lValueType := vtBoolean
else if MatchFieldNumericValue(lFieldValue) then
lValueType := vtInteger
else
Error('Expected numeric or boolean value');
end;
EatWhiteSpaces;
if GetToken <> tkClosedPar then
@ -857,6 +862,30 @@ begin
Result := False;
end;
function TRQL2SQL.MatchFieldBooleanValue(out lFieldValue: string): Boolean;
var
lChar: Char;
begin
Result := True;
lFieldValue := '';
lChar := C(0).ToLower;
if (lChar = 't') and (C(1).ToLower = 'r') and (C(2).ToLower = 'u') and (C(3).ToLower = 'e') then
begin
Skip(4);
Result := True;
lFieldValue := 'true';
end
else if (lChar = 'f') and (C(1).ToLower = 'a') and (C(2).ToLower = 'l') and (C(3).ToLower = 's') and (C(4).ToLower = 'e') then
begin
Skip(5);
Result := True;
lFieldValue := 'false';
end
else
Exit(False)
end;
function TRQL2SQL.MatchFieldName(out lFieldName: string): Boolean;
var
lChar: Char;

View File

@ -1,3 +1,5 @@
eq(value,false)
eq(value,true)
in ( value , [ 1 , 2 , 3 ] )
in ( value , [ 1 , 2 , 3 ] )
in(value,[])