Subject | Re: Important RE: [IBO] IBOQuery and Refresh |
---|---|
Author | Helen Borrie |
Post date | 2007-09-20T07:31:48Z |
At 04:59 PM 20/09/2007, Petr Hartman wrote:
Declaration:
function MakeLookupSQL( const SQL: string;
const SQLSelect: string;
const KeyLinks: TIB_StringList;
var LookupSQL: string;
var SelectParamCount: integer;
const OldParamOrder: boolean ): integer;
Implementation:
function MakeLookupSQL( const SQL: string;
const SQLSelect: string;
const KeyLinks: TIB_StringList;
var LookupSQL: string;
var SelectParamCount: integer;
const OldParamOrder: boolean ): integer;
var
ii: integer;
OldWhere: string;
NewWhere: string;
tmpFrom: string;
tmpSelect: string;
tmpPrms: TIB_StringList;
tmpLen: longint;
BegPos,
EndPos,
UnionLevel: integer;
begin
NewWhere := '';
OldWhere := '';
LookupSQL := SQL;
UnionLevel := -1;
GetSQLSelect( SQL, tmpSelect, BegPos, EndPos, UnionLevel );
SetSQLSelect( LookupSQL, SQLSelect, UnionLevel );
SetSQLPlan( LookupSQL, '', UnionLevel );
SetSQLOrder( LookupSQL, '' );
SetSQLForUpdate( LookupSQL, '' );
GetSQLWhere( LookupSQL, OldWhere, BegPos, EndPos, UnionLevel );
for ii := 0 to KeyLinks.Count - 1 do
begin
if ii > 0 then
NewWhere := NewWhere + IBO_AND;
NewWhere := NewWhere + KeyLinks.IndexNames[ii] + '=?';
end;
AddWhereClauseHigh( OldWhere, NewWhere );
SetSQLWhere( LookupSQL, OldWhere, UnionLevel );
GetSQLFrom( LookupSQL, tmpFrom, BegPos, EndPos, UnionLevel );
tmpPrms := TIB_StringList.Create;
try
MakeServerSQL( tmpFrom, tmpPrms, nil, nil, tmpFrom, #0, true, tmpLen,
OldParamOrder );
Result := tmpPrms.Count;
MakeServerSQL( tmpSelect, tmpPrms, nil, nil, tmpSelect, #0, true, tmpLen,
OldParamOrder );
SelectParamCount := tmpPrms.Count;
finally
tmpPrms.Free;
end;
end;
Contact me through list or privately for anything else that comes up missing.
Helen
> > FPrmCnt := MakeLookupSQL( ServerSQL,Here's the revised function (in IB_Parse.pas):
> > KeySQLSelect,
> > KeyLinks,
> > LookupSQL,
> > SPrmCnt,
> > tmpOldParamOrder );
Declaration:
function MakeLookupSQL( const SQL: string;
const SQLSelect: string;
const KeyLinks: TIB_StringList;
var LookupSQL: string;
var SelectParamCount: integer;
const OldParamOrder: boolean ): integer;
Implementation:
function MakeLookupSQL( const SQL: string;
const SQLSelect: string;
const KeyLinks: TIB_StringList;
var LookupSQL: string;
var SelectParamCount: integer;
const OldParamOrder: boolean ): integer;
var
ii: integer;
OldWhere: string;
NewWhere: string;
tmpFrom: string;
tmpSelect: string;
tmpPrms: TIB_StringList;
tmpLen: longint;
BegPos,
EndPos,
UnionLevel: integer;
begin
NewWhere := '';
OldWhere := '';
LookupSQL := SQL;
UnionLevel := -1;
GetSQLSelect( SQL, tmpSelect, BegPos, EndPos, UnionLevel );
SetSQLSelect( LookupSQL, SQLSelect, UnionLevel );
SetSQLPlan( LookupSQL, '', UnionLevel );
SetSQLOrder( LookupSQL, '' );
SetSQLForUpdate( LookupSQL, '' );
GetSQLWhere( LookupSQL, OldWhere, BegPos, EndPos, UnionLevel );
for ii := 0 to KeyLinks.Count - 1 do
begin
if ii > 0 then
NewWhere := NewWhere + IBO_AND;
NewWhere := NewWhere + KeyLinks.IndexNames[ii] + '=?';
end;
AddWhereClauseHigh( OldWhere, NewWhere );
SetSQLWhere( LookupSQL, OldWhere, UnionLevel );
GetSQLFrom( LookupSQL, tmpFrom, BegPos, EndPos, UnionLevel );
tmpPrms := TIB_StringList.Create;
try
MakeServerSQL( tmpFrom, tmpPrms, nil, nil, tmpFrom, #0, true, tmpLen,
OldParamOrder );
Result := tmpPrms.Count;
MakeServerSQL( tmpSelect, tmpPrms, nil, nil, tmpSelect, #0, true, tmpLen,
OldParamOrder );
SelectParamCount := tmpPrms.Count;
finally
tmpPrms.Free;
end;
end;
Contact me through list or privately for anything else that comes up missing.
Helen