Vitaliy Serdtsev · Jan 24, 2020 go to post

It should be noted that this applies not only to the try/catch block, but also to other blocks, for example:

<FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:2 </FONT><FONT COLOR="#800080">{
  </FONT><FONT COLOR="#0000ff">q </FONT>1 <FONT COLOR="#008000">; runtime error, but the line is highlighted
</FONT><FONT COLOR="#800080">}

</FONT><FONT COLOR="#0000ff">do </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">q </FONT>2 <FONT COLOR="#008000">; compilation error </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">while</FONT><FONT COLOR="#000000">(0)

</FONT><FONT COLOR="#0000ff">while </FONT><FONT COLOR="#000000">0 </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">q </FONT>3 <FONT COLOR="#008000">; compilation error </FONT><FONT COLOR="#800080">}</FONT>

Vitaliy Serdtsev · Jan 23, 2020 go to post
 

And more food for thought:

Class dc.test Abstract ]
{

/// d ##class(dc.test).test()
ClassMethod test(As %Integer 10)
{
  ..Run1(N),..Run2(N),..Run3(N),..Run4(N)
}

ClassMethod Run1(As %Integer)
{
  i=1:1:4 {
    time(i,"start")=$zh
    f j=1:1:{
        i=2 {
          a=20
        ElseIf i=3 {
          a=30
        ElseIf i=1 {
          a=10
        Else {
          a=-4
        }
    }
    time(i,"end")=$zh
  }

  "If i=2: ",?12,time(2,"end")-time(2,"start")," seconds",!,
    "ElseIf i=3: ",?12,time(3,"end")-time(3,"start")," seconds",!,
    "ElseIf i=1: ",?12,time(1,"end")-time(1,"start")," seconds",!,
    "Else: ",?12,time(4,"end")-time(4,"start")," seconds",!!
}

ClassMethod Run2(As %Integer)
{
  i=2,3,1,4 {
    time(i,"start")=$zh

    f j=1:1:a=$case(i,1:10,2:20,3:30,:-4)

    time(i,"end")=$zh
  }

  "i=1: ",time(1,"end")-time(1,"start")," seconds",!,
    "i=2: ",time(2,"end")-time(2,"start")," seconds",!,
    "i=3: ",time(3,"end")-time(3,"start")," seconds",!,
    "i=4: ",time(4,"end")-time(4,"start")," seconds",!!
}

ClassMethod Run3(As %Integer)
{
  i=1,2,3,4 {
    time(i,"start")=$zh

    f j=1:1:a=$case(i,2:20,3:30,1:10,:-4)

    time(i,"end")=$zh
  }

  "i=1: ",time(1,"end")-time(1,"start")," seconds",!,
    "i=2: ",time(2,"end")-time(2,"start")," seconds",!,
    "i=3: ",time(3,"end")-time(3,"start")," seconds",!,
    "i=4: ",time(4,"end")-time(4,"start")," seconds",!!
}

ClassMethod Run4(As %Integer) [ ProcedureBlock = 0 ]
{
  i,time,j,a
  
  i=2,3,1,4 {
    time(i,"start")=$zh

    f j=1:1:d $case(i,1:a1,2:a2,3:a3,:a4)

    time(i,"end")=$zh
  }

  "i=1: ",time(1,"end")-time(1,"start")," seconds",!,
    "i=2: ",time(2,"end")-time(2,"start")," seconds",!,
    "i=3: ",time(3,"end")-time(3,"start")," seconds",!,
    "i=4: ",time(4,"end")-time(4,"start")," seconds",!!
  q
a1 a=10 q
a2 a=20 q
a3 a=30 q
a4 a=-4 q
}

}

USER>##class(dc.test).test(1000000)
If i=2:     .027962 seconds
ElseIf i=3: .043612 seconds
ElseIf i=1: .073138 seconds
Else:       .068023 seconds
 
i=1: .035705 seconds
i=2: .035941 seconds
i=3: .03498 seconds
i=4: .033288 seconds
 
i=1: .078231 seconds
i=2: .052477 seconds
i=3: .066045 seconds
i=4: .07372 seconds
 
i=1: .051371 seconds
i=2: .052017 seconds
i=3: .050972 seconds
i=4: .052397 seconds
 
 
USER>##class(dc.test).test(1e6)
If i=2:     .060933 seconds
ElseIf i=3: .071999 seconds
ElseIf i=1: .094509 seconds
Else:       .096684 seconds
 
i=1: .058554 seconds
i=2: .058182 seconds
i=3: .059299 seconds
i=4: .054863 seconds
 
i=1: .09973 seconds
i=2: .074734 seconds
i=3: .087673 seconds
i=4: .097123 seconds
 
i=1: .082372 seconds
i=2: .084538 seconds
i=3: .081647 seconds
i=4: .079353 seconds
Vitaliy Serdtsev · Jan 23, 2020 go to post

Hi Peter.

Ok.

<FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Time for If (i=2): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(2,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(2,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!,
  </FONT><FONT COLOR="#008000">"Time for ElseIf #1 (i=3): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(3,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(3,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!,
  </FONT><FONT COLOR="#008000">"Time for ElseIf #2 (i=1): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(1,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(1,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!,
  </FONT><FONT COLOR="#008000">"Time for Else (i=4): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(4,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(4,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!!</FONT>

1e6 Time for If (i=2): .030974 seconds Time for ElseIf #1 (i=3): .045126 seconds Time for ElseIf #2 (i=1): .07144 seconds Time for Else (i=4): .087353 seconds

1e9 Time for If (i=2): 28.59286 seconds Time for ElseIf #1 (i=3): 43.044261 seconds Time for ElseIf #2 (i=1): 82.277535 seconds Time for Else (i=4): 69.212718 seconds

Vitaliy Serdtsev · Jan 23, 2020 go to post

I have (2019.1.1CE) this is not confirmed:

<FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:4 </FONT><FONT COLOR="#800080">{
  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">)=</FONT><FONT COLOR="#0000ff">$zh
  f </FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">=1:1:1e6 </FONT><FONT COLOR="#800080">{
      </FONT><FONT COLOR="#0000ff">i </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=2 </FONT><FONT COLOR="#800080">{
        </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=2
      </FONT><FONT COLOR="#800080">} </FONT><FONT COLOR="#0000ff">ElseIf </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=3 </FONT><FONT COLOR="#800080">{
        </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=3
      </FONT><FONT COLOR="#800080">} </FONT><FONT COLOR="#0000ff">ElseIf </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1 </FONT><FONT COLOR="#800080">{
        </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=1
      </FONT><FONT COLOR="#800080">} </FONT><FONT COLOR="#0000ff">Else </FONT><FONT COLOR="#800080">{
        </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=0
      </FONT><FONT COLOR="#800080">}
  }
  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)=</FONT><FONT COLOR="#0000ff">$zh
</FONT><FONT COLOR="#800080">}

</FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Time for If (i=2): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(1,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(1,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!,   </FONT><FONT COLOR="#008000">"Time for ElseIf #1 (i=3): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(2,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(2,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!,   </FONT><FONT COLOR="#008000">"Time for ElseIf #2 (i=1): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(3,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(3,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!,   </FONT><FONT COLOR="#008000">"Time for Else (i=4): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(4,</FONT><FONT COLOR="#008000">"end"</FONT><FONT COLOR="#000000">)-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">(4,</FONT><FONT COLOR="#008000">"start"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">" seconds"</FONT><FONT COLOR="#000000">,!</FONT>

Time for If (i=2): .109283 seconds Time for ElseIf #1 (i=3): .060785 seconds Time for ElseIf #2 (i=1): .08026 seconds Time for Else (i=4): .109974 seconds

Vitaliy Serdtsev · Jan 23, 2020 go to post

Hi Nigel.

I hasten to inform you that new classes have been added to IRIS for writing/reading streams in JSON format: %Stream.DynamicBinary, %Stream.DynamicCharacter.

 
Here is a sample code:
Class dc.test Extends (%RegisteredObject%JSON.Adaptor)
{

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">string </FONT><FONT COLOR="#000080">As %VarString</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">%JSONFIELDNAME </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">"longstring"</FONT><FONT COLOR="#000000">);

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">cs </FONT><FONT COLOR="#000080">As %Stream.TmpCharacter</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">%JSONFIELDNAME </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">"cstream"</FONT><FONT COLOR="#000000">);

</FONT><FONT COLOR="#000080">/// d ##class(dc.test).test() ClassMethod </FONT><FONT COLOR="#000000">test() {   </FONT><FONT COLOR="#0000ff">#define </FONT><FONT COLOR="#000000">fill(%len,%val) </FONT><FONT COLOR="#0000ff">$tr($j(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#0000ff">,%len),</FONT><FONT COLOR="#008000">" "</FONT><FONT COLOR="#0000ff">,%val)

  try</FONT><FONT COLOR="#800080">{          </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()          </FONT><FONT COLOR="#008000">; the maximum string length when exporting to JSON depends on the length of the property name     </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">string</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$$$fill</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$MaxLocalLength</FONT><FONT COLOR="#000000">-(</FONT><FONT COLOR="#0000ff">$l</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"longstring"</FONT><FONT COLOR="#000000">)+5),</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(351))          </FONT><FONT COLOR="#0000ff">$$$ThrowOnError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Write</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$fill</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$MaxLocalLength</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(355))))     </FONT><FONT COLOR="#0000ff">$$$ThrowOnError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Write</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$fill</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$MaxLocalLength</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(354))))

    </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"[Export] len(string): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$l</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">string</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">", len(cs): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Size</FONT><FONT COLOR="#000000">,!!

    </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Stream.FileCharacter</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()     </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Filename</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"VeryBigObject.json"          </FONT><FONT COLOR="#0000ff">$$$ThrowOnError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%JSONExportToStream</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">))     </FONT><FONT COLOR="#0000ff">$$$ThrowOnError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Save</FONT><FONT COLOR="#000000">())          </FONT><FONT COLOR="#008000">;------------------          </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">dobj</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#ff00ff">{}</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%FromJSON</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"1. [Import    %DynamicObject] len(longstring): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$l</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">dobj</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">longstring</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">", len(cstream): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">dobj</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Get</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"cstream"</FONT><FONT COLOR="#000000">,,</FONT><FONT COLOR="#008000">"stream"</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Size</FONT><FONT COLOR="#000000">,!

    </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">obj1</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">%JSONNew</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">dobj</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"2. [Import %RegisteredObject] len(string): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$l</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">obj1</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">string</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">", len(cs): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">obj1</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Size</FONT><FONT COLOR="#000000">,!

    </FONT><FONT COLOR="#008000">/*          The following command will generate an error (tested on IRIS 2019.1.1 CE, Unicode):          ERROR: <MAXSTRING>  zWrite^%Stream.TmpCharacter.1          To avoid errors, you need to fix the code in the GenImportCharacterStream method (see the patch below)          */          </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">obj2</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()     </FONT><FONT COLOR="#0000ff">$$$ThrowOnError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">obj2</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%JSONImport</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">file</FONT><FONT COLOR="#000000">))     </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"3. [Import %RegisteredObject] len(string): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$l</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">obj2</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">string</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">", len(cs): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">obj2</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Size</FONT><FONT COLOR="#000000">,!

  </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">catch</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"ERROR: "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayString</FONT><FONT COLOR="#000000">(),!   </FONT><FONT COLOR="#800080">} </FONT><FONT COLOR="#000000">}

</FONT><FONT COLOR="#000080">/// Get an instance of an JSON enabled class.<br><br> ///  /// You may override this method to do custom processing (such as initializing /// the object instance) before returning an instance of this class. /// However, this method should not be called directly from user code.<br> /// Arguments:<br> ///     dynamicObject is the dynamic object with thee values to be assigned to the new object.<br> ///     containerOref is the containing object instance when called from JSONImport. ClassMethod </FONT><FONT COLOR="#000000">%JSONNew(   </FONT><FONT COLOR="#ff00ff">dynamicObject </FONT><FONT COLOR="#000080">As %DynamicObject</FONT><FONT COLOR="#000000">,   </FONT><FONT COLOR="#ff00ff">containerOref </FONT><FONT COLOR="#000080">As %RegisteredObject </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">""</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">As %RegisteredObject </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">GenerateAfter </FONT><FONT COLOR="#000000">= %JSONGenerate, </FONT><FONT COLOR="#000080">ServerOnly </FONT><FONT COLOR="#000000">= 1 ] {   </FONT><FONT COLOR="#0000ff">#dim </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#0000ff">As </FONT><FONT COLOR="#008080">dc.test</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$s</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$IsObject</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">containerOref</FONT><FONT COLOR="#000000">):</FONT><FONT COLOR="#800000">containerOref</FONT><FONT COLOR="#000000">,1:..</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">())   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">r</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">string</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">dynamicObject</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">longstring   d </FONT><FONT COLOR="#800000">r</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">CopyFrom</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">dynamicObject</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Get</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"cstream"</FONT><FONT COLOR="#000000">,,</FONT><FONT COLOR="#008000">"stream"</FONT><FONT COLOR="#000000">))   </FONT><FONT COLOR="#0000ff">q </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000">}

}</FONT>

Result:
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">dc.test</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">test</FONT><FONT COLOR="#000000">()</FONT>
[Export] len(string): 3641129, len(cs): 7282288
  1. [Import %DynamicObject] len(longstring): 3641129, len(cstream): 7282288

  2. [Import %RegisteredObject] len(string): 3641129, len(cs): 7282288

  3. [Import %RegisteredObject] len(string): 3641129, len(cs): 7282288

Patch for 2019.1.1CE:
Instead of
 <s><FONT COLOR="#0000ff">$$$GENERATE</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">indent</FONT><FONT COLOR="#000000">_</FONT><FONT COLOR="#008000">&quot;&nbsp;&nbsp;Set&nbsp;sc=stream.Write(%JSONObject.&quot;</FONT><FONT COLOR="#000000">_</FONT><FONT COLOR="#0000ff">$$$QN</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$jsonfieldname</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">propertyMap</FONT><FONT COLOR="#000000">))_</FONT><FONT COLOR="#008000">&quot;)&nbsp;If&nbsp;$$$ISERR(sc)&nbsp;Goto&nbsp;%JSONImportExit&quot;</FONT><FONT COLOR="#000000">)</FONT></s>

need

	<b><FONT COLOR="#0000ff">$$$GENERATE</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">indent</FONT><FONT COLOR="#000000">_</FONT><FONT COLOR="#008000">&quot;&nbsp;&nbsp;Set&nbsp;testInvalidField=0,&nbsp;sc=stream.CopyFrom(%JSONObject.%Get(field,,&quot;&quot;stream&quot;&quot;))&nbsp;If&nbsp;$$$ISERR(sc)&nbsp;Goto&nbsp;%JSONImportExit&quot;</FONT><FONT COLOR="#000000">)</FONT></b></pre>

It is possible that in version 2019.4.x has already fixed everything.

Vitaliy Serdtsev · Jan 22, 2020 go to post
Can I safely read any size %GlobalBinaryStream into a %Binary?
No. Any string (%Binary, %String, %VarString, etc.) has size limit of 3,6MB

PS: if it's not a secret, why do you need to read from a stream to a string?

Vitaliy Serdtsev · Jan 22, 2020 go to post

The example below works even in Caché:

<FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%systemInclude </FONT><FONT COLOR="#0000ff">n

try</FONT><FONT COLOR="#800080">{

  </FONT><FONT COLOR="#0000ff">$$$AddAllRoleTemporaryInTry   n $namespace   s $namespace</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"SAMPLES"      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">person</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">Sample.Person</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%OpenId</FONT><FONT COLOR="#000000">(1)      </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%ZEN.Auxiliary.altJSONProvider</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%WriteJSONStreamFromObject</FONT><FONT COLOR="#000000">(.</FONT><FONT COLOR="#800000">stream</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">person</FONT><FONT COLOR="#000000">,,,</FONT><FONT COLOR="#0000ff">$$$YES</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"aeloq"</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"json (string): "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">stream</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Read</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$MaxLocalLength</FONT><FONT COLOR="#000000">),!!      </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%ZEN.Auxiliary.altJSONProvider</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%ConvertJSONToObject</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">stream</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"Sample.Person"</FONT><FONT COLOR="#000000">,.</FONT><FONT COLOR="#800000">obj</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"obj.Home.Street: "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">obj</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Home</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Street </FONT><FONT COLOR="#008000">; or d $system.OBJ.Dump(obj)    </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">catch</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">)</FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Error "</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayString</FONT><FONT COLOR="#000000">(),! </FONT><FONT COLOR="#800080">}</FONT>

Result:

USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^test</FONT> json (string): <FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Pascal,Martin F."</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"SSN"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"502-68-5767"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"DOB"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#000000">43307</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"Home"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Street"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"9347 Franklin Drive"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"City"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Denver"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"State"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"VA"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"Zip"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#000000">66346</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"Office"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Street"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"4897 Main Blvd"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"City"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Miami"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"State"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"MO"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"Zip"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#000000">60084</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"Spouse"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"FavoriteColors"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#ff00ff">[]</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"Age"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"60"</FONT><FONT COLOR="#ff00ff">}</FONT>

obj.Home.Street: 9347 Franklin Drive

Or use %JSON.Adaptor: Exporting and Importing
Vitaliy Serdtsev · Jan 20, 2020 go to post

See also %MATCHES

Example:

<FONT COLOR="#0000ff">select </FONT><FONT COLOR="#000080"> from </FONT><FONT COLOR="#008000">MyTable </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">MyFieldName </FONT><FONT COLOR="#000000">%MATCHES </FONT><FONT COLOR="#008080">'[~|`]*'</FONT>
Vitaliy Serdtsev · Jan 17, 2020 go to post

See answer by @Brendan Bannon about TuneTable.

Documentation:

“Relative cost” is an integer value which is computed from many factors as an abstract number for comparing the efficiency of different execution plans for the same query. This calculation takes into account (among other factors) the complexity of the query, the presence of indices, and the size of the table(s). Relative cost is not useful for comparing two different queries. proof
Vitaliy Serdtsev · Jan 17, 2020 go to post

Could you cite the test code for <FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">select</FONT><FONT COLOR="#000000">^LVBEPVIS</FONT> and run it from a VBScript program from Windows Explorer. Also give your <FONT COLOR="#0000ff">$zv</FONT> (interested primarily in 8-bit or Unicode).

My test for the Caché Unicode:

LVBEPVIS.MAC:
<FONT COLOR="#ff0000">select</FONT><FONT COLOR="#000000">(n)   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">=4   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">(1)=</FONT><FONT COLOR="#008000">"018625110"   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">(2)=</FONT><FONT COLOR="#008000">"01862511"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(9,233,769)   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">(3)=</FONT><FONT COLOR="#008000">"F"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(1)</FONT><FONT COLOR="#008000">"Female"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(1)_</FONT><FONT COLOR="#008000">"Y"   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">(4)=35633   </FONT><FONT COLOR="#0000ff">q </FONT><FONT COLOR="#000000">1</FONT>
test.vbs:
Set AxVisM1 = CreateObject("VISM.VisMCtrl.1") AxVisM1.Server="CN_IPTCP:localhost[1972]:_system:@SYS" AxVisM1.NameSpace="USER" AxVisM1.Execute("s err="""",err=$$select^LVBEPVIS(""018625110"")") WScript.Echo AxVisM1.PLIST
Result:

Vitaliy Serdtsev · Jan 16, 2020 go to post

Example with one file for Windows:

<FONT COLOR="#000080">Class dc.test </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">Abstract </FONT><FONT COLOR="#000000">]
{

</FONT><FONT COLOR="#000080">/// d ##class(dc.test).test() ClassMethod </FONT><FONT COLOR="#000000">test() {   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">ts</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%PosixTime</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">LogicalToUnixTime</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%PosixTime</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">CurrentUTCTimeStamp</FONT><FONT COLOR="#000000">()),     </FONT><FONT COLOR="#800000">oldName</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"C:\Tmp\test"</FONT><FONT COLOR="#000000">,     </FONT><FONT COLOR="#800000">newName</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">oldName</FONT><FONT COLOR="#000000">_</FONT><FONT COLOR="#0000ff">$$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"a%1.txt"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">ts</FONT><FONT COLOR="#000000">)      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Stream.FileBinary</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">LinkToFile</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">oldName</FONT><FONT COLOR="#000000">)      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">gz</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Stream.FileBinaryGzip</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">gz</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Filename</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">newName   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">gz</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">CopyFromAndSave</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">)

  </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%File</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Delete</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">oldName</FONT><FONT COLOR="#000000">) }

}</FONT>

Vitaliy Serdtsev · Jan 16, 2020 go to post

@Julius Kavay got a point.

I will offer two more options:

<FONT COLOR="#000080">Class ABC.Try </FONT><FONT COLOR="#000000">{

</FONT><FONT COLOR="#000080">/// d ##class(ABC.Try).PackageExists() ClassMethod </FONT><FONT COLOR="#000000">PackageExists(</FONT><FONT COLOR="#ff00ff">package </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">"ABC"</FONT><FONT COLOR="#000000">) {   </FONT><FONT COLOR="#008000">; option by Julius Kavay   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">list</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Dictionary.PackageDefinition</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">GetPackageList</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">''</FONT><FONT COLOR="#800000">list</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Find</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$zcvt</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">package</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"U"</FONT><FONT COLOR="#000000">)),!      </FONT><FONT COLOR="#008000">; option 2   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Library.RoutineMgr</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Exists</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$zcvt</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">package</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"U"</FONT><FONT COLOR="#000000">)_</FONT><FONT COLOR="#008000">".PKG"</FONT><FONT COLOR="#000000">),!      </FONT><FONT COLOR="#008000">; option 3   </FONT><FONT COLOR="#0000ff">k </FONT><FONT COLOR="#800000">list   </FONT><FONT COLOR="#0000ff">d $system</FONT><FONT COLOR="#008080">.OBJ</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">GetPackageList</FONT><FONT COLOR="#000000">(.</FONT><FONT COLOR="#800000">list</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">package</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">''</FONT><FONT COLOR="#0000ff">$d</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">list</FONT><FONT COLOR="#000000">),! }

}</FONT>

USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">ABC.Try</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">PackageExists</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"ab"</FONT><FONT COLOR="#000000">)</FONT> 0 0 0

USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">ABC.Try</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">PackageExists</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"abc"</FONT><FONT COLOR="#000000">)</FONT> 1 1 1

UPD: Take another look at the %Dictionary.PackageDefinitionQuery:SubPackage/FlatPackage, %ZEN.Utils:EnumeratePackages

Vitaliy Serdtsev · Jan 14, 2020 go to post

You can solve the issue "head-on", namely, to re-convert character stream using %IO.StringStream:

Class dc.test Abstract ]
{

ClassMethod test()
{
  char="тест",
    bin=$zcvt(char,"O","UTF8")

  "dump char:" zzdump char
  !!,"dump binary:" zzdump bin

  !!,"Char:",?21,$system.Encryption.Base64Encode($system.Encryption.SHAHash(256,char)),!,
     "Binary:",?21,$system.Encryption.Base64Encode($system.Encryption.SHAHash(256,bin)),!!
    
  cs=##class(%Stream.TmpCharacter).%New()
  cs.Write(char)
  
  stream=##class(%IO.StringStream).%New()
  stream.CharEncoding="UTF8" ; here should be the encoding of your CSV file
  stream.CopyFrom(cs; or d stream.CopyFrom(source.Stream)
  stream.CharEncoding="Binary"

  /*

  Attention! The following code is needed to work around an error in method the SHAHashStream,
  since it expects "Rewind() As %Status", but class the %IO.StringStream uses "Rewind(Output pSC As %Status)"

  */
  
  bs=##class(%Stream.TmpBinary).%New()
  bs.CopyFrom(stream)

  "Char (stream):",?21,$system.Encryption.Base64Encode($system.Encryption.SHAHashStream(256,cs)),!,
  "Binary (stream):",?21,$system.Encryption.Base64Encode($system.Encryption.SHAHashStream(256,bs)),!!
}

}
Result:
dump char:

0000: 0442 0435 0441 0442 тест

dump binary: 0000: D1 82 D0 B5 D1 81 D1 82 Ñ.еÑ.Ñ.

Char: 2eEII+27ZRfvbZvK4XNsx7WPDb+82DymPPOAdJ0p1SQ= Binary: 409t7BLE9FmeugePMa6BOUINIbG9LXztfSKwnCB0+0g=

Char (stream): 2eEII+27ZRfvbZvK4XNsx7WPDb+82DymPPOAdJ0p1SQ= Binary (stream): 409t7BLE9FmeugePMa6BOUINIbG9LXztfSKwnCB0+0g=

Vitaliy Serdtsev · Jan 13, 2020 go to post
COS:

  <FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%systemInclude </FONT><FONT COLOR="#ff0000">main</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">=2   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">(1)=</FONT><FONT COLOR="#008000">"line 1"   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">PLIST</FONT><FONT COLOR="#000000">(2)=</FONT><FONT COLOR="#008000">"multiline 1"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$$$NL</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#008000">"multiline 2"   </FONT><FONT COLOR="#0000ff">q </FONT><FONT COLOR="#000000">1</FONT>

DELPHI:

procedure TForm1.Button1Click(Sender: TObject);begin
  VisM.Server:='cn_iptcp:127.0.0.1[1972]:_system:@SYS';
  VisM.NameSpace:='USER';
  VisM.Execute('$$main^dc');
  ListBox.Clear;
  ListBox.Items.Text:=VisM.PLIST;end;
Result:
line 1
multiline 1
multiline 2
Vitaliy Serdtsev · Jan 11, 2020 go to post

Try change TranslateTable:

<FONT COLOR="#000080">Class dc.test </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">Abstract </FONT><FONT COLOR="#000000">]
{

</FONT><FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">runtests() {   </FONT><FONT COLOR="#008000">;d ##class(dc.test).runtests()

  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">data</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"тест"   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"data: "</FONT><FONT COLOR="#000000">,?15,</FONT><FONT COLOR="#800000">data</FONT><FONT COLOR="#000000">,!

  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">cs</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Stream.FileCharacter</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">(),     </FONT><FONT COLOR="#800000">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Filename</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"C:\Temp\test.txt"</FONT><FONT COLOR="#000000">,     </FONT><FONT COLOR="#800000">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">TranslateTable</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"UTF8"   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Write</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">data</FONT><FONT COLOR="#000000">),     </FONT><FONT COLOR="#800000">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Save</FONT><FONT COLOR="#000000">()

  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">bstream</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Stream.FileBinary</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">bstream</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">LinkToFile</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Filename</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Binary:"</FONT><FONT COLOR="#000000">,?15,</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Encryption</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Base64Encode</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Encryption</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">SHAHashStream</FONT><FONT COLOR="#000000">(256,</FONT><FONT COLOR="#800000">bstream</FONT><FONT COLOR="#000000">)),!

  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">cstream</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Stream.FileCharacter</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">cstream</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">LinkToFile</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">cs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Filename</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Char:"</FONT><FONT COLOR="#000000">,?15,</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Encryption</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Base64Encode</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Encryption</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">SHAHashStream</FONT><FONT COLOR="#000000">(256,</FONT><FONT COLOR="#800000">cstream</FONT><FONT COLOR="#000000">)),!!   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">cstream</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">TranslateTable</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"" ;or RAW, SAME   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Char->Binary:"</FONT><FONT COLOR="#000000">,?15,</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Encryption</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Base64Encode</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Encryption</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">SHAHashStream</FONT><FONT COLOR="#000000">(256,</FONT><FONT COLOR="#800000">cstream</FONT><FONT COLOR="#000000">)) }

}</FONT>

USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">dc.test</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">runtests</FONT><FONT COLOR="#000000">()</FONT> data: тест Binary: 409t7BLE9FmeugePMa6BOUINIbG9LXztfSKwnCB0+0g= Char: 2eEII+27ZRfvbZvK4XNsx7WPDb+82DymPPOAdJ0p1SQ=

Char->Binary: 409t7BLE9FmeugePMa6BOUINIbG9LXztfSKwnCB0+0g=

Vitaliy Serdtsev · Nov 6, 2019 go to post

$EXTRACTdoc

Keep in mind that

Characters are counted from 1.
, so instead

<FONT COLOR="#0000ff">$EXTRACT</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">{LabName}</FONT><FONT COLOR="#000000">,0,3)</FONT>

should be

<FONT COLOR="#0000ff">$EXTRACT</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">{LabName}</FONT><FONT COLOR="#000000">,1,3)</FONT>

In this case, it is uncritical, because

If the from value is 0 or a negative number, $EXTRACT returns a null string; however, if from is used with to, a from value of 0 or a negative number is treated as a value of 1.
But in other cases it can lead to the wrong result.
Vitaliy Serdtsev · Nov 4, 2019 go to post
That would work storagetime but not at runtime.
It was just a matter of ease of accessing data using SQL. No more than.

Who knows, maybe the author just decided to use SQL to identify duplicates?

I think runtime hook disallowing duplicate inserts would be better.
I agree. But this is a completely different task and is solved in a different way. Like this:
Property Actor As list Of packet.Actor(POPSPEC ".ActorFilter():10") [ Required ];

<FONT COLOR="#000080">Method </FONT><FONT COLOR="#000000">ActorFilter() </FONT><FONT COLOR="#000080">As %Integer </FONT><FONT COLOR="#000000">{   </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">actorID</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$random</FONT><FONT COLOR="#000000">(10)+1

  </FONT><FONT COLOR="#0000ff">for </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#0000ff">$order</FONT><FONT COLOR="#000000">(i%Actor(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">),-1) </FONT><FONT COLOR="#0000ff">return</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#800000">actorID</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$list</FONT><FONT COLOR="#000000">(i%Actor(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">),1) </FONT><FONT COLOR="#008000">""

  </FONT><FONT COLOR="#0000ff">quit </FONT><FONT COLOR="#800000">actorID </FONT><FONT COLOR="#000000">}</FONT>

The author after all asked about SQL therefore I above and asked to specify that it is necessary actually.

Vitaliy Serdtsev · Nov 4, 2019 go to post

There are a couple of comments:

  1. Instead of
    <FONT COLOR="#000080">Class packet.Actor Extends </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">%Persistent</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">%Populate</FONT><FONT COLOR="#000000">)
    {
      </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">Name </FONT><FONT COLOR="#000080">As %String </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">Required </FONT><FONT COLOR="#000000">];
    

      </FONT><FONT COLOR="#000080">Index </FONT><FONT COLOR="#000000">NameIndex On Name [ </FONT><FONT COLOR="#000080">Unique </FONT><FONT COLOR="#000000">];

      </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">Age </FONT><FONT COLOR="#000080">As %Integer </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">MAXVAL</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">100</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">MINVAL</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">10</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#000080">Required </FONT><FONT COLOR="#000000">];

      </FONT><FONT COLOR="#000080">Index </FONT><FONT COLOR="#000000">AgeIndex On Age [ </FONT><FONT COLOR="#000080">Unique </FONT><FONT COLOR="#000000">];

      </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">Sex </FONT><FONT COLOR="#000080">As %String </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">DISPLAYLIST</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">",Woman,Man"</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#000080">Required </FONT><FONT COLOR="#000000">]; }</FONT>

    better
    Class packet.Actor Extends (%Persistent%Populate)
    {
    
    Index NameIndex On (Name, Age) [ Unique ];
    
    Property Name As %Name Required ];
    
    Property Age As %Integer(MAXVAL 100MINVAL 10) [ Required ];
    
    Property Sex As %String(VALUELIST ",Woman,Man") [ Required ];
    
    }

    Otherwise it will not be possible to insert two or more persons with the same age. Or do you specifically want it?

  2. Property Actor As list of packet.Actor (POPSPEC=".ActorFilter()") [Required];

    This code contradicts the documentation (Specifying the POPSPEC Parameter for List Properties):

    Leave basicspec empty if the property is a list of objects.

    However, in this case, ActorFilter() should return strictly one ID, not a collection.

  3. The data in the Actor property is stored as $lb($lb(ID1),$lb(ID2),..,$lb(IDN)), therefore, to select all records that have ID=6 in this field, you need to perform

    <FONT COLOR="#0000ff">select </FONT><FONT COLOR="#000080">* from </FONT><FONT COLOR="#008000">packet</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Movie </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#808000">$listbuild</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'6'</FONT><FONT COLOR="#000000">) %inlist </FONT><FONT COLOR="#008000">Actor</FONT>

It seems to me that in your case it would be easier to do so:

<FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">Actor </FONT><FONT COLOR="#000080">As list Of packet.Actor</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">STORAGEDEFAULT </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">"array"</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#000080">Required </FONT><FONT COLOR="#000000">];</FONT>

Then the query will be simplified:

<FONT COLOR="#0000ff">select </FONT><FONT COLOR="#000080">* from </FONT><FONT COLOR="#008000">packet</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Movie_Actor </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">Actor</FONT><FONT COLOR="#000000">=6</FONT>

Or even so

<FONT COLOR="#0000ff">select </FONT><FONT COLOR="#000080">* from </FONT><FONT COLOR="#008000">packet</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Movie </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">Movie_Actor</FONT><FONT COLOR="#000000">-></FONT><FONT COLOR="#008000">Actor</FONT><FONT COLOR="#000000">=6</FONT>

Vitaliy Serdtsev · Oct 31, 2019 go to post

Hi, Yana!

Give the class code, the source data and an example of what you want to get in the end.

Vitaliy Serdtsev · Oct 30, 2019 go to post
If we have a lot of votes will consider to add it.
Do we still have to vote for this?

On-my enough one moreover, that moderators (you and Dmitry) and engineers InterSystems (Eduard, Alexander, Anton, Sergey, Anastasia, Timur, etc.) - Russian-speaking.

I have one problem with it - if we introduce Russian Community, will you stop answering questions in English?)
1. I here like writing code more than words. 2. It will depend on who is asking.
Vitaliy Serdtsev · Oct 30, 2019 go to post
  1. Instead of
    Property Product As %String Required ];Property Item As %String CalculatedSqlComputeCode = { {*}=$e({Product},1,5)}, SqlComputed ];

    it is better to use

    Property Product As %String Required ];Property Item As %String(MAXLEN 5) [ RequiredSqlComputeCode = { {*}=$e({Product},1,5)}, SqlComputedSqlComputeOnChange = Product ];
  2. Check on the version 2017.2 can not, but checked on 2018.1
    SELECT * FROM Portal.ProductStats ps left JOIN  Portal.ProductCacheUpdates pcu ON (pcu.Item=ps.ItemWHERE ps.Item=?
    • ExtentSize=1 (Portal.ProductStats) ExtentSize=1000 (Portal.ProductCacheUpdates)

      Relative cost = 1338 ◾Read master map Portal.ProductStats.IDKEY, looping on ID.

      ◾For each row:

      Read index map Portal.ProductCacheUpdates.pcacheUpdsProd, using the given %SQLUPPER(Item), and looping on ID. For each row: Read master map Portal.ProductCacheUpdates.IDKEY, using the given idkey value. Generate a row padded with NULL for table Portal.ProductCacheUpdates if no row qualified. Output the row.

    • ExtentSize=1000 (Portal.ProductStats) ExtentSize=1 (Portal.ProductCacheUpdates)
      Relative cost  = 1219.2
      ◾Read index map Portal.ProductStats.pcacheUpds, using the given %SQLUPPER(Item), and looping on ID.
      

      ◾For each row:

      Read master map Portal.ProductStats.IDKEY, using the given idkey value. Read index map Portal.ProductCacheUpdates.pcacheUpdsProd, using the given %SQLUPPER(Item), and looping on ID. For each row: Read master map Portal.ProductCacheUpdates.IDKEY, using the given idkey value. Generate a row padded with NULL for table Portal.ProductCacheUpdates if no row qualified. Output the row.

      As you can see in both cases the index pcacheUpdsProd is used.

Have you really set up the tables and cleared the cached queries so that the optimizer can start using the new statistics?

Try to do it manually in the terminal:

blablabla><FONT COLOR="#0000ff">d $system</FONT><FONT COLOR="#008080">.SQL</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">TuneSchema</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Portal"</FONT><FONT COLOR="#000000">,1), </FONT><FONT COLOR="#0000ff">$SYSTEM</FONT><FONT COLOR="#008080">.SQL</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Purge</FONT><FONT COLOR="#000000">(), </FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Status</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.OBJ</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">CompilePackage</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Portal"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"cu-d"</FONT><FONT COLOR="#000000">))</FONT>
Vitaliy Serdtsev · Oct 30, 2019 go to post

The documentation describes in detail how and why.

For example, sometimes the optimizer decides not to use the index if a full crawl would be more efficient. It depends on many parameters: ExtentSize, Selectivity, etc.

Give here what Robert asks, and it will be possible to tell more precisely why.

Vitaliy Serdtsev · Oct 30, 2019 go to post

Try this:

<FONT COLOR="#0000ff">update </FONT><FONT COLOR="#008000">RB_ResEffDateSessPayorRestr </FONT><FONT COLOR="#000080">set </FONT><FONT COLOR="#008000">RESTR_DATETo</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#808000">to_date</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#808000">DATEADD</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'year'</FONT><FONT COLOR="#000000">,1,</FONT><FONT COLOR="#008000">RESTR_DATETo</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008080">'YYYY-MM-DD'</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">YEAR</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">RESTR_DATETo</FONT><FONT COLOR="#000000">)=2020</FONT>
Or this:
<FONT COLOR="#0000ff">update </FONT><FONT COLOR="#008000">RB_ResEffDateSessPayorRestr </FONT><FONT COLOR="#000080">set </FONT><FONT COLOR="#008000">RESTR_DATETo</FONT><FONT COLOR="#000000">=%odbcin(</FONT><FONT COLOR="#808000">DATEADD</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'year'</FONT><FONT COLOR="#000000">,1,</FONT><FONT COLOR="#008000">RESTR_DATETo</FONT><FONT COLOR="#000000">)) </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">YEAR</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">RESTR_DATETo</FONT><FONT COLOR="#000000">)=2020</FONT>
Vitaliy Serdtsev · Oct 7, 2019 go to post

<FONT COLOR="#800080">&SQL(</FONT><FONT COLOR="#0000ff">SELECT </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">FROM </FONT><FONT COLOR="#008000">Cinema</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Film </FONT><FONT COLOR="#000080">ORDER BY </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">DESC</FONT><FONT COLOR="#800080">)</FONT>

similar to the query

<FONT COLOR="#800080">&SQL(</FONT><FONT COLOR="#0000ff">SELECT </FONT><FONT COLOR="#000080">TOP ALL </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">FROM </FONT><FONT COLOR="#008000">Cinema</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Film </FONT><FONT COLOR="#000080">ORDER BY </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">DESC</FONT><FONT COLOR="#800080">)</FONT>


Therefore, it is natural that the query plans

<FONT COLOR="#800080">&SQL(</FONT><FONT COLOR="#0000ff">SELECT </FONT><FONT COLOR="#000080">TOP ALL </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">FROM </FONT><FONT COLOR="#008000">Cinema</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Film </FONT><FONT COLOR="#000080">ORDER BY </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">DESC</FONT><FONT COLOR="#800080">)</FONT> and <FONT COLOR="#800080">&SQL(</FONT><FONT COLOR="#0000ff">SELECT </FONT><FONT COLOR="#000080">TOP 1 </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">FROM </FONT><FONT COLOR="#008000">Cinema</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Film </FONT><FONT COLOR="#000080">ORDER BY </FONT><FONT COLOR="#008000">ID </FONT><FONT COLOR="#000080">DESC</FONT><FONT COLOR="#800080">)</FONT>

are so significantly different.

Vitaliy Serdtsev · Sep 23, 2019 go to post
Class dc.test Extends %RegisteredObject
{

ClassMethod Run(
  a,
  b)
{
  w $$$FormatText("a=%1, b=%2",$g(a,"<null>"),$g(b,"<null>")),!
}

ClassMethod Test()
{
  cName="dc.test",
    mName="Run",

    args=2,
    args(1)="2019-01-01",
    args(2)="1,2,3,4"
    
  d $classmethod(cName,mName,args...)
  
  args
  args=1,
    args(1)=77
  d $classmethod(cName,mName,args...)

  args
  args=2,
    args(2)=33
  d $classmethod(cName,mName,args...)

  args
  args=""
  d $classmethod(cName,mName,args...)
}

}

Result:

USER>##class(dc.test).Test()
a=2019-01-01, b=1,2,3,4
a=77, b=<null>
a=<null>, b=33
a=<null>, b=<null>