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 · Mar 11, 2019 go to post

Hi Robert.

Exactly.

Programmatically Managing Roles:

This command can only be invoked either from a routine that is part of the CACHESYS database or if the current privileges held include Write permission for the CACHESYS database (%DB_CACHESYS:W).

Note that setting $ROLES only alters a process’s added roles, not its login roles.

There is a third way, but I specifically did not publish it.

Vitaliy Serdtsev · Mar 12, 2019 go to post

Hi Ponnumani.

I would like to make a number of clarifications:

  • <FONT COLOR="#000080">VALUELIST </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">"A A- B B- O"</FONT> -> <FONT COLOR="#000080">VALUELIST </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">" A A- B B- O"</FONT>
  • it is necessary to consider the order of the fields in the global on the basis of Storage. For example, I have following Storage:
    <Data name="samplexlsconversionDefaultData">
    <Value name="1">
    <Value>%%CLASSNAME</Value>
    </Value>
    <Value name="2">
    <Value>name</Value>
    </Value>
    <Value name="3">
    <Value>DOB</Value>
    </Value>
    <Value name="4">
    <Value>address</Value>
    </Value>
    <Value name="5">
    <Value>PhoneNumber</Value>
    </Value>
    <Value name="6">
    <Value>BloodGroup</Value>
    </Value>
    </Data>
  • need to add check for the presence of double quotes in strings, e.g. bla"bla
  • the date format for CSV should not be in the internal Caché format, because the date 37893 to users of other system/DBMS nothing says unlike e.g. 1944-09-30.
I still prefer to use built-in tools when they are there, rather than reinventing the wheel.
Class User.samplexlsconversion Extends (%Persistent%Populate)
{

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">name </FONT><FONT COLOR="#000080">As %String</FONT><FONT COLOR="#000000">;

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">DOB </FONT><FONT COLOR="#000080">As %Date</FONT><FONT COLOR="#000000">;

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">address </FONT><FONT COLOR="#000080">As %String</FONT><FONT COLOR="#000000">;

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">PhoneNumber </FONT><FONT COLOR="#000080">As %Numeric</FONT><FONT COLOR="#000000">;

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">BloodGroup </FONT><FONT COLOR="#000080">As %String</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">VALUELIST </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">" A A- B B- O"</FONT><FONT COLOR="#000000">);

</FONT><FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">TestExport2CSV() {      </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">%KillExtent</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">Populate</FONT><FONT COLOR="#000000">(1000)      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">%OpenId</FONT><FONT COLOR="#000000">(1)   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">name</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">name</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(34)   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Save</FONT><FONT COLOR="#000000">()      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">%OpenId</FONT><FONT COLOR="#000000">(2)   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">name</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(34)</FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">name</FONT><FONT COLOR="#000000">_</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(34)   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">tmp</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Save</FONT><FONT COLOR="#000000">()

  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%SQL.Export.Mgr</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">FileName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">"c:\Temp\test.csv"   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">ClassName </FONT><FONT COLOR="#000000">= ..</FONT><FONT COLOR="#0000ff">%ClassName</FONT><FONT COLOR="#000000">(1)   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">TableName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$$$CLASSsqltablename</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$gWRK</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">ClassName</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Delimiter </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">","   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">StringQuote </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(34)   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DateFormat </FONT><FONT COLOR="#000000">= 3   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">TimeFormat </FONT><FONT COLOR="#000000">= 1   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">TimeStampFormat </FONT><FONT COLOR="#000000">= 1   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">NoCheck </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$$$YES   s </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">HasHeaders </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$$$YES      s </FONT><FONT COLOR="#800000">cols</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"Name:S;Address:S;PhoneNumber:N;BloodGroup:S;DOB:D"   </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#0000ff">$l</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">cols</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">";"</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$p</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">cols</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">";"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">ColumnNames</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Insert</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$p</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">":"</FONT><FONT COLOR="#000000">,1))     </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">ColumnTypes</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Insert</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$p</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">":"</FONT><FONT COLOR="#000000">,2))   </FONT><FONT COLOR="#800080">}      </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">mgr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Export</FONT><FONT COLOR="#000000">() } }</FONT>

Vitaliy Serdtsev · Mar 14, 2019 go to post
Let's try to guess the return value of method t1().
Is that supposed to be hard? I immediately visually determined the result 20.

To be honest I don't really understand the point which the author wanted to convey. Maybe it's the lack of English.

In this case, the t3 method code is equivalent to the following code:
ClassMethod t3(ByRef pAByRef pB) [ ProcedureBlock = 1 ]
{
  set pA=4, pB=5
  set x=$increment(pA)*$increment(pB)
}
PS: by the way, absolutely nothing will change fundamentally if you replace "return" with "quit" (and "ByRef" with "Output").
Vitaliy Serdtsev · Mar 20, 2019 go to post

First, I would not use the input values directly in the query text, but would use Input Host Variables Second, if it is necessary, it is more elegant to use the following syntax:

<FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">stmt </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">%New</FONT><FONT COLOR="#000000">()
</FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">query </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Select Val1, Val2 FROM Table WHERE Val1=%1"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$quote</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"SomeCondition"</FONT><FONT COLOR="#000000">))</FONT>
Ideally these should be : &SQL(SELECT Val1, Val2 INTO :val1, :val2 FROM Table WHERE Val1='SomeCondition')
This is and now works:
&SQL(SELECT Val1Val2
               INTO :val1:val2
               FROM "Table"
               WHERE "Val1"='SomeCondition')
Vitaliy Serdtsev · Mar 28, 2019 go to post

See:

<FONT COLOR="#0000ff">select </FONT><FONT COLOR="#000080">* from </FONT><FONT COLOR="#008000">%Library</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">SQLCatalog_SQLReservedWords</FONT><FONT COLOR="#000000">()</FONT>
<FONT COLOR="#0000ff">$SYSTEM</FONT><FONT COLOR="#008080">.SQL</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">IsReservedWord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">word</FONT><FONT COLOR="#000000">)</FONT>
Vitaliy Serdtsev · Apr 4, 2019 go to post

This setting does not affect users experience. Before enabling, make sure you have Username/Password and/or System_Manager set, otherwise any user will be able to manage your CSP gateway. Everything is described in detail in the link I mentioned above, so I can hardly add anything more than that.

Vitaliy Serdtsev · Apr 10, 2019 go to post

Try this

<FONT COLOR="#000080">Class Test.String Extends %String
</FONT><FONT COLOR="#000000">{

</FONT><FONT COLOR="#000080">Method </FONT><FONT COLOR="#000000">Get() </FONT><FONT COLOR="#000080">As %String </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">CodeMode </FONT><FONT COLOR="#000000">= objectgenerator, NoContext ] {   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">%code</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">WriteLine</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"  q $this.Test()"</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">q $$$OK </FONT><FONT COLOR="#000000">}

}</FONT>

Vitaliy Serdtsev · Apr 10, 2019 go to post
NoContext helped. What does it mean?
NoContext With the same success it is possible to specify NoContext for the class:
Class Test.String Extends %String [ NoContext ]
{

</FONT><FONT COLOR="#000080">Method </FONT><FONT COLOR="#000000">Get() </FONT><FONT COLOR="#000080">As %String </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">CodeMode </FONT><FONT COLOR="#000000">= objectgenerator ] {   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">%code</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">WriteLine</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"  q $this.Test()"</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">q $$$OK </FONT><FONT COLOR="#000000">}

}</FONT>

This works too btw:
It doesn't work for me:

MPP5376 : Method or Property 'Test' does not exist in this class.

Vitaliy Serdtsev · Apr 10, 2019 go to post

Then it's better:

<FONT COLOR="#000080">Method </FONT><FONT COLOR="#000000">Get() </FONT><FONT COLOR="#000080">As %String </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">CodeMode </FONT><FONT COLOR="#000000">= objectgenerator, NoContext]
{
  </FONT><FONT COLOR="#0000ff">d</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#800000">%mode</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"propertymethod" </FONT><FONT COLOR="#800000">%code</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">WriteLine</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"  q ..Test()"</FONT><FONT COLOR="#000000">)
  </FONT><FONT COLOR="#0000ff">q $$$OK
</FONT><FONT COLOR="#000000">}</FONT>
Vitaliy Serdtsev · Apr 16, 2019 go to post

See examples and try "Run It" in JSON_ARRAYAGG.

E.g.:
  1. SELECT JSON_ARRAYAGG(Home_StateFROM Sample.Person WHERE Home_State %STARTSWITH 'A'
    Result:
    ["AR","AL","AR","AL","AL","AR","AK","AL","AR","AK","AK","AZ","AR","AR","AL"]
  2. SELECT JSON_OBJECT('state':Home_StateFROM Sample.Person WHERE Home_State %STARTSWITH 'A'
    Result:
    {"state":"AR"}{"state":"AL"}{"state":"AR"}{"state":"AL"}{"state":"AL"}{"state":"AR"}{"state":"AK"}{"state":"AL"}{"state":"AR"}{"state":"AK"}{"state":"AK"}{"state":"AZ"}{"state":"AR"}{"state":"AR"}{"state":"AL"}
  3. SELECT JSON_ARRAYAGG(JSON_OBJECT('state':Home_State)) FROM Sample.Person WHERE Home_State %STARTSWITH 'A'
    Result:
    [{"state":"AR"},{"state":"AL"},{"state":"AR"},{"state":"AL"},{"state":"AL"},{"state":"AR"},{"state":"AK"},{"state":"AL"},{"state":"AR"},{"state":"AK"},{"state":"AK"},{"state":"AZ"},{"state":"AR"},{"state":"AR"},{"state":"AL"}]
Vitaliy Serdtsev · May 3, 2019 go to post
Also I'm curious if we can set up and pass a JSON that easily too? Would be great.
Certainly.
Class dc.test Extends %RegisteredObject
{

</FONT><FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">MethodTest(</FONT><FONT COLOR="#ff00ff">args </FONT><FONT COLOR="#000080">As %DynamicObject</FONT><FONT COLOR="#000000">) {  </FONT><FONT COLOR="#0000ff">i $IsObject</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{    </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%ToJSON</FONT><FONT COLOR="#000000">(),!    </FONT><FONT COLOR="#0000ff">w</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%IsDefined</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"arr"</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">arr</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">"2"</FONT><FONT COLOR="#000000">,!  </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">else</FONT><FONT COLOR="#800080">{    </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"null"</FONT><FONT COLOR="#000000">,!  </FONT><FONT COLOR="#800080">} </FONT><FONT COLOR="#000000">}

</FONT><FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">Test() {   </FONT><FONT COLOR="#008000">;d ##class(dc.test).Test()   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">MethodTest</FONT><FONT COLOR="#000000">(),     ..</FONT><FONT COLOR="#0000ff">MethodTest</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#ff00ff">{}</FONT><FONT COLOR="#000000">),     ..</FONT><FONT COLOR="#0000ff">MethodTest</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"arg1"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$zts</FONT><FONT COLOR="#000000">)</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"arg6"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"hello"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"arr"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#ff00ff">[</FONT><FONT COLOR="#008000">"a"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#000000">10</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#0000ff">true</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#000000">2.5674</FONT><FONT COLOR="#ff00ff">]}</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>
null
<FONT COLOR="#ff00ff">{}</FONT>
<FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"arg1"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"65136,19638.022"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"arg6"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"hello"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"arr"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#ff00ff">[</FONT><FONT COLOR="#008000">"a"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#000000">10</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#0000ff">true</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#000000">2.5674</FONT><FONT COLOR="#ff00ff">]}</FONT>
1
Vitaliy Serdtsev · May 17, 2019 go to post

Try this:

<FONT COLOR="#000080">XData </FONT><FONT COLOR="#000000">Contents [ </FONT><FONT COLOR="#000080">XMLNamespace </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">"http://www.intersystems.com/zen" </FONT><FONT COLOR="#000000">]
{
<</FONT><FONT COLOR="#000080">page </FONT><FONT COLOR="#800000">xmlns</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"http://www.intersystems.com/zen"</FONT><FONT COLOR="#000000">>
  <</FONT><FONT COLOR="#000080">tableNavigatorBar </FONT><FONT COLOR="#800000">tablePaneId</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"tp1"</FONT><FONT COLOR="#000000">/>
    <</FONT><FONT COLOR="#000080">tablePane
      </FONT><FONT COLOR="#800000">id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"tp1"
      </FONT><FONT COLOR="#800000">OnCreateResultSet</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"CreateRS"
      </FONT><FONT COLOR="#800000">OnExecuteResultSet</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"ExecuteRS"
      </FONT><FONT COLOR="#800000">maxRows</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"0"
      </FONT><FONT COLOR="#800000">pageSize</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"10"
      </FONT><FONT COLOR="#800000">useSnapshot</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"true"
    </FONT><FONT COLOR="#000000">>
    <</FONT><FONT COLOR="#000080">parameter </FONT><FONT COLOR="#800000">value</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"USER1"</FONT><FONT COLOR="#000000">/>
  </</FONT><FONT COLOR="#000080">tablePane</FONT><FONT COLOR="#000000">>
  <</FONT><FONT COLOR="#000080">tableNavigatorBar </FONT><FONT COLOR="#800000">tablePaneId</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"tp2"</FONT><FONT COLOR="#000000">/>
    <</FONT><FONT COLOR="#000080">tablePane
      </FONT><FONT COLOR="#800000">id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"tp2"
      </FONT><FONT COLOR="#800000">OnCreateResultSet</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"CreateRS"
      </FONT><FONT COLOR="#800000">OnExecuteResultSet</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"ExecuteRS"
      </FONT><FONT COLOR="#800000">maxRows</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"0"
      </FONT><FONT COLOR="#800000">pageSize</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"10"
      </FONT><FONT COLOR="#800000">useSnapshot</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"true"
    </FONT><FONT COLOR="#000000">>
    <</FONT><FONT COLOR="#000080">parameter </FONT><FONT COLOR="#800000">value</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"USER2"</FONT><FONT COLOR="#000000">/>
  </</FONT><FONT COLOR="#000080">tablePane</FONT><FONT COLOR="#000000">>
</</FONT><FONT COLOR="#000080">page</FONT><FONT COLOR="#000000">>
}</FONT>
Vitaliy Serdtsev · May 21, 2019 go to post

Can be easier:

<FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">GetPrivateProp(
  </FONT><FONT COLOR="#ff00ff">oref</FONT><FONT COLOR="#000000">,
  </FONT><FONT COLOR="#ff00ff">propName</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">As %String
</FONT><FONT COLOR="#000000">{
  </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Studio.General</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">DumpObjectExecute</FONT><FONT COLOR="#000000">(.</FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">oref</FONT><FONT COLOR="#000000">)
  </FONT><FONT COLOR="#0000ff">q </FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">propName</FONT><FONT COLOR="#000000">)
}</FONT>
Vitaliy Serdtsev · Jul 10, 2019 go to post

Translation of: LUA

<FONT COLOR="#ff0000">calcPILua</FONT><FONT COLOR="#000000">(n=1000) </FONT><FONT COLOR="#0000ff">public </FONT><FONT COLOR="#800080">{ 
  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">len </FONT><FONT COLOR="#000000">= 10*</FONT><FONT COLOR="#800000">n</FONT><FONT COLOR="#000000">\3,
    </FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#000000">= 0,
    </FONT><FONT COLOR="#800000">predigit </FONT><FONT COLOR="#000000">= 0
  
  </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">len </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">)=2
  
  </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">n </FONT><FONT COLOR="#800080">{
    </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">q</FONT><FONT COLOR="#000000">=0
    </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">:-1:1 </FONT><FONT COLOR="#800080">{
      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">x </FONT><FONT COLOR="#000000">= 10*</FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">) + (</FONT><FONT COLOR="#800000">q</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">),
        </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">)=</FONT><FONT COLOR="#800000">x</FONT><FONT COLOR="#000000">#(2</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">-1),
        </FONT><FONT COLOR="#800000">q</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">x</FONT><FONT COLOR="#000000">(2*</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="#800000">q</FONT><FONT COLOR="#000000">#10,
      </FONT><FONT COLOR="#800000">q</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">q</FONT><FONT COLOR="#000000">\10
    </FONT><FONT COLOR="#0000ff">i </FONT><FONT COLOR="#800000">q</FONT><FONT COLOR="#000000">=9 </FONT><FONT COLOR="#800080">{
      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#000000">+ 1
    </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">elseif </FONT><FONT COLOR="#800000">q</FONT><FONT COLOR="#000000">=10 </FONT><FONT COLOR="#800080">{
      </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">predigit</FONT><FONT COLOR="#000000">+1
      </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">k </FONT><FONT COLOR="#000000">= 1:1:</FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">0
      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">predigit </FONT><FONT COLOR="#000000">= 0, </FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#000000">= 0
    </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">else</FONT><FONT COLOR="#800080">{
      </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">predigit
      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">predigit </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800000">q
      </FONT><FONT COLOR="#0000ff">i </FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#800080">{
        </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">k </FONT><FONT COLOR="#000000">= 1:1:</FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">9
        </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">nines </FONT><FONT COLOR="#000000">= 0
      </FONT><FONT COLOR="#800080">}
    }
  }
  </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">predigit
</FONT><FONT COLOR="#800080">}</FONT>
The result of this example is exactly the same as the result of the program C# (tested at n=10000).
Vitaliy Serdtsev · Jul 10, 2019 go to post

I found out the reason for the difference in the result BASIC256:

Instead

len = 10*n\4,

must be

len = 10*n\3,

Error on site.

Vitaliy Serdtsev · Jul 12, 2019 go to post

And if so?

<FONT COLOR="#0000ff">w $zobjref</FONT><FONT COLOR="#000000">(^||PPG(1)).</FONT><FONT COLOR="#0000ff">Name</FONT>

Still take a look at <FONT COLOR="#0000ff">$$$objOrefToInt</FONT>/<FONT COLOR="#0000ff">$$$objIntToOref</FONT> (%occObject.inc)

PS: it should be noted that OREF ≠ OID and serve different purposes.

Vitaliy Serdtsev · Jul 16, 2019 go to post

Intel i5-2400

10000 digits ~ 58 sec.

calcPI(n) public { 
  s $lb(len,nines,predigit,r)=$lb(10*n\3,0,0,"")
  
  i=1:1:len a(i)=2
  
  j=1:1:{
    q=0
    i=len:-1:1 x=10*a(i)+(q*i), a(i)=x#(2*i-1), q=x\(2*i-1)
    a(1)=q#10, q=q\10
    q=9 {
      nines=nines+1
    }elseif q=10 {
      r=r_(predigit+1)_$$repeat^%qarfunc(0,nines), predigit=0, nines=0
    }else{
      r=r_predigitpredigit=q
      s:nines r=r_$$repeat^%qarfunc(9,nines), nines=0
    }
  }
  r_predigit
}
Vitaliy Serdtsev · Jul 24, 2019 go to post

Thank you for your comment. This code is taken from the source code %SYS, which in theory should be an example for application developers.

I hope that InterSystems developers will see your comment and make appropriate changes.

Vitaliy Serdtsev · Jul 24, 2019 go to post

Important note: it should be noted that the proposed solutions refer only to the port of the private web server, which may not even be installed. In the case of an external web server, this is not possible.

Vitaliy Serdtsev · Jul 29, 2019 go to post

I checked for versions 2009.1/2010.1: unfortunately, the <FONT COLOR="#0000ff">$zu</FONT><FONT COLOR="#000000">(114,0)</FONT> returns nothing, therefore, remains variant with the command line.

Example for Windows, provided that the system has a single network card:

<FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%syConfig
 </FONT><FONT COLOR="#0000ff">n </FONT><FONT COLOR="#800000">result
 </FONT><FONT COLOR="#0000ff">w $zu</FONT><FONT COLOR="#000000">(144,1,</FONT><FONT COLOR="#0000ff">$$$DEFETHADDR</FONT><FONT COLOR="#000000">),!,</FONT><FONT COLOR="#008000">"------"</FONT><FONT COLOR="#000000">,!
 
 </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="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Net.Remote.Utility</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">RunCommandViaCPIPE</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"getmac /NH /fo table"</FONT><FONT COLOR="#000000">,,.</FONT><FONT COLOR="#800000">result</FONT><FONT COLOR="#000000">))
 </FONT><FONT COLOR="#0000ff">w $p</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">result</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">" "</FONT><FONT COLOR="#000000">,1)</FONT>
PS: for other OS command line may be different.
Vitaliy Serdtsev · Jul 30, 2019 go to post

By default, the mac address of the computer on which the DBMS instance is running is returned. But you can get the mac address of any other computer, see getmac /?.

Vitaliy Serdtsev · Sep 18, 2019 go to post

The field TimeCreated is of type Ens.DataType.UTC.

Then so:

<FONT COLOR="#808000">datepart</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'hh'</FONT><FONT COLOR="#000000">, %external(</FONT><FONT COLOR="#008000">TimeCreated</FONT><FONT COLOR="#000000">))

See Data Display Options

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.