go to post Vitaliy Serdtsev · May 3, 2022 My current result: size = 94 84 ClassMethod Detector( a As %String, b As %String) As %Boolean { s:$l(a)>$l(b) i=b,b=a,a=i f i=1:1:$l(a){s b=$replace(b,$e(a,i),"",,1,1)} q b?." " }
go to post Vitaliy Serdtsev · Apr 29, 2022 w $tr("123-45-6789","123456789","256128799"),! w $tr("123-45-6789","123456789","891445555"),!Output: 256-12-8799 891-44-5555 Based on: Yet another use case for $translate: date conversion
go to post Vitaliy Serdtsev · Apr 27, 2022 I already tried option 1 with Timeformat=1 for the avg and didn't work. Have you changed the TimeFormat at the process or system level? If at the process level, then most likely you have changed this value in one process, and are executing the query in another. Therefore, there is no effect. If at the system level, then the query should work. To avoid uncertainty, change the definition of the field Property PackingTimeSpent As %Time; and execute in SMP for Display Mode select PackingTimeSpent from MSDS_Serenity.KitlabelAssoc The hh:mm:ss format string should be displayed. so eg. select %external(CAST(+avg(166.38) as TIME)) didn't work for me Two remarks: this will work as intended only if you have changed the TimeFormat=1 at the system level avg(166.38) - it's pointless to write like that. you mentioned the example above and I'm not sure to which one are youi refering to with so many replies, so can you point me to which one exactly See Time-to-String Conversionlink Try this (does not depend on the TimeFormat value of the current locale): select TO_CHAR(avg(PackingTimeSpent),'HH24:MI:SS') average from MSDS_Serenity.KitlabelAssoc where label='00007IT4'PS: By the way, I noticed in your screenshots the differences in queries: somewhere you write where label='00007IT4'somewhere you write where ID='00007IT4' Is this how it should be? To avoid unnecessary questions, please do not change everytime the names of the fields in the queries. This is misleading.
go to post Vitaliy Serdtsev · Apr 27, 2022 If the data already exists, then this is a non-trivial task, especially if inheritance or Parent/Child is present, since this will lead to a change in the storage scheme of your data. The easiest way to do this is through an intermediate (temporary) table: create a new class with the same structure, but with a new primary key; move data from the old class into it using SQL (not the merge command); delete data/indexes in the old class, then change the primary key in it; move data from the new class to the old class, using the merge command; delete the new class with the data; rebuild the indexes if there are any. Useful links: MERGE Persistent Objects and InterSystems IRIS SQL Introduction to Persistent Objects If you feel insecure with Caché/IRIS, it is better to ask WRC for help.
go to post Vitaliy Serdtsev · Apr 27, 2022 From doc: AVG returns either NUMERIC data type values or DOUBLE data type values. If expression is data type DOUBLE, AVG returns DOUBLE; otherwise, it returns NUMERIC. For non-DOUBLE expression values, AVG returns a double-precision floating point number.proof The specification of the field [%Time(FORMAT=1)] plays absolutely no role in the case of an aggregate function, since AVG returns just a number (DOUBLE or NUMERIC). Above I gave links to examples of how a number can be converted to TIME, then to STRING. For example: if in the current locale TimeFormat = 1 select %external(CAST(+166.38 as TIME)) Important: it is necessary to convert a float number to an integer type, otherwise you will get zero. if in the current locale TimeFormat <> 1 select TO_CHAR(166.38,'HH24:MI:SS')
go to post Vitaliy Serdtsev · Apr 26, 2022 You have already been answered here: "Dealing with time format as string" PS: don't forget to mark the answer as an answer.
go to post Vitaliy Serdtsev · Apr 26, 2022 Try other methods/queries of this class, such as Dump*, ProcessList, ConnectionList, etc., which return the number of connections.
go to post Vitaliy Serdtsev · Apr 26, 2022 It is very strange that the mechanism ^%SYS("CSP", "MimeFileClassify") does not work for you. According to the sources of %CSP.StreamServer, it can be seen that all the work takes place in the FileClassify method, where ^%SYS("CSP", "MimeFileClassify") is also used. I used ZEN on Caché and all was fine. Can you give a simple CSP example to reproduce your situation?
go to post Vitaliy Serdtsev · Apr 26, 2022 Try this (%Dialect): Set sqlStatement=##class(%SQL.Statement).%New(,,"MSSQL") Simple example Class dc.test Extends %Persistent { Property t As %Integer; ClassMethod Test() { d ..%KillExtent() &sql(insert into dc.test(t) values(30)) &sql(insert into dc.test(t) values(303)) zw ^dc.testD w ! s sql=2 s sql(1)="update dc.test set t=t+1 where ID=1" s sql(2)="update dc.test set t=t+2 where ID=2" s st=##class(%SQL.Statement).%New(,,"MSSQL") w "SQLCODE=",st.%ExecDirect(.st,.sql).%SQLCODE,!! zw ^dc.testD } } Output: USER>d ##class(dc.test).Test() ^dc.testD=2 ^dc.testD(1)=$lb("",30) ^dc.testD(2)=$lb("",303) SQLCODE=0 ^dc.testD=2 ^dc.testD(1)=$lb("",31) ^dc.testD(2)=$lb("",305)
go to post Vitaliy Serdtsev · Apr 18, 2022 This may be useful to you: LogRollback Transactions and Savepoints Rolling Back Incomplete Transactions
go to post Vitaliy Serdtsev · Apr 13, 2022 As I wrote above, there are two ways to solve: change TimeFormat in the locale. Query in this case will be simple. See ##class(%SYS.NLS.Format).SetFormatItem, Configuring National Language Support (NLS). complicate query. See Time-to-String Conversion Which option do you choose?
go to post Vitaliy Serdtsev · Apr 13, 2022 Rochdi, please be attentive. Above I already led an example with AVG (see spoiler "Simple sample").
go to post Vitaliy Serdtsev · Apr 13, 2022 Most likely, your locale uses TimeFormat = 2 (see tformat) You can change your locale or explicitly specify the format of the field, for example like this: Property PackingTimeSpent As %Time(FORMAT = 1);
go to post Vitaliy Serdtsev · Apr 13, 2022 What locale are you using? I use "rusw". Try to do the following in SMP: update MSDS_Serenity.KitlabelAssoc set PackingTimeSpent=35000 where label='00007IT4'then select PackingTimeSpent, %internal(PackingTimeSpent) ptsLOGICAL, %external(PackingTimeSpent) ptsDISPLAY, %odbcout(PackingTimeSpent) ptsODBC from MSDS_Serenity.KitlabelAssoc where label='00007IT4'What are your results? I have the following displayed (for DISPLAY mode): PackingTimeSpent = 09:43:20 ptsLOGICAL = 35000 ptsDISPLAY = 09:43:20 ptsODBC = 09:43:20
go to post Vitaliy Serdtsev · Apr 13, 2022 Notes on Indices Defined in Classes When working with indices in class definitions, here are some points to keep in mind: • Index definitions are only inherited from the primary (first) superclass. • ... Simple sample Class dc.Aclass [ Abstract ] { Index idxF On f; Property f As %Integer; } Class dc.test Extends (dc.Aclass, %Persistent) [ ClassType = persistent ] { ClassMethod Test() { k ^dc.testD,^dc.testI &sql(insert into dc.test(f) values(30)) &sql(insert into dc.test(f) values(303)) zw ^dc.testD,^dc.testI } } Output: USER>d ##class(dc.test).Test() ^dc.testD=2 ^dc.testD(1)=$lb("",30) ^dc.testD(2)=$lb("",303) ^dc.testI("idxF",30,1)="" ^dc.testI("idxF",303,2)=""
go to post Vitaliy Serdtsev · Apr 13, 2022 having the field defined as integer would allow selecting avg but running a query in my Zen page wouldn’t show me a time format If you the field is defined as %Integer or %String, then this is incorrect. The field type must be %Time. In this case, a time will be stored in the database as number, and the query will display the time as a string. Here is a small example: select 166 seconds,%external(cast(+166.5 as TIME)) "avg" Output: seconds = 166 avg = 00:02:46 Simple sample Class dc.test Extends %Persistent { Property t As %Time; ClassMethod Test() { d ..%KillExtent() &sql(insert into dc.test(t) values(30)) &sql(insert into dc.test(t) values(303)) zw ^dc.testD w ! s st=##class(%SQL.Statement).%New() s st.%SelectMode=2 d st.%ExecDirect(.st,"select t, %internal(t) tINT, %external(t) tSTR, avg(t) average,CAST(+avg(t) as TIME) avgSTR from dc.test").%Display() ; or w !! d ##class(%SQL.Statement).%ExecDirect(,"select t, %internal(t) tINT, %external(t) tSTR, avg(t) average,%external(CAST(+avg(t) as TIME)) avgSTR from dc.test").%Display() } } Output: USER>d ##class(dc.test).Test() ^dc.testD=2 ^dc.testD(1)=$lb("",30) ^dc.testD(2)=$lb("",303) t tINT tSTR average avgSTR 00:00:30 30 00:00:30 166.5 00:02:46 00:05:03 303 00:05:03 166.5 00:02:46 2 Rows(s) Affected t tINT tSTR average avgSTR 30 30 00:00:30 166.5 00:02:46 303 303 00:05:03 166.5 00:02:46 2 Rows(s) Affected
go to post Vitaliy Serdtsev · Apr 12, 2022 By default, data in the global is stored as glbD(ID)=$LB(%%CLASSNAME,prop1,prop2,..,propN) The total size of the string cannot exceed 3641144. Therefore, if you have a field length >3.6E6, and there are several such fields, the limit is exceeded. To work around this, you need to change storage for your class. For example so: glbD(ID)=$LB(%%CLASSNAME) glbD(ID,"prop1")=prop1 glbD(ID,"prop2")=prop2 ... glbD(ID,"propN")=propN Simple example Class dc.test Extends %Persistent { Index mySimilarityIndex On SettingsJSON(KEYS) [ Data = SettingsJSON(ELEMENTS) ]; Index mySimilaritybackupIndex On SettingsJSONbackup(KEYS) [ Data = SettingsJSONbackup(ELEMENTS) ]; Property SettingsJSON As %Text(LANGUAGECLASS = "%Text.English", MAXLEN = 3600000, SIMILARITYINDEX = "mySimilarityIndex"); Property SettingsJSONbackup As %Text(LANGUAGECLASS = "%Text.English", MAXLEN = 3600000, SIMILARITYINDEX = "mySimilaritybackupIndex"); ClassMethod Test() { d ..%KillExtent() s json=$tr($j("",3600000)," ","0") &sql(insert into dc.test(SettingsJSON,SettingsJSONbackup) values(:json,:json)) w $l(json),":",SQLCODE } Storage Default { <Data name="backup"> <Attribute>SettingsJSONbackup</Attribute> <Structure>node</Structure> <Subscript>"SettingsJSONbackup"</Subscript> </Data> <Data name="json"> <Attribute>SettingsJSON</Attribute> <Structure>node</Structure> <Subscript>"SettingsJSON"</Subscript> </Data> <Data name="testDefaultData"> <Value name="1"> <Value>%%CLASSNAME</Value> </Value> </Data> <DataLocation>^dc.testD</DataLocation> <DefaultData>testDefaultData</DefaultData> <IdLocation>^dc.testD</IdLocation> <IndexLocation>^dc.testI</IndexLocation> <StreamLocation>^dc.testS</StreamLocation> <Type>%Library.CacheStorage</Type> } }