Project

General

Profile

Bug #6401

dynamic query can reference any buffer part of the added buffer's dataset

Added by Constantin Asofiei almost 2 years ago. Updated almost 2 years ago.

Status:
Test
Priority:
High
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:

History

#1 Updated by Constantin Asofiei almost 2 years ago

  • Start date deleted (05/24/2022)

Ovidiu, have you seen something like this before?

def var hq as handle.
def temp-table tt1 field f1 as char.
def temp-table tt2 field f1 as char.

def dataset ds1 for tt1, tt2.

create query hq.
hq:set-buffers(buffer tt1:handle).
hq:query-prepare("for each tt1 where tt1.f1 = tt2.f1").

Without the def dataset ds1 for tt1, tt2., the query can't be prepared ('tt2' is not 'seen').

#3 Updated by Constantin Asofiei almost 2 years ago

This patch solves my problem:

### Eclipse Workspace Patch 1.0
#P p2j6129a
Index: src/com/goldencode/p2j/persist/DynamicQueryHelper.java
===================================================================
--- src/com/goldencode/p2j/persist/DynamicQueryHelper.java    (revision 3609)
+++ src/com/goldencode/p2j/persist/DynamicQueryHelper.java    (working copy)
@@ -275,8 +275,18 @@
                                  String qname,
                                  List<Buffer> substBuffers)
    {
-      List<Buffer> allBuffers = new ArrayList<>();
-      buffers.forEach(b -> allBuffers.add(((BufferImpl) b).ref()));
+      Set<Buffer> allBuffersSet = new LinkedHashSet<>();
+      buffers.forEach(b -> 
+      {
+         allBuffersSet.add(((BufferImpl) b).ref());
+         if (b.dataSet()._isValid())
+         {
+            DataSet ds = (DataSet) b.dataSet().getResource();
+            ds.getBuffers().forEach(b2 -> allBuffersSet.add(b2));
+         }
+      });
+      
+      List<Buffer> allBuffers = new ArrayList<>(allBuffersSet);
       if (substBuffers != null && !substBuffers.isEmpty())
       {
          substBuffers.forEach(b -> allBuffers.add(((BufferImpl) b).ref()));

but we need to check if all buffers from the dataset are added indiscriminately (and here I think about cases where an explicit buffer (with the same name?) is added to the list, and a dataset also has it - does this get added from the dataset?).

#4 Updated by Ovidiu Maxiniuc almost 2 years ago

  • Status changed from New to WIP

I am looking at this now and report if your patch is correct.

#5 Updated by Ovidiu Maxiniuc almost 2 years ago

  • Status changed from WIP to Review
  • % Done changed from 0 to 100

Although, at first, I was a bit circumspect about adding all buffers from the dataset, it appears that this is how 4GL does it. More than that, my whole scaffolding for providing the "substitution buffers" is just a particular case of it: in all cases, these "substitution buffers" are just siblings buffers of the same dataset.

I would like to drop that support (substBuffers from QueryWrapper) but this involves a bit of risk I an not taking right now.

Regarding the second part. I tried to construct a procedure with two dynamic datasets using explicit buffers of different tables but caring the same name. My attempts to trick a query to run with wrong buffers failed. I even discovered error 7327, which is very similar to 7328 we have at the moment.

In conclusion, I committed your patch as r13881/6129a.

#6 Updated by Constantin Asofiei almost 2 years ago

  • Status changed from Review to Test

Also available in: Atom PDF