Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Query object from SELECT statement

15 views
Skip to first unread message

andyax

unread,
Jun 20, 2007, 10:23:01 AM6/20/07
to
I’m trying to build a query object from the following select statement:

while select * from field join fields where field.FieldId == fields.FieldsId
&& fields.TemplateTableID == 2{
info(strfmt("%1, %2", fields.TemplateTableID, fields.FieldsId));
}


This works just fine!When I try to get this into an object the query returns
nothing:


query = new Query();
qbds1 = query.addDataSource(tablenum(TecTEField));
qbds1.relations(true);
qbds2 = qbds1.addDataSource(tablenum(TecTEFields));
qbds2.relations(true);

qbds1.addRange(fieldnum(TecTEFields, TemplateTableID)).value("2");

The relations on the database tables seem to be OK? What do I wrong?
Thank you very much in advance, Andy

Marina Chernysheva

unread,
Jun 20, 2007, 10:29:04 AM6/20/07
to
Hi,

You are adding range to the different datasource.
qbds1 - is TecTEField

and your range is for TecTEFields.
You can also see the result query in qbds1.toString().

Regards, Marina

andyax

unread,
Jun 20, 2007, 10:51:00 AM6/20/07
to
Thank you Marina,

but even when I don't define a range the query returns nothing! I'm using
temporary tables. Could it be that these are causing problems?

Regards, Andy

andyax

unread,
Jun 20, 2007, 11:10:03 AM6/20/07
to
It seems like this is a problem with the temporary tables. How can I use a
query in temporary tables?

Tank you, Andy

Marina Chernysheva

unread,
Jun 20, 2007, 11:28:02 AM6/20/07
to
Yes!

When you specify something by tablenum in query it goes to db and looks for
data for it. Temporary tables are not stored in database.

You can still use them as the datasource:
After you have completed query, construct queryRun object and make the
following : queryRun.setRecord(youTmpTableRecord);
When obtaining data from query use method data on the variable you want the
data to be placed in.

P.S. When naming temporary tables it is best practice to use tmp prefix.

Best regards, Marina

andyax

unread,
Jun 20, 2007, 11:47:01 AM6/20/07
to
Thank you Marina!

But I want to show the results on a form grid via

TecTEField_ds.query(query);
TecTEField_ds.executeQuery();

or better (thanx for your best practice advice)... :-)
tmpTEField_ds.query(query);
tmpTEField_ds.executeQuery();

so the QueryRun doesn't realy work in this case.

Marina Chernysheva

unread,
Jun 20, 2007, 12:06:00 PM6/20/07
to
Dear Andy,

First, please refer to this link -
http://patrickchuaax.spaces.live.com/Blog/cns!4D841FDCFEC868AA!119.entry
There's a part for temporary tables and forms.

If you want to replace table contents with yours you just make
tmpTEField.setTmpData(yourNewDataset);
tmpTEField_ds.executeQuery();

Then, if you have want to replace query from the form with your custom
query, do like this:


query = new Query();
qbds1 = query.addDataSource(tablenum(tmpTableId));
qbds1.addRange(fieldnum(tmpTableId, someField)).value(queryValue(777));

tmpTableId.setTmpData (yourNewDataSet); //tmpTableId is a cursor of your
table on the form
tmpTableId_ds.queryRun().query(query);
tmpTableId_ds.research();

It is important to call research here, because research has a flag of saving
the query. if you call executeQuery, previous query will be rebuilt.

Regards, Marina

andyax

unread,
Jun 21, 2007, 5:39:01 AM6/21/07
to
It seems like AX doesn't take the correct instance of the temp table an takes
an empty one!

ACO

unread,
Jun 21, 2007, 7:26:00 AM6/21/07
to
Andy:

The thing to remember about temporary tables is that the life span of the
data is the life span of the object that filled the temporary table. Two
distinct instances would not have access to the same data (unlike true
tables).

I have typically used a Class to create the table data with the Class
instantiated from the Form. A call to one of the Class's methods would return
a temporary table object that would be used as the data source for the grid.
Since the data belongs to the Class, and the life span of the Class determins
the life span of the data, the Class object being called would reside in the
classDeclaration of the Form allowing it to exist through the duration of the
Form's life.

Does that help explain the scenario or did I simply manage to muddy the
waters?

Marina Chernysheva

unread,
Jun 21, 2007, 7:46:02 AM6/21/07
to
Andy, I think you should paste code here, so we would know the problem. )

firdousali

unread,
Dec 23, 2009, 1:07:47 PM12/23/09
to
Hi i want to build a query object like
"select nofetch formletterParmTable
where formletterParmTable.ParmId == parmId;"


any alternative of nofetch while building query? any help would be highly appreciated

MarinaChernyshev wrote:

RE: Query object from SELECT statement
20-Jun-07

Dear Andy,

First, please refer to this link -
http://patrickchuaax.spaces.live.com/Blog/cns!4D841FDCFEC868AA!119.entry
There's a part for temporary tables and forms.

If you want to replace table contents with yours you just make
tmpTEField.setTmpData(yourNewDataset);
tmpTEField_ds.executeQuery();

Then, if you have want to replace query from the form with your custom
query, do like this:


query = new Query();
qbds1 = query.addDataSource(tablenum(tmpTableId));
qbds1.addRange(fieldnum(tmpTableId, someField)).value(queryValue(777));

tmpTableId.setTmpData (yourNewDataSet); //tmpTableId is a cursor of your
table on the form
tmpTableId_ds.queryRun().query(query);
tmpTableId_ds.research();

It is important to call research here, because research has a flag of saving
the query. if you call executeQuery, previous query will be rebuilt.

Regards, Marina

"andyax" wrote:

Previous Posts In This Thread:

On Wednesday, June 20, 2007 10:23 AM
andya wrote:

Query object from SELECT statement
I???m trying to build a query object from the following select statement:

while select * from field join fields where field.FieldId == fields.FieldsId
&& fields.TemplateTableID == 2{
info(strfmt("%1, %2", fields.TemplateTableID, fields.FieldsId));
}


This works just fine!When I try to get this into an object the query returns
nothing:


query = new Query();


qbds1 = query.addDataSource(tablenum(TecTEField));
qbds1.relations(true);
qbds2 = qbds1.addDataSource(tablenum(TecTEFields));
qbds2.relations(true);

qbds1.addRange(fieldnum(TecTEFields, TemplateTableID)).value("2");

The relations on the database tables seem to be OK? What do I wrong?
Thank you very much in advance, Andy

On Wednesday, June 20, 2007 10:29 AM
MarinaChernyshev wrote:

Hi,You are adding range to the different datasource.
Hi,

You are adding range to the different datasource.
qbds1 - is TecTEField

and your range is for TecTEFields.
You can also see the result query in qbds1.toString().

Regards, Marina

"andyax" wrote:

On Wednesday, June 20, 2007 10:51 AM
andya wrote:

Thank you Marina,but even when I don't define a range the query returns
Thank you Marina,

but even when I don't define a range the query returns nothing! I'm using
temporary tables. Could it be that these are causing problems?

Regards, Andy

"Marina Chernysheva" wrote:

On Wednesday, June 20, 2007 11:10 AM
andya wrote:

It seems like this is a problem with the temporary tables.
It seems like this is a problem with the temporary tables. How can I use a
query in temporary tables?

Tank you, Andy

"andyax" wrote:

On Wednesday, June 20, 2007 11:28 AM
MarinaChernyshev wrote:

Yes!
Yes!

When you specify something by tablenum in query it goes to db and looks for
data for it. Temporary tables are not stored in database.

You can still use them as the datasource:
After you have completed query, construct queryRun object and make the
following : queryRun.setRecord(youTmpTableRecord);
When obtaining data from query use method data on the variable you want the
data to be placed in.

P.S. When naming temporary tables it is best practice to use tmp prefix.

Best regards, Marina

"andyax" wrote:

On Wednesday, June 20, 2007 11:47 AM
andya wrote:

Thank you Marina!
Thank you Marina!

But I want to show the results on a form grid via

TecTEField_ds.query(query);
TecTEField_ds.executeQuery();

or better (thanx for your best practice advice)... :-)
tmpTEField_ds.query(query);
tmpTEField_ds.executeQuery();

so the QueryRun doesn't realy work in this case.

Regards, Andy

"Marina Chernysheva" wrote:

On Wednesday, June 20, 2007 12:06 PM
MarinaChernyshev wrote:

RE: Query object from SELECT statement
Dear Andy,

First, please refer to this link -
http://patrickchuaax.spaces.live.com/Blog/cns!4D841FDCFEC868AA!119.entry
There's a part for temporary tables and forms.

If you want to replace table contents with yours you just make
tmpTEField.setTmpData(yourNewDataset);
tmpTEField_ds.executeQuery();

Then, if you have want to replace query from the form with your custom
query, do like this:


query = new Query();
qbds1 = query.addDataSource(tablenum(tmpTableId));
qbds1.addRange(fieldnum(tmpTableId, someField)).value(queryValue(777));

tmpTableId.setTmpData (yourNewDataSet); //tmpTableId is a cursor of your
table on the form
tmpTableId_ds.queryRun().query(query);
tmpTableId_ds.research();

It is important to call research here, because research has a flag of saving
the query. if you call executeQuery, previous query will be rebuilt.

Regards, Marina

"andyax" wrote:

On Thursday, June 21, 2007 5:39 AM
andya wrote:

It seems like AX doesn't take the correct instance of the temp table an takes

It seems like AX does not take the correct instance of the temp table an takes
an empty one!

"Marina Chernysheva" wrote:

On Thursday, June 21, 2007 7:26 AM
AC wrote:

RE: Query object from SELECT statement
Andy:

The thing to remember about temporary tables is that the life span of the
data is the life span of the object that filled the temporary table. Two
distinct instances would not have access to the same data (unlike true
tables).

I have typically used a Class to create the table data with the Class
instantiated from the Form. A call to one of the Class's methods would return
a temporary table object that would be used as the data source for the grid.
Since the data belongs to the Class, and the life span of the Class determins
the life span of the data, the Class object being called would reside in the
classDeclaration of the Form allowing it to exist through the duration of the
Form's life.

Does that help explain the scenario or did I simply manage to muddy the
waters?

"andyax" wrote:

On Thursday, June 21, 2007 7:46 AM
MarinaChernyshev wrote:

Andy, I think you should paste code here, so we would know the problem. )
Andy, I think you should paste code here, so we would know the problem. )


Submitted via EggHeadCafe - Software Developer Portal of Choice
Javascript OK/Cancel Message Box Example
http://www.eggheadcafe.com/tutorials/aspnet/845898fd-9b2f-4568-8c25-6df4b8de84c0/javascript-okcancel-mess.aspx

0 new messages