Vitaliy Serdtsev · Mar 6, 2019 go to post

And if so?

<FONT COLOR="#0000ff">CREATE </FONT><FONT COLOR="#000080">TABLE </FONT><FONT COLOR="#008000">test </FONT><FONT COLOR="#000000">(
  </FONT><FONT COLOR="#008000">identifier   </FONT><FONT COLOR="#000080">VARCHAR</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">200</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">NOT NULL</FONT><FONT COLOR="#000000">,
  </FONT><FONT COLOR="#008000">value        </FONT><FONT COLOR="#000080">INTEGER COMPUTEONCHANGE</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"%%UPDATE"</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">COMPUTECODE </FONT><FONT COLOR="#000000">{</FONT><FONT COLOR="#800080">&sql(</FONT><FONT COLOR="#0000ff">select </FONT><FONT COLOR="#808000">max</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">value</FONT><FONT COLOR="#000000">)+1 </FONT><FONT COLOR="#000080">into </FONT><FONT COLOR="#800000">:{*} </FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">test </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">identifier</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">:{identifier}</FONT><FONT COLOR="#800080">)</FONT><FONT COLOR="#000000">},
  </FONT><FONT COLOR="#000080">PRIMARY KEY </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">identifier</FONT><FONT COLOR="#000000">)
)</FONT>
Vitaliy Serdtsev · Feb 28, 2019 go to post

SQL Projection of Object-Valued Properties

<FONT COLOR="#0000ff">INSERT </FONT><FONT COLOR="#000080">INTO </FONT><FONT COLOR="#008000">Package_Tables</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Person_Address
    </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">Person</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#008000">element_key</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#008000">Address_AddressType</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#008000">Address_StreetAddress</FONT><FONT COLOR="#000000">)
    </FONT><FONT COLOR="#000080">VALUES
    </FONT><FONT COLOR="#000000">(1,2,1,</FONT><FONT COLOR="#008080">'72 Fake Street'</FONT><FONT COLOR="#000000">)</FONT>
Vitaliy Serdtsev · Feb 28, 2019 go to post

Working example:

<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).Test1() ClassMethod </FONT><FONT COLOR="#000000">Test1() [ </FONT><FONT COLOR="#000080">ProcedureBlock </FONT><FONT COLOR="#000000">= 0 ] {   </FONT><FONT COLOR="#0000ff">new </FONT><FONT COLOR="#800000">active</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">reactive</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">info</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">i      </FONT><FONT COLOR="#0000ff">kill </FONT><FONT COLOR="#800000">info

  </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">active </FONT><FONT COLOR="#000000">= 1   </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">reactive </FONT><FONT COLOR="#000000">= 2

  </FONT><FONT COLOR="#0000ff">for </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"active"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"reactive" </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">info</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">)= @</FONT><FONT COLOR="#800000">i   </FONT><FONT COLOR="#800080">}

  </FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#800000">info </FONT><FONT COLOR="#000000">}

</FONT><FONT COLOR="#000080">/// d ##class(dc.test).Test2() ClassMethod </FONT><FONT COLOR="#000000">Test2() [ </FONT><FONT COLOR="#000080">PublicList </FONT><FONT COLOR="#000000">= (active, reactive) ] {   </FONT><FONT COLOR="#0000ff">new </FONT><FONT COLOR="#800000">active</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">reactive   </FONT><FONT COLOR="#0000ff">kill </FONT><FONT COLOR="#800000">info

  </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">active </FONT><FONT COLOR="#000000">= 1   </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">reactive </FONT><FONT COLOR="#000000">= 2

  </FONT><FONT COLOR="#0000ff">for </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"active"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"reactive" </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">info</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">)= @</FONT><FONT COLOR="#800000">i   </FONT><FONT COLOR="#800080">}

  </FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#800000">info </FONT><FONT COLOR="#000000">}

}</FONT>

Vitaliy Serdtsev · Feb 22, 2019 go to post

What will the following code output?

<FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">resptext</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"{""access_token"":""4SDFDSFDSF-aSDASDASD"",""expires_in"":""3300"",""refresh_token"":"""",""scope"":""sms_send"",""token_type"":""Bearer""}"

</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">sc </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%ZEN.Auxiliary.jsonProvider</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%ParseJSON</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">resptext</FONT><FONT COLOR="#000000">,,.</FONT><FONT COLOR="#800000">pObject</FONT><FONT COLOR="#000000">,1) </FONT><FONT COLOR="#0000ff">i $$$ISOK</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">sc</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">pObject</FONT><FONT COLOR="#000000">,!!,     </FONT><FONT COLOR="#800000">pObject</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">"access_token"</FONT><FONT COLOR="#000000">,!,     </FONT><FONT COLOR="#800000">pObject</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">"expires_in"</FONT><FONT COLOR="#000000">,!   </FONT><FONT COLOR="#0000ff">k </FONT><FONT COLOR="#800000">arr </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"" </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">pObject</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%CopyToArray</FONT><FONT COLOR="#000000">(.</FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#800000">arr </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">else</FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">d $system</FONT><FONT COLOR="#008080">.OBJ</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">sc</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">}</FONT>

My result (2018.1):
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^test</FONT>
1@%ZEN.proxyObject

4SDFDSFDSF-aSDASDASD 3300 arr("access_token")="4SDFDSFDSF-aSDASDASD" arr("expires_in")=3300 arr("refresh_token")="" arr("scope")="sms_send" arr("token_type")="Bearer"

Vitaliy Serdtsev · Feb 22, 2019 go to post

What will the following code output?

USER><FONT COLOR="#0000ff">k </FONT><FONT COLOR="#800000">arr </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">pObject</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%CopyToArray</FONT><FONT COLOR="#000000">(.</FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#800000">arr</FONT>

PS: "in" ≠ "expires_in"

Vitaliy Serdtsev · Feb 18, 2019 go to post

Hi Adrian.

Made a small example:

<FONT COLOR="#0000ff">#dim </FONT><FONT COLOR="#800000">rs </FONT><FONT COLOR="#0000ff">As </FONT><FONT COLOR="#008080">%ResultSet
   
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">pid</FONT><FONT COLOR="#000000">=4652
   
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%ResultSet</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"%SYS.ProcessQuery:VariableByPid"</FONT><FONT COLOR="#000000">)
   
</FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">filter</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"a*" </FONT><FONT COLOR="#800080">{
 </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">!,</FONT><FONT COLOR="#008000">"Filter = "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$quote</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">filter</FONT><FONT COLOR="#000000">),!
 </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Execute</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pid</FONT><FONT COLOR="#000000">,,,,</FONT><FONT COLOR="#800000">filter</FONT><FONT COLOR="#000000">)
 </FONT><FONT COLOR="#0000ff">while </FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Next</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#800080">{
   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Name = "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Get</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#008000">", Value = "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Get</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Value"</FONT><FONT COLOR="#000000">),!
 </FONT><FONT COLOR="#800080">}
}</FONT>
Result:
USER:4652><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"11"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"22"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">a1</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"33" </FONT><FONT COLOR="#0000ff">w $job</FONT>
4652

USER:1392><FONT COLOR="#0000ff">w $job</FONT><FONT COLOR="#000000">,! </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^dc</FONT> 1392

Filter = "" Name = a, Value = 11 Name = a1, Value = 33 Name = b, Value = 22

Filter = "a*" Name = a, Value = 11 Name = a1, Value = 33

Vitaliy Serdtsev · Feb 16, 2019 go to post

The presence of a potential opportunity to read the documentation via "Class Reference". For macros from *.inc this is not possible.

Vitaliy Serdtsev · Feb 14, 2019 go to post

Still another option:

<FONT COLOR="#000080">Class dc.test Extends %Persistent
</FONT><FONT COLOR="#000000">{

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">JSONData </FONT><FONT COLOR="#000080">As list Of %String </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">SqlListType </FONT><FONT COLOR="#000000">= SUBNODE ];

</FONT><FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">Test() {   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">%KillExtent</FONT><FONT COLOR="#000000">()      </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">l</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"apple"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"pear"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"plum"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Kyle"</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%ToJSON</FONT><FONT COLOR="#000000">(),</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Evgeny"</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%ToJSON</FONT><FONT COLOR="#000000">()) </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()     </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">JSONData</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">InsertList</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">l</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Save</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#800080">}

  </FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#000000">@</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Dictionary</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">comMemberKeyGet</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$this</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$cCLASSstorage</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$nameDefaultStorageNameGet</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$cSDEFdatalocation</FONT><FONT COLOR="#000000">)      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%SQL.Statement</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%ExecDirect</FONT><FONT COLOR="#000000">(,</FONT><FONT COLOR="#008000">"select distinct json_arrayagg(JSONData %foreach(test)) from dc.test_JSONData"</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">while </FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Next</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">jsonStr</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%GetData</FONT><FONT COLOR="#000000">(1),       </FONT><FONT COLOR="#800000">json</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">jsonStr</FONT><FONT COLOR="#000000">)

    </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">!,</FONT><FONT COLOR="#800000">jsonStr</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">", %Size()="</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">json</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Size</FONT><FONT COLOR="#000000">(),!   </FONT><FONT COLOR="#800080">} </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>
<FONT COLOR="#000000">^dc.testD=2
</FONT><FONT COLOR="#000000">^dc.testD(1)=</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">)=3
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,1)=</FONT><FONT COLOR="#008000">"apple"
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,2)=</FONT><FONT COLOR="#008000">"pear"
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,3)=</FONT><FONT COLOR="#008000">"plum"
</FONT><FONT COLOR="#000000">^dc.testD(2)=</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#000000">^dc.testD(2,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">)=2
</FONT><FONT COLOR="#000000">^dc.testD(2,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,1)=</FONT><FONT COLOR="#008000">"{""Name"":""Kyle""}"
</FONT><FONT COLOR="#000000">^dc.testD(2,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,2)=</FONT><FONT COLOR="#008000">"{""Name"":""Evgeny""}"</FONT>

<FONT COLOR="#ff00ff">[</FONT><FONT COLOR="#008000">"apple"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"pear"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"plum"</FONT><FONT COLOR="#ff00ff">]</FONT>, %Size()=3

<FONT COLOR="#ff00ff">[{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Kyle"</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Evgeny"</FONT><FONT COLOR="#ff00ff">}]</FONT>, %Size()=2

Doc:
Vitaliy Serdtsev · Jan 16, 2019 go to post
if I call giveMeAFalseMe from Cache when it's returning "true" or "false", Cache will translate "true" into a truthy %Boolean return value, right?

No, it does zenBool, which is on the client side.

The important thing is that #server()# always returns a string, for example:

<script language="cache" method="giveMeAFalse" arguments="" procedureblock='1' returntype="%Integer">return 4</script>var bool #server(..giveMeAFalse())#;
console.log("bool = " bool);
console.log("typeof bool = "typeof bool);

Result:
bool = 4
typeof bool =  string
PS: you can further explore the sources of the #server()# -> cspHttpServerMethod() -> cspProcessResponse(), which are in the file cspxmlhttp.js.
Vitaliy Serdtsev · Jan 15, 2019 go to post

See zenConvertType() [///Converts a typed value returned from the server to an appropriate JS type] from zenutils.js.

Try this:

<script src="zenutils.js"></script>

<script language="javascript">
function isItActuallyFalse() {

var bool zenConvertType('BOOLEAN',#server(..giveMeAFalse())#);

...
}

</script>

<script language="cache" method="giveMeAFalse" arguments="" returntype="%Boolean" procedureblock='1'>return $$$NO</script>
or
var bool zenBool(#server(..giveMeAFalse())#);

... <<FONT COLOR="#ff0000">script </FONT><FONT COLOR="#000080">language</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"cache" </FONT><FONT COLOR="#000080">method</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"giveMeAFalse" </FONT><FONT COLOR="#000080">arguments</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"" </FONT><FONT COLOR="#000080">returntype</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"%Boolean" </FONT><FONT COLOR="#000080">procedureblock</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">'1'</FONT><FONT COLOR="#000000">></FONT><FONT COLOR="#0000ff">return </FONT><FONT COLOR="#008000">"false"</FONT><FONT COLOR="#000000"></</FONT><FONT COLOR="#ff0000">script</FONT><FONT COLOR="#000000">></FONT>

Vitaliy Serdtsev · Dec 31, 2018 go to post
tags=$lb("a","b","c"),
  str="c,a1,d,b,f"
   
l=$lfs(str),ptr=0
while $listnext(tags,ptr,tag{
  w:$lf(l,tagtag,!
}
Result

b c

Vitaliy Serdtsev · Nov 2, 2018 go to post

No. If you beware to use %occLibrary, you may look into side %Regex.Matcher

Here is another documented solution:

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

    </FONT><FONT COLOR="#0000ff">#define </FONT><FONT COLOR="#000000">TAB </FONT><FONT COLOR="#0000ff">$c(9)          s </FONT><FONT COLOR="#800000">csv</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"""ABC,"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(10)</FONT><FONT COLOR="#008000">" Company,"",""123 Main St, Ste 102"",""Anytown, DC"",10001,234-567-8901,""Anytown"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$$$TAB</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#008000">"DC"""

    </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%DeepSee.TermList</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%ParseCSVRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">csv</FONT><FONT COLOR="#000000">,.</FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">)

    </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">csv</FONT><FONT COLOR="#000000">,!!,</FONT><FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">WriteCSVRecord</FONT><FONT COLOR="#000000">(.</FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$TAB</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="#ff0000">WriteCSVRecord</FONT><FONT COLOR="#000000">(&pRecord, pDelim=</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">, pEncode=</FONT><FONT COLOR="#0000ff">$$$YES</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#008000">// made on the basis of the method %WriteCSVRecord   </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">""   </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">k </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$O</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">))   </FONT><FONT COLOR="#0000ff">While </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">'=</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">tValue </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$G</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">))     </FONT><FONT COLOR="#0000ff">Set</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#0000ff">$G</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pEncode</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800000">tValue </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$ZCVT</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"O"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"UTF8"</FONT><FONT COLOR="#000000">) 

    </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000"> </FONT><FONT COLOR="#0000ff">$S</FONT><FONT COLOR="#000000">((</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#008000">""""</FONT><FONT COLOR="#000000">)||(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">)||(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#800000">pDelim</FONT><FONT COLOR="#000000">):</FONT><FONT COLOR="#0000ff">$$$quote</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">),1:</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">k </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$O</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">))     </FONT><FONT COLOR="#0000ff">Set</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">'=</FONT><FONT COLOR="#008000">"" </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000"> </FONT><FONT COLOR="#800000">pDelim   </FONT><FONT COLOR="#800080">}   </FONT><FONT COLOR="#0000ff">Quit </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#800080">}</FONT>

Result:
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^dc</FONT>
"ABC,
Company,","123 Main St, Ste 102","Anytown, DC",10001,234-567-8901,"Anytown        DC"

"ABC, Company," "123 Main St, Ste 102" "Anytown, DC" 10001 234-567-8901 "Anytown DC"

Vitaliy Serdtsev · Nov 1, 2018 go to post
#include %systemInclude

    csv="ABC Company,""123 Main St, Ste 102"",""Anytown, DC"",10001,234-567-8901"
    list=$$CSVtoList^%occLibrary(csv)

    i=1:1:$ll(lists:$li(list,i)["," $li(list,i)=$$$quote($li(list,i))
        
    csv,!,$lts(list,$c(9))
Result:
USER>^test

ABC Company,"123 Main St, Ste 102","Anytown, DC",10001,234-567-8901 ABC Company "123 Main St, Ste 102" "Anytown, DC" 10001 234-567-8901

Vitaliy Serdtsev · Nov 1, 2018 go to post

Maybe the name of the topic to specify a CSV-string instead of string ?

After clarification, the question became more clear.

Vitaliy Serdtsev · Nov 1, 2018 go to post

<FONT COLOR="#0000ff">$tr</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">str</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(9))</FONT> or <FONT COLOR="#0000ff">$replace</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">str</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(9))</FONT>

Vitaliy Serdtsev · Nov 1, 2018 go to post

I was looking at the generated INT code for <FONT COLOR="#800080">&sql(</FONT><FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'1'</FONT><FONT COLOR="#000000">,4,</FONT><FONT COLOR="#008080">'0'</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#008000">n</FONT><FONT COLOR="#800080">)</FONT>

Unfortunately, for COS at the moment I have not found an analogue LPADSQL. Can you offer a documented LPADCOS ?

Vitaliy Serdtsev · Oct 30, 2018 go to post

Once upon a time promised to make Server-Side JavaScript alongside with Caché ObjectScript and Caché Basic:

I found a JS Runtime Shell that uses Node.JS & esprima:

SAMPLES><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%CPT.JS.Runtime.Shell</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Run</FONT><FONT COLOR="#000000">()</FONT>

JRS> ?

.L CLASS - load javascript methods from CLASS into JS global namespace .LV var,.. - load the given COS public vars into JS global namespace

.S FUNC - list the source of the method which implements function FUNC - FUNC must be in the global namespace - the whole implementing method is shown, even for an inner function - this will also work for non-javascript methods .M - list MAC code from latest compilation .I - list INT code from latest compilation .T - show latest tree

.G - list global symbols

.N CODE - execute JS on node.js .N - execute the last-entered line of JS on node.js

.CONFIG ... - passed to %CPT.CalloutShell 'CONFIG' command

.SET ... - passed to %CPT.CalloutShell 'SET' command .CLEAR ... - passed to %CPT.CalloutShell 'CLEAR' command .SHOW ... - passed to %CPT.CalloutShell 'SHOW' command

!COS - execute a line of COS

Anything else is interpreted as JS. :-

  • if preceded by "=" it must be a single function definition
  • otherwise it can be either a single expression or a sequence of statements separated by ";"s

Either way it will be compiled into a function body and :-

  • if preceded by "==" it is stored as a JS global with the new function's name
  • otherwise it will just be executed

\n can be used to represent a newline.

You can also take input from a file :- <FILE - read JS from FILE and compile+execute it <=FILE - read JS from FILE and compile+store it

The result of the execution is shown and also stored in global variable '_'.

For a global variable, set it without using 'var' (this will be fixed)

JRS> .N <FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">obj </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">{ name: </FONT><FONT COLOR="#800000">"John"</FONT><FONT COLOR="#000000">, age: </FONT><FONT COLOR="#000080">30</FONT><FONT COLOR="#000000">, city: </FONT><FONT COLOR="#800000">"New York" </FONT><FONT COLOR="#000000">}; JSON.stringify(obj);</FONT> {result: "{""name"":""John"",""age"":30,""city"":""New York""}"}

JRS> .N Math.random() {result: .5670654247514904}

JRS> .N <FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">fruits </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#800000">"Banana"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">"Orange"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">"Apple"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">"Mango"</FONT><FONT COLOR="#000000">]; fruits.sort();</FONT> {result: ["Apple", "Banana", "Mango", "Orange", 1: "Apple", 2: "Banana", 3: "Mango", 4: "Orange"]}

JRS> q

SAMPLES>

Vitaliy Serdtsev · Oct 30, 2018 go to post

If you do universal LPAD, it is best $$lpad^%qarfunc, because for certain arguments may produce an incorrect result, for example:

<FONT COLOR="#0000ff">#define </FONT><FONT COLOR="#000000">lpad(%s,%len,%pad) </FONT><FONT COLOR="#0000ff">$tr($j(%s,%len),</FONT><FONT COLOR="#008000">" "</FONT><FONT COLOR="#0000ff">,%pad)
   
s </FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"a b"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">=8,</FONT><FONT COLOR="#800000">pad</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"0"
   
</FONT><FONT COLOR="#0000ff">w $$$lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">pad</FONT><FONT COLOR="#000000">),!
 ,</FONT><FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">lpad</FONT><FONT COLOR="#000000">^%qarfunc(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">pad</FONT><FONT COLOR="#000000">),!
 ,</FONT><FONT COLOR="#0000ff">$$$lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">),!
 ,</FONT><FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">lpad</FONT><FONT COLOR="#000000">^%qarfunc(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">),!</FONT>
Result:
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^test</FONT>
<FONT COLOR="red">00000a0b</FONT>
<FONT COLOR="green">00000a b</FONT>
<FONT COLOR="red">aaaaaaab</FONT>
<FONT COLOR="green">a ba a b</FONT>
Vitaliy Serdtsev · Oct 29, 2018 go to post

Also LPADSQL
USER><FONT COLOR="#0000ff">d $system</FONT><FONT COLOR="#008080">.SQL</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Shell</FONT><FONT COLOR="#000000">()</FONT>
SQL Command Line Shell

The command prefix is currently set to: <>. Enter q to quit, ? for help. USER>><FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'1'</FONT><FONT COLOR="#000000">,4,</FONT><FONT COLOR="#008080">'0'</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#008000">n</FONT>

  1.  <FONT COLOR="#0000ff">select&nbsp;</FONT><FONT COLOR="#008000">lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'1'</FONT><FONT COLOR="#000000">,4,</FONT><FONT COLOR="#008080">'0'</FONT><FONT COLOR="#000000">)&nbsp;</FONT><FONT COLOR="#008000">n</FONT>
    

n 0001

1 Rows(s) Affected

Vitaliy Serdtsev · Oct 29, 2018 go to post

The functions from %qarfunc are actively used in system classes, so I don't think ^%qarfunc will be removed in the near future, otherwise everything will stop working.

Vitaliy Serdtsev · Oct 19, 2018 go to post

Try

<FONT COLOR="#000080">ClientMethod </FONT><FONT COLOR="#000000">changeParams() [ </FONT><FONT COLOR="#000080">Language </FONT><FONT COLOR="#000000">= javascript ]
{
  </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">query </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">zen(</FONT><FONT COLOR="#800000">'categorieBeneficiaire'</FONT><FONT COLOR="#000000">);
  </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">param1 </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">zen(</FONT><FONT COLOR="#800000">'catBParam1'</FONT><FONT COLOR="#000000">);
  </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">param2 </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">zen(</FONT><FONT COLOR="#800000">'catBParam2'</FONT><FONT COLOR="#000000">);

  param1.value</FONT><FONT COLOR="#000080">=</FONT><FONT COLOR="#800000">'OS'</FONT><FONT COLOR="#000000">;   param2.value</FONT><FONT COLOR="#000080">=</FONT><FONT COLOR="#800000">'NSAL'</FONT><FONT COLOR="#000000">;   query.refreshContents(); }</FONT>

<FONT COLOR="#000080">/// This client event, if present, is fired when the page is loaded. ClientMethod </FONT><FONT COLOR="#000000">onloadHandler() [ </FONT><FONT COLOR="#000080">Language </FONT><FONT COLOR="#000000">= javascript ] {   zenPage.changeParams(); }</FONT>