And if so?
w $zobjref(^||PPG(1)).Name
Still take a look at $$$objOrefToInt/$$$objIntToOref (%occObject.inc)
PS: it should be noted that OREF ≠ OID and serve different purposes.
- Log in to post comments
And if so?
w $zobjref(^||PPG(1)).Name
Still take a look at $$$objOrefToInt/$$$objIntToOref (%occObject.inc)
PS: it should be noted that OREF ≠ OID and serve different purposes.
I found out the reason for the difference in the result BASIC256:
InsteadError on site.s len = 10*n\4,
must be
s len = 10*n\3,
Translation of: LUA
calcPILua(n=1000) public {
s len = 10*n\3,
nines = 0,
predigit = 0
f j=1:1:len s a(j)=2
f j=1:1:n {
s q=0
f i=len:-1:1 {
s x = 10*a(i) + (q*i),
a(i)=x#(2*i-1),
q=x\(2*i-1)
}
s a(1)=q#10,
q=q\10
i q=9 {
s nines = nines + 1
}elseif q=10 {
w predigit+1
f k = 1:1:nines w 0
s predigit = 0, nines = 0
}else{
w predigit
s predigit = q
i nines {
f k = 1:1:nines w 9
s nines = 0
}
}
}
w predigit
}The result of this example is exactly the same as the result of the program C# (tested at n=10000).
Translation of: BASIC256
calcPI(n=1000) public {
s len = 10*n\4,
needdecimal = $$$YES,
nines = 0,
predigit = 0 ;# {First predigit is a 0}
f j=1:1:len s a(j-1)=2 ;# {Start with 2s}
f j=1:1:n {
s q=0
f i=len:-1:1 {
;# {Work backwards}
s x = 10*a(i-1) + (q*i),
a(i-1)=x#(2*i-1),
q=x\(2*i-1)
}
s a(0)=q#10,
q=q\10
i q=9 {
s nines = nines + 1
}elseif q=10 {
s d = predigit+1 d outputd
i nines>0 f k = 1:1:nines s d = 0 d outputd
s predigit = 0, nines = 0
}else{
s d = predigit,predigit = q d outputd
i nines {
f k = 1:1:nines s d = 9 d outputd
s nines = 0
}
}
}
w predigit
q
outputd()
if needdecimal {
q:d=0
w d_"."
s needdecimal = $$$NO
} else {
w d
}
}The greater "n", the higher the accuracy.
If there is a lack of RAM, you can easily replace the local array "a" with globals ^||a or ^a.
w $$MyFunc(1),!, $$MyFunc(1,.V)," V=",V,! MyFunc(p...) s Answer=p_" params" s:p=2 p(2)="it's all good" q AnswerUSER>do ^test 1 params 2 params V=it's all good
Can be easier:
ClassMethod GetPrivateProp(
oref,
propName) As %String
{
d ##class(%Studio.General).DumpObjectExecute(.arr,oref)
q arr(propName)
}SELECT
LBTS_RowID
,LBTS_CollectedDate
FROM SQLUser.LB_TestSet
JOIN SQLUser.LB_Transfer ON ($LISTBUILD(LBTS_RowID) %INLIST LBTR_TestSetList)
WHERE LBTS_CollectedDate BETWEEN {d '2019-01-01'} AND {d '2019-05-10'}Try this:
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen">
<tableNavigatorBar tablePaneId="tp1"/>
<tablePane
id="tp1"
OnCreateResultSet="CreateRS"
OnExecuteResultSet="ExecuteRS"
maxRows="0"
pageSize="10"
useSnapshot="true"
>
<parameter value="USER1"/>
</tablePane>
<tableNavigatorBar tablePaneId="tp2"/>
<tablePane
id="tp2"
OnCreateResultSet="CreateRS"
OnExecuteResultSet="ExecuteRS"
maxRows="0"
pageSize="10"
useSnapshot="true"
>
<parameter value="USER2"/>
</tablePane>
</page>
}For example so:
Class dc.test Extends %ZEN.Component.page
{
XData Style
{
<style type="text/css">
</style>
}
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen">
<tablePane
OnCreateResultSet="CreateRS"
OnExecuteResultSet="ExecuteRS"
>
<parameter name="ns" value="USER1"/>
</tablePane>
<tablePane
OnCreateResultSet="CreateRS"
OnExecuteResultSet="ExecuteRS"
>
<parameter name="ns" value="USER2"/>
</tablePane>
</page>
}
Method ExecuteRS(
myRS As %ResultSet,
Output pSC As %Status,
pInfo As %ZEN.Auxiliary.QueryInfo) As %Boolean
{
d myRS.Prepare("select * from xyz")
d myRS.Execute()
s tSC=$$$OK
q $$$YES
}
Method CreateRS(
Output tSC As %Status,
pInfo As %ZEN.Auxiliary.QueryInfo) As %ResultSet
{
s rs=##class(%RemoteResultSet).%New()
s rs.UserName="_system"
s rs.Password="SYS"
s rs.ConnectionString=$$$FormatText("localhost[%1]:%2",##class(%SQL.Manager.API).GetPort(),pInfo.parms(1))
s tSC=$$$OK
q rs
}
}For example so:
Class myapp.jsonProvider Extends %ZEN.Auxiliary.jsonProvider
{
ClassMethod getOrderedProps(
pClass As %Dictionary.CompiledClass,
ByRef pList) [ Internal ]
{
d ##super(pClass,.pList)
s key = "" f { s key = $o(pList(key)) q:""=key
zk:$lf(^||skipProps,pList(key)) pList(key)
}
}
}
Class myapp.myclass Extends %RegisteredObject
{
Property property1 As %String;
Property property2 As %String;
Property property3 As %String;
/// d ##class(myapp.myclass).Test()
ClassMethod Test()
{
s myClass = ..%New()
s myClass.property1 = "value 1"
s myClass.property2 = "value 2"
s myClass.property3 = "value 3"
f i=$lb("property3"),$lb("property2","property1") {
s ^||skipProps=i
d ##class(myapp.jsonProvider).%WriteJSONStreamFromObject(.tStream,myClass,,,$$$YES,"ed")
w "skip:",$lts(i),?25," -> ",tStream.Read(),!
}
}
}
USER>d ##class(myapp.myclass).Test()
skip:property3 -> {"property1":"value 1","property2":"value 2"}
skip:property2,property1 -> {"property3":"value 3"}Made a small demo with two options.
Include %occResultSet
Class dc.test [ Abstract ]
{
ClassMethod MultiRS(i As %Integer) [ ReturnResultsets, SqlProc ]
{
i i#2 {
$$$ResultSet("select 'Name1_1' s1,'Name2_1' s2 union all select 'Name1_2','Name2_2'")
} else {
$$$ResultSet("select 1 i1,4 i2,3 i3 union all select 2,5,6 union all select 3,6,9")
$$$ResultSet("select '+1' n union all select '-2' union all select '3.1' union all select '4_4'")
}
}
Query MyCustomQueryCube(pCubeName As %String) As %Query [ SqlProc ]
{
}
ClassMethod MyCustomQueryCubeExecute(
ByRef qHandle As %Binary,
pCubeName As %String) As %Status
{
s qHandle("pCubeName")=pCubeName
i pCubeName="a" {
s N=2 f i=1:1:N s qHandle(N+1-i)=$lb("Name1_"_i,"Name2_"_i)
}else{
s N=3 f i=1:1:N s qHandle(N+1-i)=$lb(i,i+3,i*3)
}
s qHandle=N
q $$$OK
}
ClassMethod MyCustomQueryCubeFetch(
ByRef qHandle As %Binary,
ByRef Row As %List,
ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = MyCustomQueryCubeExecute ]
{
i qHandle=0 {
s Row=""
s AtEnd=1
}else{
s Row=qHandle(qHandle)
s qHandle=qHandle-1
}
q $$$OK
}
ClassMethod MyCustomQueryCubeClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = MyCustomQueryCubeFetch ]
{
k qHandle
q $$$OK
}
ClassMethod MyCustomQueryCubeGetInfo(
ByRef colinfo As %List,
ByRef parminfo As %List,
ByRef idinfo As %List,
ByRef qHandle As %Binary,
extoption As %Integer = 0,
ByRef extinfo As %List) As %Status
{
i qHandle("pCubeName")="a" {
s colinfo=$lb($lb("s1",10,"s1"),$lb("s2",10,"s2"))
}else{
s colinfo=$lb($lb("i1",5,"i1"),$lb("i2",5,"i2"),$lb("i3",5,"i3"))
}
s parminfo=$lb($lb("pCubeName","10"))
s idinfo=$lb(0,"")
q $$$OK
}
ClassMethod MyCustomQueryCubeGetODBCInfo(
ByRef colinfo As %List,
ByRef parminfo As %List,
ByRef qHandle As %Binary) As %Status
{
i qHandle("pCubeName")="a" {
s colinfo=$lb(2,
"s1",12,50,0,2,"s1","test","dc","",$c(0,0,0,0,0,0,0,0,0,0,0,0),
"s2",12,50,0,2,"s2","test","dc","",$c(0,0,0,0,0,0,0,0,0,0,0,0)
)
}else{
s colinfo=$lb(3,
"i1",4,10,0,2,"i1","test","dc","",$c(0,0,0,0,0,0,0,0,0,0,0,0),
"i2",4,10,0,2,"i2","test","dc","",$c(0,0,0,0,0,0,0,0,0,0,0,0),
"i3",4,10,0,2,"i3","test","dc","",$c(0,0,0,0,0,0,0,0,0,0,0,0)
)
}
s parminfo=$lb(1,12,50,0,2,"pCubeName",1)
q $$$OK
}
/// d ##class(dc.test).Test()
ClassMethod Test()
{
try{
s rs=##class(%SQL.Statement).%New()
$$$ThrowOnError(rs.%PrepareClassQuery("dc.test","MyCustomQueryCube"))
f i="a","b" d rs.%Execute(i).%Display()
w !!,"=============="
$$$ThrowOnError(rs.%Prepare("call dc.test_MultiRS(?)"))
f i=0,1 d rs.%Execute(i).%Display()
}catch(ex){
w "Error ", ex.DisplayString(),!
}
}
}
USER>d ##class(dc.test).Test()
Dumping result #1
s1 s2
Name1_1 Name2_1
Name1_2 Name2_2
2 Rows(s) Affected
Dumping result #1
i1 i2 i3
1 4 3
2 5 6
3 6 9
3 Rows(s) Affected
==============
Dumping result #1
i1 i2 i3
1 4 3
2 5 6
3 6 9
3 Rows(s) Affected
Dumping result #2
n
+1
-2
3.1
4_4
4 Rows(s) Affected
Dumping result #1
s1 s2
Name1_1 Name2_1
Name1_2 Name2_2
2 Rows(s) Affecteds delim = " ", abbrv = "" ... set abbrv = abbrv _ $e($PIECE(desc,delim,i),1,2) // But if I put w abbrv I can get "Resytorewipa"
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
{
ClassMethod MethodTest(args As %DynamicObject)
{
i $IsObject(args) {
w args.%ToJSON(),!
w:args.%IsDefined("arr") args.arr."2",!
}else{
w "null",!
}
}
ClassMethod Test()
{
;d ##class(dc.test).Test()
d ..MethodTest(),
..MethodTest({}),
..MethodTest({"arg1":($zts),"arg6":"hello","arr":["a",10,true,2.5674]})
}
}Result:
USER>d ##class(dc.test).Test()
null
{}
{"arg1":"65136,19638.022","arg6":"hello","arr":["a",10,true,2.5674]}
1First, should be so (AttachFile):
s status=msg.AttachFile("F:\MyDir","myFirstFile.pdf",1,,.count)
s status=msg.AttachFile("F:\MyDir","mySecondFile.pdf",1,,.count)Second, you did not specify the error text.
Try the following simple MAC-example, replacing the values with your own:
#include %systemInclude
new
try{
$$$AddAllRoleTemporaryInTry
new $namespace
set msg=##class(%Net.MailMessage).%New()
set msg.Subject="Subject"
set msg.From="from@domain"
do msg.To.Insert("to@domain")
do msg.TextData.Write("Hello!")
$$$ThrowOnError(msg.AttachFile("F:\MyDir","myFirstFile.pdf"))
$$$ThrowOnError(msg.AttachFile("F:\MyDir","mySecondFile.pdf"))
set smtp=##class(%Net.SMTP).%New()
set smtp.smtpserver="123.145.167.189"
$$$ThrowOnError(smtp.Send(msg))
}catch(ex){
write "Error ", ex.DisplayString(),!
}s res=##class(%SQL.Statement).%ExecDirect(,$$$FormatText("CREATE TABLE %1 (TNAMESPACE CHAR(100),TINTERFACE CHAR(100))",$$$quote("xxxxx"_$USERNAME)))
w res.%SQLCODESee examples and try "Run It" in JSON_ARRAYAGG.
E.g.:SELECT JSON_ARRAYAGG(Home_State) FROM Sample.Person WHERE Home_State %STARTSWITH 'A'Result:
["AR","AL","AR","AL","AL","AR","AK","AL","AR","AK","AK","AZ","AR","AR","AL"]
SELECT 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"}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"}]See %CACHE_HOME%\dev\Cache\callout\demo\czf.pdf (Section "Lists")
Here is a small example:
select JSON_ARRAYAGG(JSON_OBJECT('ID':ID,'Age':Age,'SSN':SSN)) from (select top 3 ID,Age,SSN from sample.person)Result:
[{"ID":1,"Age":59,"SSN":"502-68-5767"},{"ID":2,"Age":6,"SSN":"169-66-9969"},{"ID":3,"Age":64,"SSN":"868-61-3642"}]As of release 2012.2, member names can be delimited. To create a delimited member name, use double quotes for the first and last characters of the name. Then the name can include characters that are otherwise not permitted.
Then it's better:
Method Get() As %String [ CodeMode = objectgenerator, NoContext]
{
d:%mode="propertymethod" %code.WriteLine(" q ..Test()")
q $$$OK
}It doesn't work for me too, there is an error
#1056: Missing subscript : '}'
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 ]
{
Method Get() As %String [ CodeMode = objectgenerator ]
{
d %code.WriteLine(" q $this.Test()")
q $$$OK
}
}This works too btw:
It doesn't work for me:
MPP5376 : Method or Property 'Test' does not exist in this class.
Try this
Class Test.String Extends %String
{
Method Get() As %String [ CodeMode = objectgenerator, NoContext ]
{
d %code.WriteLine(" q $this.Test()")
q $$$OK
}
}You can do it even easier:
&sql(SELECT {fn TIMESTAMPDIFF(SQL_TSI_HOUR,CURRENT_TIMESTAMP(3),:tx)})Small example:
&sql(SELECT CURRENT_TIMESTAMP(3),
{fn TIMESTAMPADD(SQL_TSI_MINUTE,67,CURRENT_TIMESTAMP(3))} into :txBefore,:txAfter)
w txBefore," -> ",txAfter,!!
&sql(SELECT {fn TIMESTAMPDIFF(SQL_TSI_HOUR,CURRENT_TIMESTAMP(3),:txAfter)},
{fn TIMESTAMPDIFF(SQL_TSI_HOUR,:txBefore,:txAfter)} into :r1,:r2)
w r1,!,r2Result:
USER>d ^test 2019-04-08 08:51:34.916 -> 2019-04-08 09:58:34.916 1 1 USER>d ^test 2019-04-08 08:55:11.907 -> 2019-04-08 10:02:11.907 2 2
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.
There are two ways to define views, so I'll give you both options:
/// bla-bla-bla:<ul>
/// <li>Name - Person's name;</li>
/// <li>SSN - Person's Social Security number. This is validated using pattern match;</li>
/// <li>DOB - Person's Date of Birth.</li></ul>
Class view.Person [ ClassType = view, CompileAfter = Sample.Person, DdlAllowed, Not ProcedureBlock, ViewQuery = { select Name,SSN,DOB from Sample.Person} ]
{
}/// This sample persistent class represents a person.
/// <p>Maintenance note: This class is used by some of the bindings samples.
Class Sample.Person Extends (%Persistent, %Populate, %XML.Adaptor)
{
...
/// bla-bla-bla:<ul>
/// <li>Name - Person's name;</li>
/// <li>SSN - Person's Social Security number. This is validated using pattern match;</li>
/// <li>DOB - Person's Date of Birth.</li></ul>
Query viewPerson() As %SQLQuery [ SqlView, SqlViewName = viewPerson ]
{
select Name,SSN,DOB from Sample.Person
}
...
}Now take a look at these classes from Documatic.
Look in the direction of the DocBook that is used in the embedded InterSystems documentation. There is support for highlighting for many languages: Caché Basic, Caché ObjectScript, Caché Class Definition Syntax, etc.
Very long ago (2012), I wrote an article on this topic, but it is in Russian (machine translation).