Vitaliy Serdtsev · Feb 3, 2022 go to post

So, the author is not lucky and in its version this feature is not available. It seems you have the wrong addressee, I have 2021.2 :)

Vitaliy Serdtsev · Feb 3, 2022 go to post

I won't be able to check for version 2020.1 since I have 2021.2.

Try to make a DROP COLUMN and then ADD COLUMN (of course according to the documentation for your version)

Vitaliy Serdtsev · Feb 3, 2022 go to post

After calling

alter table fixxer.decars alter column color rename color2
it became
<FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">color </FONT><FONT COLOR="#000080">As %Library.String</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">MAXLEN </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#000080">500</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#000080">SqlColumnNumber </FONT><FONT COLOR="#000000">= 5, </FONT><FONT COLOR="#000080">SqlFieldName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">COLOR2 </FONT><FONT COLOR="#000000">];</FONT>
It looks like something was fixed in 2021.2.
Vitaliy Serdtsev · Feb 3, 2022 go to post

Good trick!

size = 47

ClassMethod Solve2(As %StringAs %Integer
{
c=$p(o,",",$i(i)) g:$lf($lfs(o),-cc
}
Vitaliy Serdtsev · Feb 3, 2022 go to post

I have 190 on 1 line.

UPD: Program can be reduced to 189, but at the same time efficiency will decrease. Therefore, I will stop on the value 190. Let us know when the contest ends and it will be possible to open the sources.

Vitaliy Serdtsev · Feb 3, 2022 go to post

It is a pity that the author left the previous task (Code Golf - Encoder) without attention, and the community ignored her (or did not notice;)

Vitaliy Serdtsev · Feb 3, 2022 go to post

size = 49

ClassMethod Solve(As %StringAs %Integer
{
 i=1:1 c=$p(o,",",iret:'$lf($lfs(o),-cc
}
Vitaliy Serdtsev · Feb 3, 2022 go to post

Given (IRIS 2021.2):

<FONT COLOR="#000080">Class fixxer.decars Extends %Persistent </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">DdlAllowed</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">SqlRowIdName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">UniqueIdentifier </FONT><FONT COLOR="#000000">]
{

</FONT><FONT COLOR="#000080">Index </FONT><FONT COLOR="#000000">iUnq On (brand, MaxSpeed, color) [ </FONT><FONT COLOR="#000080">IdKey</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">PrimaryKey</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">Unique </FONT><FONT COLOR="#000000">]; </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">brand [ </FONT><FONT COLOR="#000080">SqlColumnNumber </FONT><FONT COLOR="#000000">= 2 ]; </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">MaxSpeed; </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">color;

}</FONT>

USER>d $system.SQL.Shell()
SQL Command Line Shell
----------------------------------------------------
 
The command prefix is currently set to: <>.
Enter , 'q' to quit, '?' for help.
[SQL]USER>>select * from fixxer.decars
1.      select * from fixxer.decars
 
UniqueIdentifier        brand   MaxSpeed        color
 
0 Rows(s) Affected
statement prepare time(s)/globals/cmds/disk: 0.0020s/5/140/0ms
          execute time(s)/globals/cmds/disk: 0.0004s/1/719/0ms
                          cached query class: %sqlcq.TEST.cls4
---------------------------------------------------------------------------
[SQL]USER>>alter table fixxer.decars alter column color rename color2
2.      alter table fixxer.decars alter column color rename color2
 
0 Rows Affected
statement prepare time(s)/globals/cmds/disk: 0.0153s/2 113/13 157/0ms
          execute time(s)/globals/cmds/disk: 0.1492s/52 206/467 790/0ms
                          cached query class: %sqlcq.TEST.cls5
---------------------------------------------------------------------------
[SQL]USER>>select * from fixxer.decars
3.      select * from fixxer.decars
 
UniqueIdentifier        brand   MaxSpeed        COLOR2
 
0 Rows(s) Affected
statement prepare time(s)/globals/cmds/disk: 0.0741s/38 529/179 560/0ms
          execute time(s)/globals/cmds/disk: 0.0003s/1/719/0ms
                          cached query class: %sqlcq.TEST.cls4
---------------------------------------------------------------------------
[SQL]USER>>

Now:

<FONT COLOR="#000080">Class fixxer.decars Extends %Persistent </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">DdlAllowed</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">SqlRowIdName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">UniqueIdentifier </FONT><FONT COLOR="#000000">]
{

</FONT><FONT COLOR="#000080">Index </FONT><FONT COLOR="#000000">iUnq On (brand, MaxSpeed, color) [ </FONT><FONT COLOR="#000080">IdKey</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">PrimaryKey</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">Unique </FONT><FONT COLOR="#000000">]; </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">brand [ </FONT><FONT COLOR="#000080">SqlColumnNumber </FONT><FONT COLOR="#000000">= 2 ]; </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">MaxSpeed; </FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">color [ </FONT><FONT COLOR="#000080">SqlFieldName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">COLOR2 </FONT><FONT COLOR="#000000">];

}</FONT>

PS: by the way Studio highlights the error in the following code

&sql(alter table fixxer.decars alter column color rename color2)

But the compilation goes without errors.

Vitaliy Serdtsev · Feb 1, 2022 go to post

See

<FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">TableName</FONT><FONT COLOR="#000000">^%occLGUtil(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">)</FONT> (taken from sources %DeepSee.Report.Model.Report)
<FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%DeepSee.Utils</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%GetSQLTableName</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">)</FONT>
<FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%ZEN.DataModelUtils</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">GetSQLTableName</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">)</FONT>
<FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%DeepSee.Generator</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%GetSQLTableName</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">)</FONT> (my choice)

It is worth remembering that the table name can be a reserved word, so you need to put it in quotation marks.

For example, the method %DeepSee.Generator:%GetSQLTableName does not always work correctly for Caché:

<FONT COLOR="#000080">Class count.sum.select Extends %Persistent </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">SqlTableName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">"current_date.max" </FONT><FONT COLOR="#000000">]
{

</FONT><FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">TableName(</FONT><FONT COLOR="#ff00ff">which </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#000080">0</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#000080">CodeMode </FONT><FONT COLOR="#000000">= objectgenerator ] {   </FONT><FONT COLOR="#0000ff">set </FONT><FONT COLOR="#800000">sch</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">%compiledclass</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">SqlSchemaName</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">tab</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">%compiledclass</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">SqlTableName   do </FONT><FONT COLOR="#800000">%code</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">WriteLine</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(9)</FONT><FONT COLOR="#008000">"quit $p("""</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">sch</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#008000">"."</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">tab</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">sch</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">tab</FONT><FONT COLOR="#000000">_</FONT><FONT COLOR="#008000">""","","",which+1)"</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">quit $$$OK </FONT><FONT COLOR="#000000">}

</FONT><FONT COLOR="#000080">/// d ##class(count.sum.select).Test() ClassMethod </FONT><FONT COLOR="#000000">Test() {   </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=0:1:2 </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">TableName</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">),!

  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$classname</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">!,</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%DeepSee.Generator</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%GetSQLTableName</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">),!

  </FONT><FONT COLOR="#0000ff">w $$</FONT><FONT COLOR="#ff0000">TableName</FONT><FONT COLOR="#000000">^%occLGUtil(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">),!   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%DeepSee.Utils</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%GetSQLTableName</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">),!   </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%ZEN.DataModelUtils</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">GetSQLTableName</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pClass</FONT><FONT COLOR="#000000">),! }

}</FONT>

USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">count.sum.select</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Test</FONT><FONT COLOR="#000000">()</FONT> count_sum.current_date.max count_sum current_date.max

count_sum."current_date" ERROR! count_sum.current_date.max count_sum.current_date.max count_sum.current_date.max

In IRIS 2021.2, an error occurs yet at the compilation stage of the class.
Vitaliy Serdtsev · Jan 27, 2022 go to post

In Caché 2018.1, which the author indicated, there is no such function. In addition, instead of HH need to specify HH24, otherwise instead of 20220126155704 will get 20220126035704.

Vitaliy Serdtsev · Jan 27, 2022 go to post
I would like to avoid string manipulation
Delimiters in the format are required, so you will have to manipulate the strings anyway.
$tr($system.SQL.TOCHAR($h,"YYYYMMDD HH24 MI SS")," ","")
or
$tr($system.SQL.TOCHAR($h,"YYYY^MM^DD^HH24^MI^SS"),"^","")
Vitaliy Serdtsev · Dec 8, 2021 go to post

Ok, the index can be omitted. The table data is stored in different globals: *D - for data, *I - for indexes, *S - for streams. You can get the size of the data parts you want.

Example [Size()]:

<FONT COLOR="#0000ff">select </FONT><FONT COLOR="#000080">* from </FONT><FONT COLOR="#008000">%SYS</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">GlobalQuery_Size</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'C:\InterSystems\Cache\mgr\samples'</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008080">''</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008080">'*D,*S'</FONT><FONT COLOR="#000000">,0,0,1) </FONT><FONT COLOR="#000080">order by </FONT><FONT COLOR="#008000">"Allocated MB" </FONT><FONT COLOR="#000080">desc</FONT>
Vitaliy Serdtsev · Dec 8, 2021 go to post

See the sources of method %SYSTEM.SQL:Export() for a description of the parameters.

Only instead of 0, use 1, for example:

SAMPLES><FONT COLOR="#0000ff">w $$</FONT><FONT COLOR="#ff0000">Export</FONT><FONT COLOR="#000000">^%qarDDLExport(</FONT><FONT COLOR="#008000">"Sample"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"*"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"C:\Temp\Sample.sql"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"WNS"</FONT><FONT COLOR="#000000">,1,0,0,0,0)</FONT>
Vitaliy Serdtsev · Dec 7, 2021 go to post

Try the following:

  1. enable "Retain cached query source" as described above
  2. compile your class/project with addition flags "k /compileembedded=1" (see Validating Embedded SQL Code)
  3. open the code of the generated program from the Studio or System Portal like %sqlcq.[YOURNAMESPACE].xETs3uMe2Ehn2LY5inuZiK4xgwnS.1.int
  4. Note: at the same time, do not forget to specify checkbox for system items
  5. Profit!
Vitaliy Serdtsev · Dec 6, 2021 go to post

That's what I expected to see.

But need remember that

This method is only available for stored properties.
In other words, if the storage changes tomorrow, will have to rewrite a bunch of code.
Vitaliy Serdtsev · Dec 6, 2021 go to post

I meant the length of the code.

I can write like this:

<..> <FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">a</FONT><FONT COLOR="#000000">-></FONT><FONT COLOR="#008000">b</FONT><FONT COLOR="#000000">-></FONT><FONT COLOR="#008000">c</FONT><FONT COLOR="#000000">-></FONT><FONT COLOR="#008000">d </FONT><FONT COLOR="#000080">into </FONT><FONT COLOR="#800000">:r </FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">table </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">%ID</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">:id</FONT> <..>

Can you give a complete code example for a->b->c->d using GetStored?

Vitaliy Serdtsev · Dec 3, 2021 go to post

See this.

Note: For Caché, there will be a "\Intersystems\Cache" instead of "\Intersystems\IRIS". Also note that for the 32-bit version, the paths in the registry will be slightly different from those specified in the example.

Vitaliy Serdtsev · Dec 3, 2021 go to post
  1. stop IRIS
  2. close IRIS Launcher (aka Cube)
  3. open regedit (run as Administrator)
  4. rename instance name (let's say "ABC")
    1. [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Intersystems\IRIS\Configurations\ABC]
    2. [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Intersystems\IRIS\Configurations\ABC\Manager\PreferredServer] @="ABC"
  5. run IRIS Launcher (aka Cube) and rename server names. If you want, you can also do this through the registry:
    1. [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Intersystems\CACHE\Servers\ABC]
    2. [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Intersystems\CACHE\Servers] "DefaultServer"="ABC"
  6. start IRIS
  7. Profit! Now the instance name is ABC.
Vitaliy Serdtsev · Dec 3, 2021 go to post

Another option 

/// This sample persistent class represents an employee.<br>
Class Sample.Employee Extends Person
{

...

/// The company this employee works for.
Relationship Company As Company Cardinality = one, Inverse = Employees ];
Property Cname As %String CalculatedSqlComputeCode = {id,id={%%ID} &sql(select Company->Name into :r from Sample.Employee where %ID=:id{*}=r}, SqlComputed ];

...
}
Vitaliy Serdtsev · Nov 23, 2021 go to post

There is a ready-made method for this: getFileslink

Usage example:

<FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">path</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"C:\Temp"

</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">pExtension</FONT><FONT COLOR="#000000">=1 </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">pExtension</FONT><FONT COLOR="#000000">(1)=</FONT><FONT COLOR="#008000">"*"

</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">pTempNode</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$i</FONT><FONT COLOR="#000000">(^CacheTemp) </FONT><FONT COLOR="#0000ff">k </FONT><FONT COLOR="#000000">^CacheTemp(</FONT><FONT COLOR="#800000">pTempNode</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%SQL.Util.Import</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">getFiles</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">path</FONT><FONT COLOR="#000000">,.</FONT><FONT COLOR="#800000">pExtension</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">pTempNode</FONT><FONT COLOR="#000000">,1) </FONT><FONT COLOR="#0000ff">m </FONT><FONT COLOR="#800000">dirlist</FONT><FONT COLOR="#000000">=^CacheTemp(</FONT><FONT COLOR="#800000">pTempNode</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#0000ff">k </FONT><FONT COLOR="#000000">^CacheTemp(</FONT><FONT COLOR="#800000">pTempNode</FONT><FONT COLOR="#000000">)

</FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#800000">dirlist</FONT>