Julius Kavay · May 24, 2022 go to post

From your JSON-String, someone stripped off two chars at the end: "}]"

So if you add those chars, everything will be OK

d ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(JSONString3_"}]",,.list)
w list.GetAt(1).sensors.GetAt(1).jobGUID --> 0b955ee7-9a54-4b13-9af1-7019721faeab
 
Julius Kavay · May 23, 2022 go to post

I was told,  it's illegal to use data structure information, which doesn't were changed in the last 25 years (and after this many years, one could think to have the right given by "customary law" to use it), hence I decided for a more "legal" solution for the above problem - although this solution will work for IRIS (and recent Cache systems) only:

Class DC.Test Extends %RegisteredObject
{

/// Return TRUE if val contains a string
ClassMethod IsString2(val) As %Boolean
{
    quit {"a":(val)}.%GetTypeOf("a")="string"
}

/// Return TRUE if val contains a number (int, real or double)
ClassMethod IsNumber2(val) As %Boolean
{
    quit {"a":(val)}.%GetTypeOf("a")="number"
}

}
Julius Kavay · May 20, 2022 go to post

Oh, thanks for the hint, I'm aware of that. Actually one should remove the same characters as used in $locate():

if $locate($zstrip(data,"<w",",."), ...)

but the point is, to circumvent such problems, the rule number one in the electronic data processing is: you have to apply for check each and every input (at least) a formal check or you end up with problems like this. So the desired process should be:

read_data --> check_it --> proceed_if_OK_else_back_to_input

The same goes for data during an import process.

Julius Kavay · May 20, 2022 go to post

Try this one. The idea is, find the state (including the separators), everything before is the city and everything after is the zip code. Then we remove the separator chars (whitespaces, commas and dots).

ClassMethod Disjoin(data, cty, sta, zip)
{
    i $locate(data,"(\s|,|\.)[A-Za-z]{2}(\s|,|\.)",3,,sta) {
        s $lb(cty,zip)=$lfs(data,sta), sta=$$s(sta), cty=$$s(cty), zip=$$s(zip)
        
    } else { s (cty,sta,zip)="" }
    
    q sta]""
    
s(x)	q $zstrip(x,"<>w",",.")
}
Some examples
i ##class(DC.Test).Disjoin("CANTON,TX.,75103",.c,.s,.z) w c,", ",s,", ",z --> CANTON, TX, 75103
i ##class(DC.Test).Disjoin("MILFORD, OH 45150",.c,.s,.z) w c,", ",s,", ",z --> MILFORD, OH, 45150
i ##class(DC.Test).Disjoin("MILFORD OH 45150",.c,.s,.z) w c,", ",s,", ",z --> MILFORD, OH, 45150
i ##class(DC.Test).Disjoin("KANSAS CITY, MO, 12345",.c,.s,.z) w c,", ",s,", ",z --> KANSAS CITY, MO, 12345
i ##class(DC.Test).Disjoin("KANSAS CITY MO, 12345",.c,.s,.z) w c,", ",s,", ",z --> KANSAS CITY, MO, 12345
i ##class(DC.Test).Disjoin("ST. LOUIS MO, 12345",.c,.s,.z) w c,", ",s,", ",z --> ST. LOUIS, MO, 12345
i ##class(DC.Test).Disjoin("  ST. LOUIS MO, 12345",.c,.s,.z) w c,", ",s,", ",z --> ST. LOUIS, MO, 12345

OK, something like this gives a wrong result...
i ##class(DC.Test).Disjoin("   ST. LOUIS MO, 12345",.c,.s,.z) w c,", ",s,", ",z --> , ST, LOUIS MO, 12345

Julius Kavay · May 16, 2022 go to post
Class DC.Test Extends %RegisteredObject
{
/// Return TRUE if val contains an string
ClassMethod IsString(val) As %Boolean
{
    q $a($lb(val),2)<3
}
/// Return TRUE if val contains a number (int, real or double)
ClassMethod IsNumber(val) As %Boolean
{
    q $a($lb(val),2)>3
}
}

w ##class(DC.Test).IsString("abc") //--> 1
w ##class(DC.Test).IsString("123") //--> 1
w ##class(DC.Test).IsString(123) //--> 0
w ##class(DC.Test).IsNumber(123) //--> 1
w ##class(DC.Test).IsNumber("abc") //--> 0
w ##class(DC.Test).IsNumber("123") //--> 0
w ##class(DC.Test).IsNumber(123_345) //--> 0
w ##class(DC.Test).IsNumber(123+345) //--> 1
w ##class(DC.Test).IsString(123_456) //--> 1
w ##class(DC.Test).IsString(123+456) //--> 0

s x=123, y="123"
w ##class(DC.Test).IsString(x) //--> 0
w ##class(DC.Test).IsString(y) //--> 1

Julius Kavay · May 15, 2022 go to post

You are right, that's my fault. I didn't read the Notes, just the beginning of the challenge. Sorry.

Julius Kavay · May 11, 2022 go to post

The challenge talks about "...rearranging the letters ...", there is no restriction for the ASCII sequence, so this would not work with cyrillic character set :

CMOKBA  (fig tree, russian)
MOCKBA  (Moscow, capital city)

justmy2cents

Julius Kavay · May 8, 2022 go to post

The input variable pInput is an object(reference). You can't save OREFs in a global!

Think about OREFs as memory location (or, if you "speak" C, as a pointer). Trying to save it in a global is the same as saving a C pointer into a file for a later use... Won't work either 

Julius Kavay · Apr 29, 2022 go to post

People call it the reverse mode of $translate().

I saw this kind of usage of $tr() some 20 years ago. If I recall it right, it was mentioned in an article on usenet: comp.lang.mumps.

Julius Kavay · Apr 12, 2022 go to post

I referred in his answer only the $replace() function without explicit pointing this out. I was upset about the ambiguous question, sorry.

Julius Kavay · Apr 11, 2022 go to post

Sergei Shutov's answer is correct. The question was, how to remove a specific character (in this case: double quotes) from a string. Your answer is also correct but he told nothing about quoted strings.

The problem is, we have a question but no explanatory examples. Something like xxxx is the string I have, and
 yyyyy  is the string, I want to get.

Julius Kavay · Apr 11, 2022 go to post

To help you, help us to help you. This means, show us what you have you already done. So we can you point in the right direction, maybe explain, why your solution dosn't work, etc. It's nothing bad to ask for help. At some point in the time we all were new to Studio and ObjecScript.

Just asking for a solution is like going home from the school and letting the parents make the homework...

So what have you tryed?

Julius Kavay · Apr 5, 2022 go to post

For us all, the common denominator is Cache/IRIS and we have, as you know, Cache/IRIS for Win, Linux, AIX and MAC platforms. It's nice to know about existing external tools, but for some of us the COS solutions remains as the last resort, especially if those (external) tools do not exists for the OS, one works on (Just My2Cents).

Julius Kavay · Apr 4, 2022 go to post

First, as you alread wrote, changing the collation of an already existing installation is dengerious,
second, as far as I know, the database creation page (of ManagementPortal) offers you "Cache/IRIS-standard" and "Cache/IRIS-standard string" only. Nevertheless, changing to "standard string" only affects the collation and not the display, i.e. string subscripts will be displayed quoted but numeric subscripts are not quoted.

Julius Kavay · Mar 30, 2022 go to post

However, those legacy systems are already in operation, therefore they neither need python nor 3DES, at most, an upgrade to an current system. Hence, I don't understand your argumentation.

Julius Kavay · Mar 17, 2022 go to post

I'm quite shure, the above code won't work as expected, or with the words of Joseph Weizenbaum: “A computer will do what you tell it to do, but that may be much different from what you had in mind.”

The content of your myf variable is always 0 (the result of comparing nullstring with a filename), the size of tmpFile stream is also 0 (you never write into the stream).

Sometimes it's faster to write a "oneliner" to solve a simple problem then searching and downloading a solution from openexchange or from whereever... That's the beauty of the ObjectScript.

And if you think, the oneliner is worth to be reused, then make it to a method, add some small adjustments for a general usability...

The oneliner

s str="",tmp=##class(%File).TempFilename("txt") o tmp:"NWRU":0 i $t { u tmp zw ^||fruit s s=$zpos r:'$zseek(0) str#s c tmp:"D" }

The more general version

ClassMethod ToString(ref,max=32000)
{
    s tmp=##class(%File).TempFilename("txt") o tmp:"NWRU":0 q:'$t ""
    u tmp zw @ref s siz=$zpos r:'$zseek(0) str#$s(siz>max:max,1:siz) c tmp:"D" q str
}

Use it as

write ##(your.class).ToString($na(^||fruit))
Julius Kavay · Feb 8, 2022 go to post

Nice and easy...

That's like having an anteroom into bedroom and living room. There is always just one door open. If you want to go into bedroom, you have to brick the door of the living room and make a break through into the bedroom. The way back into living room is the same, just vice versa...

Julius Kavay · Feb 1, 2022 go to post

If you ask me, it should be the responsibility of the class compiler to check table names against reserved words and to quote them, if neccessary.
I think, you have closer connection to the development - what about an enhancement request?
Maybe a new property, say SqlTableNameQuoted.

Julius Kavay · Jan 31, 2022 go to post

First, disable the start of %ZSTART:

ManagementPortal-->SystemAdmin-->Configuration-->AdditionalSettings-->Startup:

here, set SystemStart to false.

Now, you can (Re)Start the system and check the %ZSTART routine.  <DIRECTORY> means, trying to access a nonexistent database directory.

After solving the problem, set SystemStart to true.

Julius Kavay · Jan 31, 2022 go to post

The simplest way is to create a classmethod, which returns the desired name:

Class DC.Evgenys.Data Extends %Persistent
{
/// which: 0=Fullname, 1=Schemaname, 2=Tablename
ClassMethod TableName(which = 0) [ CodeMode = objectgenerator ]
{
    set sch=%compiledclass.SqlSchemaName, tab=%compiledclass.SqlTableName
    do %code.WriteLine($c(9)_"quit $p("""_sch_"."_tab_","_sch_","_tab_""","","",which+1)")
    quit $$$OK
}
}

So you can do something like this:

for i=0:1:2 write ##class(DC.Evgenys.Data).TableName(i),!
DC_Evgenys.Data
DC_Evgenys
Data
Julius Kavay · Jan 28, 2022 go to post

You forgot to take into account the $system.SQL.* variants . They make much more fun, especially because you get time for a coffee break... devil

Julius Kavay · Jan 28, 2022 go to post
Class My.Class 
{
Property MyProperty As %String [ReadOnly];

Method %OnNew(init As %String) As %Status [ Private, ServerOnly = 1 ]
{
    set i%MyProperty = init
}
} 

And use it as

set obj = ##class(My.Class).%New("Some initial value")
write obj.MyProperty --> Some initial value
set obj.MyProperty --> <CANNOT SET THIS PROPERTY>
Julius Kavay · Jan 28, 2022 go to post

A possible work-around could be the class below. In short, you work with your json property as intended, merely before saving the object, you save the json-property into a stream and after opening an instance, you restore the json-property from the the stream - that's all. The drawback, no SQL over the json property...

Class DC.Dyn Extends %Persistent
{
Property json As %DynamicObject [ Transient ];
Property jstr As %GlobalCharacterStream [ Internal, Private ];

ClassMethod MyTest(kill = 0)
{
   if kill do ..%KillExtent(1,1)

   set obj=..%New()
   set obj.json.short="A short test text"
   set obj.json.maxstr=$tr($j("",$$$MaxStringLength)," ","X")
   do obj.json.%Set("hugedata",..stream(obj),"stream")

   write "Status : ",obj.%Save(),!
   set id=obj.%Id()
   write "ID : ",id,!
   kill (id)

   set obj=..%OpenId(id)
   write "short : ",obj.json.short,!
   write "maxstr : ",$e(obj.json.maxstr,1,20),"... Size: ",$length(obj.json.maxstr),!
   set stream=obj.json.%Get("hugedata",,"stream")
   write "hugedata: ",stream.Read(20),"... Size: ",stream.Size,!
}

ClassMethod stream(obj)
{
   set stream=##class(%Stream.TmpCharacter).%New()
   do stream.Write(obj.json.short)
   do stream.Write(obj.json.maxstr)
   do stream.Write(obj.json.maxstr)
   quit stream
}

Method %OnOpen() As %Status [ Private, ServerOnly = 1 ]
{
   if ..jstr {
      do ..jstr.Rewind()
      set ..json=##class(%DynamicAbstractObject).%FromJSON(..jstr)
   }
   Quit $$$OK
}

Method %OnAddToSaveSet(depth As %Integer = 3, insert As %Integer = 0, callcount As %Integer = 0) As %Status [ Private, ServerOnly = 1 ]
{
   do ..jstr.Clear(), ..json.%ToJSON(..jstr)
   Quit $$$OK
}
}

Some testing...

IDEV:USER>d ##class(DC.Dyn).MyTest(1)
Status  : 1
ID      : 1
short   : A short test text
maxstr  : XXXXXXXXXXXXXXXXXXXX... Size: 3641144
hugedata: A short test textXXX... Size: 7282305

If your code uses obj.%Reload() then %OnReload() and %OnOpen() should contain the same code.

Julius Kavay · Jan 27, 2022 go to post

Your solution is just perfect. And fast.

But yes, you can avoid string manipulations... This one, for example, uses math only, merely it's neither short nor looks elegant:

 set dt=$h write $zd(dt,8)*100+($p(dt,",",2)\3600)*100+($p(dt,",",2)#3600\60)*100+($p(dt,",",2)#60)

but gives the same result as your short and nice solution...

 set dt=$h write $zd(dt,8)*100+($p(dt,",",2)\3600)*100+($p(dt,",",2)#3600\60)*100+($p(dt,",",2)#60),!,$tr($zdt(dt,8)," :")

On the other hand, you can install new brakes on your car, as suggested by others... ;-))

Just compare those codes with yours:

set h=$h, t=$zh for i=1:1:1E6 { set x=$tr($system.SQL.TOCHAR($h,"YYYY^MM^DD^HH24^MI^SS"),"^") } write $zh-t,!

set h=$h, t=$zh for i=1:1:1E6 { set x=$tr($zdt(h,8)," :") } write $zh-t,!

The choice is yours...