Browse Source

* Patch from Dmitry Boyarintsev to support empty statements

git-svn-id: trunk@17545 -
michael 14 years ago
parent
commit
cbcece1ae6
2 changed files with 22 additions and 1 deletions
  1. 5 0
      packages/fcl-db/src/sql/fpsqlparser.pas
  2. 17 1
      packages/fcl-db/tests/tcparser.pas

+ 5 - 0
packages/fcl-db/src/sql/fpsqlparser.pas

@@ -3758,6 +3758,10 @@ end;
 
 function TSQLParser.Parse: TSQLElement;
 begin
+  if CurrentToken=tsqlEOF then begin
+    Result:=nil;
+    Exit;
+  end;
   GetNextToken;
   Case CurrentToken of
     tsqlSelect : Result:=ParseSelectStatement(Nil,[]);
@@ -3775,6 +3779,7 @@ begin
     tsqlDeclare : Result:=ParseDeclareStatement(Nil);
     tsqlGrant : Result:=ParseGrantStatement(Nil);
     tsqlRevoke : Result:=ParseRevokeStatement(Nil);
+    tsqlEOF : Result:=nil;
   else
     UnexpectedToken;
   end;

+ 17 - 1
packages/fcl-db/tests/tcparser.pas

@@ -831,10 +831,25 @@ type
     procedure Test2RolesToUser;
   end;
 
+  { TTestGlobalParser }
+
+  TTestGlobalParser = Class(TTestSQLParser)
+  published
+    procedure TestEmpty;
+  end;
+
 implementation
 
 uses typinfo;
 
+{ TTestGlobalParser }
+
+procedure TTestGlobalParser.TestEmpty;
+begin
+  CreateParser('');
+  AssertNull('Empty statement returns nil',Parser.Parse);
+end;
+
 { --------------------------------------------------------------------
   TTestParser
   --------------------------------------------------------------------}
@@ -7991,6 +8006,7 @@ initialization
                  TTestCreateTriggerParser,
                  TTestDeclareExternalFunctionParser,
                  TTestGrantParser,
-                 TTestRevokeParser]);
+                 TTestRevokeParser,
+                 TTestGlobalParser]);
 end.