See more here: Evaluating XPath Expressions
- Log in to post comments
See more here: Evaluating XPath Expressions
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 pA, ByRef 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").Hi Ponnumani.
I would like to make a number of clarifications:
<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>
I still prefer to use built-in tools when they are there, rather than reinventing the wheel.
Class User.samplexlsconversion Extends (%Persistent, %Populate)
{
Property name As %String;
Property DOB As %Date;
Property address As %String;
Property PhoneNumber As %Numeric;
Property BloodGroup As %String(VALUELIST = " A A- B B- O");
ClassMethod TestExport2CSV()
{
d ..%KillExtent()
d ..Populate(1000)
s tmp=..%OpenId(1)
s tmp.name=tmp.name_$c(34)
d tmp.%Save()
s tmp=..%OpenId(2)
s tmp.name=$c(34)_tmp.name_$c(34)
d tmp.%Save()
s mgr = ##class(%SQL.Export.Mgr).%New()
s mgr.FileName = "c:\Temp\test.csv"
s mgr.ClassName = ..%ClassName(1)
s mgr.TableName = $$$CLASSsqltablename($$$gWRK,mgr.ClassName)
s mgr.Delimiter = ","
s mgr.StringQuote = $c(34)
s mgr.DateFormat = 3
s mgr.TimeFormat = 1
s mgr.TimeStampFormat = 1
s mgr.NoCheck = $$$YES
s mgr.HasHeaders = $$$YES
s cols="Name:S;Address:S;PhoneNumber:N;BloodGroup:S;DOB:D"
f i=1:1:$l(cols,";") {
s c=$p(cols,";",i)
d mgr.ColumnNames.Insert($p(c,":",1))
d mgr.ColumnTypes.Insert($p(c,":",2))
}
d mgr.Export()
}
}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.
Below are two ways without additional permissions on %DB_CACHESYS:
#include %systemInclude
n
try{
s sslName="Test"
w "1) GetSSLConfigList^%SYS.SECURITY1(.SSLConfigs)",!!
w $$Test1(sslName)
w !!,"2) $$ListSSLConfigs^%SYS.SECURITY(Client/Server)",!!
w $$Test2(sslName)
}catch(ex){
w "Error ", ex.DisplayString(),!
}
Test1(ssl) {
d GetSSLConfigList^%SYS.SECURITY1(.SSLConfigs)
f i=1:1:SSLConfigs return:SSLConfigs(i)=ssl $$$YES
q $$$NO
}
Test2(ssl) {
q ''$lf($lfs($$ListSSLConfigs^%SYS.SECURITY("Client")_","_
$$ListSSLConfigs^%SYS.SECURITY("Server"))
,ssl)
}See %RemoteResultSet.
And if so?
CREATE TABLE test (
identifier VARCHAR(200) NOT NULL,
value INTEGER COMPUTEONCHANGE("%%UPDATE") COMPUTECODE {&sql(select max(value)+1 into :{*} from test where identifier=:{identifier})},
PRIMARY KEY (identifier)
)SQL Projection of Object-Valued Properties
INSERT INTO Package_Tables.Person_Address (Person, element_key, Address_AddressType, Address_StreetAddress) VALUES (1,2,1,'72 Fake Street')
Working example:
Class dc.test [ Abstract ]
{
/// d ##class(dc.test).Test1()
ClassMethod Test1() [ ProcedureBlock = 0 ]
{
new active,reactive,info,i
kill info
set active = 1
set reactive = 2
for i="active","reactive" {
set info(i)= @i
}
zw info
}
/// d ##class(dc.test).Test2()
ClassMethod Test2() [ PublicList = (active, reactive) ]
{
new active, reactive
kill info
set active = 1
set reactive = 2
for i="active","reactive" {
set info(i)= @i
}
zw info
}
}What will the following code output?
s resptext="{""access_token"":""4SDFDSFDSF-aSDASDASD"",""expires_in"":""3300"",""refresh_token"":"""",""scope"":""sms_send"",""token_type"":""Bearer""}"
s sc = ##class(%ZEN.Auxiliary.jsonProvider).%ParseJSON(resptext,,.pObject,1)
i $$$ISOK(sc) {
w pObject,!!,
pObject."access_token",!,
pObject."expires_in",!
k arr s arr="" d pObject.%CopyToArray(.arr) zw arr
}else{
d $system.OBJ.DisplayError(sc)
}My result (2018.1):
USER>d ^test
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"What will the following code output?
USER>k arr d pObject.%CopyToArray(.arr) zw arr
PS: "in" ≠ "expires_in"
Hi Adrian.
Made a small example:
#dim rs As %ResultSet
s pid=4652
s rs=##class(%ResultSet).%New("%SYS.ProcessQuery:VariableByPid")
f filter="","a*" {
w !,"Filter = ",$$$quote(filter),!
d rs.Execute(pid,,,,filter)
while rs.Next() {
w "Name = ",rs.Get("Name"),", Value = ",rs.Get("Value"),!
}
}Result:
USER:4652>s a="11",b="22",a1="33" w $job 4652 USER:1392>w $job,! d ^dc 1392 Filter = "" Name = a, Value = 11 Name = a1, Value = 33 Name = b, Value = 22 Filter = "a*" Name = a, Value = 11 Name = a1, Value = 33
The presence of a potential opportunity to read the documentation via "Class Reference". For macros from *.inc this is not possible.
Still another option:
Class dc.test Extends %Persistent
{
Property JSONData As list Of %String [ SqlListType = SUBNODE ];
ClassMethod Test()
{
d ..%KillExtent()
f l=$lb("apple","pear","plum"),$lb({"Name":"Kyle"}.%ToJSON(),{"Name":"Evgeny"}.%ToJSON()) {
s t=..%New()
d t.JSONData.InsertList(l)
d t.%Save()
}
zw @$system.Dictionary.comMemberKeyGet($this,$$$cCLASSstorage,$$$nameDefaultStorageNameGet,$$$cSDEFdatalocation)
s rs=##class(%SQL.Statement).%ExecDirect(,"select distinct json_arrayagg(JSONData %foreach(test)) from dc.test_JSONData")
while rs.%Next() {
s jsonStr=rs.%GetData(1),
json=[].%FromJSON(jsonStr)
w !,jsonStr,", %Size()=",json.%Size(),!
}
}
}Result:
USER>d ##class(dc.test).Test()
^dc.testD=2
^dc.testD(1)=$lb("")
^dc.testD(1,"JSONData")=3
^dc.testD(1,"JSONData",1)="apple"
^dc.testD(1,"JSONData",2)="pear"
^dc.testD(1,"JSONData",3)="plum"
^dc.testD(2)=$lb("")
^dc.testD(2,"JSONData")=2
^dc.testD(2,"JSONData",1)="{""Name"":""Kyle""}"
^dc.testD(2,"JSONData",2)="{""Name"":""Evgeny""}"
["apple","pear","plum"], %Size()=3
[{"Name":"Kyle"},{"Name":"Evgeny"}], %Size()=2Doc:
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>PS: you can further explore the sources of the #server()# -> cspHttpServerMethod() -> cspProcessResponse(), which are in the file cspxmlhttp.js.var bool = #server(..giveMeAFalse())#; console.log("bool = " + bool); console.log("typeof bool = ", typeof bool);
Result: bool = 4 typeof bool = string
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())#); ... <script language="cache" method="giveMeAFalse" arguments="" returntype="%Boolean" procedureblock='1'>return "false"</script>
s tags=$lb("a","b","c"),
str="c,a1,d,b,f"
s l=$lfs(str),ptr=0
while $listnext(tags,ptr,tag) {
w:$lf(l,tag) tag,!
}Resultb c
Source code of class %Net.Remote.Utility is open, so you can use it to make your "RunCommandViaCPIPE" method and already use it.
PS: it's just a wrapper around low-level commands, see Local Interprocess Communication.
use %VarString
No.
If you beware to use %occLibrary, you may look into side %Regex.Matcher
Here is another documented solution:
#include %systemInclude
n
try{
#define TAB $c(9)
s csv="""ABC,"_$c(10)_" Company,"",""123 Main St, Ste 102"",""Anytown, DC"",10001,234-567-8901,""Anytown"_$$$TAB_"DC"""
d ##class(%DeepSee.TermList).%ParseCSVRecord(csv,.arr)
w csv,!!,$$WriteCSVRecord(.arr,$$$TAB)
}catch(ex){
w "Error ", ex.DisplayString(),!
}
WriteCSVRecord(&pRecord, pDelim=",", pEncode=$$$YES) {
// made on the basis of the method %WriteCSVRecord
Set r = ""
Set k = $O(pRecord(""))
While (k'="") {
Set tValue = $G(pRecord(k))
Set:$G(pEncode) tValue = $ZCVT(tValue,"O","UTF8")
Set r = r _ $S((tValue["""")||(tValue[",")||(tValue[pDelim):$$$quote(tValue),1:tValue)
Set k = $O(pRecord(k))
Set:k'="" r = r _ pDelim
}
Quit r
}Result:
USER>d ^dc
"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"#include %systemIncludeResult:s csv="ABC Company,""123 Main St, Ste 102"",""Anytown, DC"",10001,234-567-8901" s list=$$CSVtoList^%occLibrary(csv)
f i=1:1:$ll(list) s:$li(list,i)["," $li(list,i)=$$$quote($li(list,i)) w csv,!,$lts(list,$c(9))
USER>d ^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
Maybe the name of the topic to specify a CSV-string instead of string ?
After clarification, the question became more clear.
$tr(str,",",$c(9))
or
$replace(str,",",$c(9))
I was looking at the generated INT code for &sql(select lpad('1',4,'0') n)
Unfortunately, for COS at the moment I have not found an analogue LPADSQL.
Can you offer a documented LPADCOS ?
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>d ##class(%CPT.JS.Runtime.Shell).Run()
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 var obj = { name: "John", age: 30, city: "New York" }; JSON.stringify(obj);
{result: "{""name"":""John"",""age"":30,""city"":""New York""}"}
JRS> .N Math.random()
{result: .5670654247514904}
JRS> .N var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.sort();
{result: ["Apple", "Banana", "Mango", "Orange", 1: "Apple", 2: "Banana", 3: "Mango", 4: "Orange"]}
JRS> q
SAMPLES>