Subject SV: [IBO] How-To detach a TIB_Dataset from a TIB Query. Stateless TIB_Dataset.
Author Magnus Karlsson
At 02:10 PM 05-07-02 +0200, Magnus Karlsson wrote:
>Hi,
>
>I wish to extract the retrieved data from a TIB_Query and store it in a
>TIB_Dataset. The problem is that the data vanish from the TIB_Dataset the
>moment I close the TIB_Query?

TIB_Dataset is the base class for several descendants, including
TIB_Query. All of its properties and methods are inherited by TIB_Query. A
TIB_Query is already a TIB_Dataset so the output of the query statement is
already stored in a TIB_Dataset! Please tell us what you are trying to
achieve...

I solved the problem.

_connection = new TIB_Connection(NULL);
_connection->DatabaseName = database;
_connection->Username = username;
_connection->Password = password;

_query = new TIB_Query(NULL);
_query->IB_Connection = _connection;

_query->SQL->Text = sql;
_query->Open();
TIB_Dataset *dataset = new TIB_Dataset(*_query); // copy the content.
cout << endl << _query->Active << endl;
_query->Close();
dataset->First();
while (!dataset->Eof)
{
cout << dataset->FieldByName("STOPCODE")->AsString.c_str() << "\t";
cout << dataset->FieldByName("ACTIVITYCODE")->AsString.c_str() <<
"\t";
cout << dataset->FieldByName("CLOCKSTART")->AsString.c_str() <<
"\t";
cout << dataset->FieldByName("CLOCKEND")->AsString.c_str() << endl;

cout << endl << _query->Active << endl; // check to see that the
connection still is closed.

dataset->Next();
}

Now I can work with the retrieved data, without having a opened connection
to the database. The problem occurred when removing the line
"dataset->First();", then the contents of dataset is empty.

This is what I mean with "stateless". I can work with the dataset, without
knowing the state of its query (opened, closed, etc.), i.e. stateless.

>Other properties I have looked at is
>IBODataset

The IBODataset property does not pertain to TIB_Query. It refers to the
TDataset, when TIB_BDataset (a descendant) is used as a wrapper for the
TDataset-compatible datasets.

>MasterDataset

The MasterDataset property is used internally when the TIB_Query class is
used as the detail set in a master-detail relationship.

>KeyDataset

The KeyDataset property is used internally when the TIB_Query class is used
as the lookup set in a Keysource-Lookup relationship.

Could you please send me some best practise code examples.

>But they are all NULL.

Of course. They are nil because the supporting properties are not used.

>I also tried to use the copy constructor for TIB_Dataset, with input the
>opened TIB_Query, but afterwards I close the TIB_Query and iterating throw
>the newly copy-constructed TIB_Dataset I receive a unknown cannot read
>exception.

Please provide a good description of what you want to do.

>Does anyone know how to accomplish a stateless TIB_Dataset?

How "stateless"? Please describe.
See above.


regards,
Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com


Regards, Magnus Karlsson.


___________________________________________________________________________
IB Objects - direct, complete, custom connectivity to Firebird or InterBase
without the need for BDE, ODBC or any other layer.
___________________________________________________________________________
http://www.ibobjects.com - your IBO community resource for Tech Info papers,
keyword-searchable FAQ, community code contributions and more !

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/