Dynamic Queries with field lists.

Posted by Admin on 18-Jan-2011 07:13

I haven't used field lists in a while, so this was a bit surprising.

It looks like there is no way to use field lists with dynamic queries. The CREATE QUERY statement or ADD BUFFERS method of the query object handle does not allow to define a field list. When I try to use a field list in the QUERY-PREPARE string, I get an error message telling me that I need to use the fields option with the DEFINE QUERY statement.

But I need to CREATE a query here, rather than to DEFINE it.

Am I right, that there is no way to specify a field list here?

All Replies

Posted by Tim Kuehn on 18-Jan-2011 07:31

Why do you need a field list - you're not running a fat client connection are you?

Posted by Admin on 18-Jan-2011 07:56

Why do you need a field list - you're not running a fat client connection are you?

I'd rather not (and usually don't do). But this customer's end customers tend to use it. The application is still client/server being modernized stepwise to OERA with AppServer - but currently there is only little AppServer code. So I must admit, it's understandable that at many end customer site's there is a tendency to run that on the client.

Posted by Tim Kuehn on 18-Jan-2011 08:12

In this case, all I can think is to have a set of appropriately structured static queries in something persistent, and then use their handles to open and manipulate them as needed.

Posted by Admin on 18-Jan-2011 08:36

In this case, all I can think is to have a set of appropriately structured static queries in something persistent, and then use their handles to open and manipulate them as needed.

Yeah

It's going to get dirty, because we will also need to specify the same field list in the ATTACH-DATA-SOURCE method of a ProDataset buffer. And there seems to be no way to query the fields from above, so we need to keep those lists twice. Bad.

Posted by rbf on 18-Jan-2011 09:22

FWIW, the other option is of course to limit the fields in the temp-table you are sending across.

I am sure you considered this but in some cases it might be an option.

We always use that option, as all our temp-tables are dynamic so we always create only the fields that we actually want to send across.

So who needs fields lists?

Posted by Admin on 18-Jan-2011 09:31

So who needs fields lists?

As written in my original post. The beauty of appserver code is that you CAN run it on the client. When there is not a lot AppSErver code yet, it's difficult to argue that every end customer site uses the AppServer immediately (although you know, I would prefer that). And when the LAN network bandwidth is an issue the field list between the client and the DB server may get very relevant. Although if I'm not completely mistaking, that Oracle data server uses field lists to optimize reads as well.

I fully agree that this is not an issue for code that already runs on the AppServer. But for this customer, it's right now still future, not present.

But when Peter, Tim and Gerd don't know a solution, I guess there is none and I didn't have apples on my eyes when I was reading the docs this morning.

Posted by Tim Kuehn on 18-Jan-2011 09:56

Try PSC Tech Support and see if there's something "not in the docs" you can do.

Posted by guilmori on 18-Jan-2011 12:14

This works for me with 10.1C02

DEF VAR hq AS HANDLE.
CREATE QUERY hq.
hq:SET-BUFFERS(BUFFER customer:handle).

hq:QUERY-PREPARE("for each customer fields(cust-no)").
DEF VAR i as inte.
hq:QUERY-OPEN().
DO WHILE hq:GET-NEXT() i = 1 TO 5:
   MESSAGE BUFFER customer::cust-no
           /* BUFFER customer::name*/ /* -> complain with error 8826 */
      VIEW-AS ALERT-BOX.
END.

Posted by Admin on 18-Jan-2011 12:31

Got (very quick) response from tech support - thank you guys.

Looks like there is a difference between full dynamic queries and static queries that you open dynamically, this works:

CREATE QUERY qh.

qh:SET-BUFFERS(BUFFER customer:HANDLE).

qh:QUERY-PREPARE("FOR EACH customer FIELDS (CustNum Name City ) WHERE custnum

But with a statically defined query it doesn't:

QUERY qryCustomer:QUERY-PREPARE("FOR EACH customer FIELDS (CustNum Name City ) WHERE custnum

Throws an error at me:

FIELDS/EXCEPT belong on DEFINE QUERY, not on OPEN QUERY. (3638)

While I can now workaround that (using the DYNAMIC property of a widget handle for the first time in the real world), this is another useless case of inconsistency in the ABL.

Posted by Admin on 18-Jan-2011 12:31

Exactly. Giving you the answer points, share them in mind with tech support

Posted by Admin on 18-Jan-2011 12:46

Just got another response from tech support, didn't wanna keep that hidden from the forum:

"Hi Mike,
Please keep in mind that you should never use a FIELDS list at all on any QUERY unless you have the following conditions:

1.       You are using a dataserver.

2.       You have especially bad network performance in a particular situation.

3.       You know for a fact that no uses of non- FIELDS fields can come up.

The above recommendations come from the lead 4GL/ABL developer in Progress because the ABL in general assumes all fields in all fetched records are available. This is true throughout the ABL, but the FIELDS list implementation makes an attempt to get some but not all of the implicit fields. There are implicit uses of fields for sorting and joining and triggers and the compiler does not get them all, and they are not seen in the ABL code, so it is always risky to use the FIELDS list .
Best Wishes,"

While I'm aware of all the bad things that can happen :-) it seems that my memory about the data server performance was right.

This thread is closed