go to post Vitaliy Serdtsev · May 11, 2022 (And I think you may be waiting a long time for the Encoder game to close) The author seems to have forgotten or this no longer relevant. I'm not interested in opening code when there are no alternatives and there is no competitive spirit.
go to post Vitaliy Serdtsev · May 11, 2022 size = 74 ClassMethod Detector( a As %String, b As %String) As %Boolean { q $$r(a)=$$r(b) r(x)f i=65:1:90{s $li(y,i)=$l($zcvt(x,"u"),$c(i))} q y } I'm not publishing the option with size = 73 yet, to wait, maybe someone will guess how to do it or offer an ever shorter option (by analogy with Code Golf - Encoder). UPD: I managed to reduce size to 72.
go to post Vitaliy Serdtsev · May 10, 2022 Example Class dc.golf.Anagram { ClassMethod Detector( a As %String, b As %String) As %Boolean { f c="a","b"{ s @c=$zstrip($zcvt(@c,"U"),"*W") } w $$$quote(a),":",$l(a)," - ",$$$quote(b),":",$l(b),! q $tr(a,b)=$tr(b,a)&($l(a)=$l(b)) } } Output (tested on IRIS 2021.2CE): USER>w ##class(dc.golf.Anagram).Detector("apple", "pale") <UNDEFINED>zDetector+2^dc.golf.Anagram.1 *a If I change Undefined, then there is no error, but the result is incorrect: USER>d $system.Process.Undefined(2) USER>w ##class(dc.golf.Anagram).Detector("apple", "pale") "apple":5 - "pale":4 0 The code works correctly if change the signature of the method (ProcedureBlock/PublicList/new), but this is a violation of the conditions of the task.
go to post Vitaliy Serdtsev · May 4, 2022 See %ZEN.Auxiliary.jsonSQLProvider:%WriteJSONStreamFromSQL() Simple example Class dc.test Extends %Persistent { Property int As %Integer; Property str As %VarString; Property bool As %Boolean; Property Date As %Date; ClassMethod Test() { d ..%KillExtent() &sql(insert into dc.test("int",str,bool,"Date") select 30,'Hello Caché',0,current_date union select 303,'ăîşţâ',1,0 union select null,null,null,null) s stream=##class(%Stream.FileBinary).%New(), stream.Filename="c:\temp\test.json", sql="select * from dc.test", format="twu", maxRows=0 s status=##class(%ZEN.Auxiliary.jsonSQLProvider).%WriteJSONStreamFromSQL(.stream, sql, format, maxRows) d:$$$ISOK(status) stream.%Save() } } The contents of the file test.json (UTF8): { "children":[ {"ID":1,"Date":"04.05.2022","bool":0,"int":30,"str":"Hello Caché"} ,{"ID":2,"Date":"31.12.1840","bool":1,"int":303,"str":"ăîşţâ"} ,{"ID":3,"Date":"","bool":"","int":"","str":""} ] }
go to post Vitaliy Serdtsev · May 3, 2022 In Ensemble 2014, which the author indicated in his question, there are no classes %Library.DynamicObject and %Library.DynamicArray
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);