Subject | Questions about IBO (How to... or feature requests?) |
---|---|
Author | IBM T |
Post date | 2001-11-01T09:27:28Z |
Hi,
1. How to close an old GDB and open a new GDB (with the same structure) at
runtime keeping all the datasets open?
(Or, what is wrong with this code? - in IBX worked very well... here it
leaves 'some' closed datasets. All of them are TIBOQuery. One, for example,
is located in a frame embbeded in a secondary form. This helps with
something?)
{------------------------------
This pair Get/SetActiveDataSets is intended to
use only when the dataset list of the database
is the same, since the dataset's name isn't saved
in the snapshot
-------------------------------}
function GetActiveDataSets(aDataBase: TIBODatabase): string;
var
i: integer;
c: char;
begin
with aDataBase do
for i:=0 to DataSetCount-1 do
begin
if DataSets[i].Owner.InheritsFrom(TIBODataSet) then
begin
if TIBODataSet(DataSets[i].Owner).Active then
c:='1'
else
c:='0';
Result:=Result+c;
end;
end;
end;
procedure SetActiveDataSets(aDataBase: TIBODatabase; aSnapshot: string);
var
i: integer;
n: integer;
begin
with aDataBase do
begin
{ if DataSetCount<>Length(aSnapShot) then
Exception.CreateFmt('The snapshot is not inteded for the database
"%s"', [aDataBase.Name]);}
n:=0;
for i:=0 to DataSetCount-1 do
if DataSets[i].Owner.InheritsFrom(TIBODataSet) then
begin
TIBODataSet(DataSets[i].Owner).Active:=aSnapShot[n]='1';
inc(n);
end;
end;
end;
function ChangeDBName(aDataBase: TIBODatabase; aNewName: string): boolean;
var
cDataSets: string;
begin
Result:=False;
with aDataBase do
begin
if (aNewName='') or (aDataBase.DatabaseName=aNewName) then
Exit;
Result:=True;
if Connected then
begin
cDataSets:=GetActiveDataSets(aDatabase);
Connected:=False;
DataBaseName:=aNewName;
Connect;
SetActiveDataSets(aDatabase, cDataSets);
end
else
DatabaseName:=aNewName;
end;
end;
... perhaps a boolean property ActiveOnConnect, which will open the datasets
when they are created or their database switches to Connected:=True will be
a nice thing ...
2. Exists a field property for giving an appropiate name for a field to be
included in an 'OrderBy' clause? IMHO, It must cover all the cases. I found
that the most complete is
with InternalDataSet.FindField(AFieldName) do //is the TIBODataset's
InternalDataSet
if (RelName<>'') and (SQLName<>'') then
Result:=RelName+'.'+SQLName //covers the 'Select t1.Field1 as
"MyFirstField"' and 'Select * from'...
else
Result:=IntToStr(FieldNo); //covers the Select t1.Field1,
(Select t2.Field2 from table2 t2 where t1.k1=t2.k1)...
but this sollution doesn't cover the 'Select t1.Field1, t3.Field1 from
table1 t1, table1 t3 (it returns table1.field1 for both fields...). (btw,
the FullFieldName property throws an AV here...)
Knows someone how to return the table alias of a field ie. to gain the
"t3.field1"?
3. (- For Jason: -) Please, can I use the solution which I proposed for
mixing the TFields with the native IBO, or can you give me another solution,
or should I try to remove all the fields from the app?
HTH
1. How to close an old GDB and open a new GDB (with the same structure) at
runtime keeping all the datasets open?
(Or, what is wrong with this code? - in IBX worked very well... here it
leaves 'some' closed datasets. All of them are TIBOQuery. One, for example,
is located in a frame embbeded in a secondary form. This helps with
something?)
{------------------------------
This pair Get/SetActiveDataSets is intended to
use only when the dataset list of the database
is the same, since the dataset's name isn't saved
in the snapshot
-------------------------------}
function GetActiveDataSets(aDataBase: TIBODatabase): string;
var
i: integer;
c: char;
begin
with aDataBase do
for i:=0 to DataSetCount-1 do
begin
if DataSets[i].Owner.InheritsFrom(TIBODataSet) then
begin
if TIBODataSet(DataSets[i].Owner).Active then
c:='1'
else
c:='0';
Result:=Result+c;
end;
end;
end;
procedure SetActiveDataSets(aDataBase: TIBODatabase; aSnapshot: string);
var
i: integer;
n: integer;
begin
with aDataBase do
begin
{ if DataSetCount<>Length(aSnapShot) then
Exception.CreateFmt('The snapshot is not inteded for the database
"%s"', [aDataBase.Name]);}
n:=0;
for i:=0 to DataSetCount-1 do
if DataSets[i].Owner.InheritsFrom(TIBODataSet) then
begin
TIBODataSet(DataSets[i].Owner).Active:=aSnapShot[n]='1';
inc(n);
end;
end;
end;
function ChangeDBName(aDataBase: TIBODatabase; aNewName: string): boolean;
var
cDataSets: string;
begin
Result:=False;
with aDataBase do
begin
if (aNewName='') or (aDataBase.DatabaseName=aNewName) then
Exit;
Result:=True;
if Connected then
begin
cDataSets:=GetActiveDataSets(aDatabase);
Connected:=False;
DataBaseName:=aNewName;
Connect;
SetActiveDataSets(aDatabase, cDataSets);
end
else
DatabaseName:=aNewName;
end;
end;
... perhaps a boolean property ActiveOnConnect, which will open the datasets
when they are created or their database switches to Connected:=True will be
a nice thing ...
2. Exists a field property for giving an appropiate name for a field to be
included in an 'OrderBy' clause? IMHO, It must cover all the cases. I found
that the most complete is
with InternalDataSet.FindField(AFieldName) do //is the TIBODataset's
InternalDataSet
if (RelName<>'') and (SQLName<>'') then
Result:=RelName+'.'+SQLName //covers the 'Select t1.Field1 as
"MyFirstField"' and 'Select * from'...
else
Result:=IntToStr(FieldNo); //covers the Select t1.Field1,
(Select t2.Field2 from table2 t2 where t1.k1=t2.k1)...
but this sollution doesn't cover the 'Select t1.Field1, t3.Field1 from
table1 t1, table1 t3 (it returns table1.field1 for both fields...). (btw,
the FullFieldName property throws an AV here...)
Knows someone how to return the table alias of a field ie. to gain the
"t3.field1"?
3. (- For Jason: -) Please, can I use the solution which I proposed for
mixing the TFields with the native IBO, or can you give me another solution,
or should I try to remove all the fields from the app?
HTH