Project

General

Profile

can-find.diff

Igor Skornyakov, 02/20/2023 09:47 AM

Download (5.41 KB)

View differences:

rules/annotations/where_clause_prep.rules 2023-02-20 14:37:08 +0000
4 4
** Module   : where_clause_prep.rules
5 5
** Abstract : prepare for where clause conversion 
6 6
**
7
** Copyright (c) 2005-2021, Golden Code Development Corporation.
7
** Copyright (c) 2005-2023, Golden Code Development Corporation.
8 8
**
9 9
** _#_ _I_ __Date__ __JPRM__ __________________________________Description___________________________________
10 10
** 001 GES 20051024   @23118 Prepare for where clause conversion.
......
81 81
** 041 IAS 20210208          Do not convert CONTAINS arguments to upper case at conversion time.
82 82
**     ECF 20210317          Ignore subscript on an extent field lvalue of a CONTAINS operation.
83 83
**     IAS 20211004          Fixed conversion of INDEX and LOOKUP for case-sensitive arguments
84
** 042 IAS 20230220          Fixed nested CAN-FIND conversion
84 85
*/
85 86
-->
86 87

  
......
175 176
   <variable name="litDate"      type="com.goldencode.p2j.util.date" />
176 177
   <variable name="litDatetime"  type="com.goldencode.p2j.util.datetime" />
177 178
   <variable name="litDatetimetz" type="com.goldencode.p2j.util.datetimetz" />
179
   <variable name="canFind"      type="java.util.Set" />
178 180
   
179 181
   <!-- expression libraries -->
180 182
   <include name="common-progress" />
181 183
   
182 184
   <func-library access="private">
183 185
   
186
       <!-- detect whether node is part of a nested CAN-FIND expression -->
187
      <function name="is_nested_can_find">
188
      
189
         <variable name="ref"    type="com.goldencode.ast.Aast" />
190
         <return   name="res"    type="java.lang.Boolean" />
191
         
192
         <expression>
193
            ref = this.getAncestor(-1, prog.record_phrase)
194
         </expression>
195
         <expression>
196
            res = ref != null                         and
197
                  ref.isAnnotation("nested_can_find") and
198
                  #(boolean) ref.getAnnotation("nested_can_find")
199
         </expression>
200
         
201
      </function>
202
 
184 203
      <!-- test if this is the special case where a function gets
185 204
           translated into the id field reference in FQL -->
186 205
      <function name="test_for_id_function">
......
272 291
      <rule>bcCutoff    = create("com.goldencode.p2j.util.date", 12, 31, -1)</rule>
273 292
      <rule>bcDtCutoff  = create("com.goldencode.p2j.util.datetime", 12, 31, -1, 0, 0)</rule>
274 293
      <rule>bcDtzCutoff = create("com.goldencode.p2j.util.datetimetz", 12, 31, -1, 0, 0)</rule>
294
      <rule>canFind = create("java.util.HashSet") </rule>
295
      
275 296
      
276 297
   </init-rules>
277 298
   
......
325 346
            </while>
326 347
            <action>colonRef.putAnnotation("sub_expression", true)</action>
327 348
         </rule>
349

  
350
         <rule>type == prog.table and getNoteBoolean("canfind")
351
            <action>canFind.add(getNoteString("bufname"))</action>
352
         </rule>       
328 353
         
354
         <rule>type == prog.record_phrase and !evalLib("is_nested_can_find")
355
             <action>canFind.clear()</action>
356
         </rule>       
357

  
329 358
         <rule>ignoreId == -1
330 359
         
331 360
            <!-- this node can't be represented in FQL -->
......
413 442
                type == prog.kw_not                                        or
414 443
                validop                                                    or
415 444
                evalLib("literals", type)                                  or
416
                (evalLib("fields") and getNoteBoolean("current_buffer"))   or
445
                (evalLib("fields") and 
446
                    (getNoteBoolean("current_buffer") or getNoteBoolean("canfind"))
447
                )                                                          or
417 448
                evalLib("subscript")                                       or
418 449
                idfunc                                                     or
419 450
                evalLib("is_type_pair", prog.func_poly, prog.kw_if))
420
               
451

  
421 452
               <!-- this is an FQL node (for AND, OR, NOT, and ternary IF this is
422 453
                    provisional only, until children can be checked) -->
423 454
               <action>putNote("hql", true)</action>
......
645 676
                  <!-- remember that this is the root node of a sub-expression
646 677
                       that must be evaluated on the client (and substituted
647 678
                       into the query) -->
679

  
648 680
                  <rule>!evalLib("is_type_pair", prog.func_logical, prog.kw_can_find)
649 681
                     <action>putNote("sub_expression", true)</action>
650 682
                  </rule>
651
                  
652 683
                  <!-- sub-expressions rooted at a field reference to a related buffer in a
653 684
                       multi-table query need to be emitted with a field name -->
654 685
                  <rule>evalLib("fields") and getNoteBoolean("related_buffer")
......
712 743
                     <action>copy.parent.putAnnotation("casesens", true)</action>
713 744
                  </rule>
714 745
               </rule>
715
               
746
        
747
               <action>test=false</action>
748
               <rule>evalLib("fields")
749
                    <action>test = canFind.contains(getNoteString("bufname"))</action>
750
               </rule>
716 751
               <!-- this node can't be represented in FQL -->
717
               <action on="false">putNote("hql", false)</action>
752
               <action on="false">putNote("hql", test)</action>
718 753
               
719 754
            </rule>
720 755
         </rule>