瀏覽代碼

* Do only add parentheses when necessary for filtering. So that when the
query parser fails this only leads to problem when the filter is used

git-svn-id: trunk@15199 -

joost 15 年之前
父節點
當前提交
a4a1cd76e5
共有 1 個文件被更改,包括 9 次插入9 次删除
  1. 9 9
      packages/fcl-db/src/sqldb/sqldb.pp

+ 9 - 9
packages/fcl-db/src/sqldb/sqldb.pp

@@ -235,7 +235,7 @@ type
     procedure OnChangeSQL(Sender : TObject);
     procedure OnChangeModifySQL(Sender : TObject);
     procedure Execute;
-    Function SQLParser(var ASQL : string) : TStatementType;
+    Function SQLParser(const ASQL : string) : TStatementType;
     procedure ApplyFilter;
     Function AddFilter(SQLstr : string) : string;
   protected
@@ -861,10 +861,16 @@ end;
 Function TCustomSQLQuery.AddFilter(SQLstr : string) : string;
 
 begin
+  if (FWhereStartPos > 0) and (FWhereStopPos > 0) then
+    begin
+    system.insert('(',SQLstr,FWhereStartPos+1);
+    system.insert(')',SQLstr,FWhereStopPos+1);
+    end;
+
   if FWhereStartPos = 0 then
     SQLstr := SQLstr + ' where (' + Filter + ')'
   else if FWhereStopPos > 0 then
-    system.insert(' and ('+ServerFilter+') ',SQLstr,FWhereStopPos+1)
+    system.insert(' and ('+ServerFilter+') ',SQLstr,FWhereStopPos+2)
   else
     system.insert(' where ('+ServerFilter+') ',SQLstr,FWhereStartPos);
   Result := SQLstr;
@@ -1060,7 +1066,7 @@ begin
   end;
 end;
 
-function TCustomSQLQuery.SQLParser(var ASQL : string) : TStatementType;
+function TCustomSQLQuery.SQLParser(const ASQL : string) : TStatementType;
 
 type TParsePart = (ppStart,ppSelect,ppWhere,ppFrom,ppOrder,ppComment,ppGroup,ppBogus);
 
@@ -1206,12 +1212,6 @@ begin
       end
     end;
   until CurrentP^=#0;
-  if (FWhereStartPos > 0) and (FWhereStopPos > 0) then
-    begin
-    system.insert('(',ASQL,FWhereStartPos+1);
-    inc(FWhereStopPos);
-    system.insert(')',ASQL,FWhereStopPos);
-    end
 end;
 
 procedure TCustomSQLQuery.InternalOpen;