* Changed SQLParser in a function which returns the obtained statement-type instead of setting the statementtype of the cursor directly, second part of r12512

git-svn-id: trunk@12513 -
This commit is contained in:
joost 2009-01-05 13:01:44 +00:00
parent d6903a4bb6
commit 11015eb6ad

View File

@ -222,7 +222,7 @@ type
procedure OnChangeSQL(Sender : TObject); procedure OnChangeSQL(Sender : TObject);
procedure OnChangeModifySQL(Sender : TObject); procedure OnChangeModifySQL(Sender : TObject);
procedure Execute; procedure Execute;
Procedure SQLParser(var ASQL : string); Function SQLParser(var ASQL : string) : TStatementType;
procedure ApplyFilter; procedure ApplyFilter;
Function AddFilter(SQLstr : string) : string; Function AddFilter(SQLstr : string) : string;
protected protected
@ -898,8 +898,9 @@ end;
procedure TCustomSQLQuery.Prepare; procedure TCustomSQLQuery.Prepare;
var var
db : tsqlconnection; db : tsqlconnection;
sqltr : tsqltransaction; sqltr : tsqltransaction;
StmType: TStatementType;
begin begin
if not IsPrepared then if not IsPrepared then
@ -919,7 +920,7 @@ begin
if FSQLBuf = '' then if FSQLBuf = '' then
DatabaseError(SErrNoStatement); DatabaseError(SErrNoStatement);
SQLParser(FSQLBuf); StmType:=SQLParser(FSQLBuf);
// There may no error occur between the allocation of the cursor and // There may no error occur between the allocation of the cursor and
// the preparation of the cursor. Because internalclose (which is called in // the preparation of the cursor. Because internalclose (which is called in
@ -929,7 +930,7 @@ begin
// unpredictable results. // unpredictable results.
if not assigned(fcursor) then if not assigned(fcursor) then
FCursor := Db.AllocateCursorHandle; FCursor := Db.AllocateCursorHandle;
FCursor.FStatementType:=StmType;
if ServerFiltered then if ServerFiltered then
Db.PrepareStatement(Fcursor,sqltr,AddFilter(FSQLBuf),FParams) Db.PrepareStatement(Fcursor,sqltr,AddFilter(FSQLBuf),FParams)
else else
@ -1027,7 +1028,7 @@ begin
end; end;
end; end;
procedure TCustomSQLQuery.SQLParser(var ASQL : string); function TCustomSQLQuery.SQLParser(var ASQL : string) : TStatementType;
type TParsePart = (ppStart,ppSelect,ppWhere,ppFrom,ppOrder,ppComment,ppGroup,ppBogus); type TParsePart = (ppStart,ppSelect,ppWhere,ppFrom,ppOrder,ppComment,ppGroup,ppBogus);
@ -1089,8 +1090,8 @@ begin
case ParsePart of case ParsePart of
ppStart : begin ppStart : begin
FCursor.FStatementType := TSQLConnection(Database).StrToStatementType(s); Result := TSQLConnection(Database).StrToStatementType(s);
if FCursor.FStatementType = stSelect then ParsePart := ppSelect if Result = stSelect then ParsePart := ppSelect
else break; else break;
if not FParseSQL then break; if not FParseSQL then break;
PStatementPart := CurrentP; PStatementPart := CurrentP;
@ -1126,7 +1127,7 @@ begin
ParsePart := ppBogus; ParsePart := ppBogus;
StrLength := CurrentP-PStatementPart; StrLength := CurrentP-PStatementPart;
end; end;
if FCursor.FStatementType = stSelect then if Result = stSelect then
begin begin
Setlength(FFromPart,StrLength); Setlength(FFromPart,StrLength);
Move(PStatementPart^,FFromPart[1],(StrLength)); Move(PStatementPart^,FFromPart[1],(StrLength));