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):

Class fixxer.decars Extends %Persistent DdlAllowedSqlRowIdName UniqueIdentifier ]
{

Index iUnq On (brand, MaxSpeed, color) [ IdKeyPrimaryKeyUnique ];
Property brand [ SqlColumnNumber = 2 ];
Property MaxSpeed;
Property color;

}
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:

Class fixxer.decars Extends %Persistent DdlAllowedSqlRowIdName UniqueIdentifier ]
{

Index iUnq On (brand, MaxSpeed, color) [ IdKeyPrimaryKeyUnique ];
Property brand [ SqlColumnNumber = 2 ];
Property MaxSpeed;
Property color [ SqlFieldName COLOR2 ];

}

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

$$TableName^%occLGUtil(pClass) (taken from sources %DeepSee.Report.Model.Report)
##class(%DeepSee.Utils).%GetSQLTableName(pClass)
##class(%ZEN.DataModelUtils).GetSQLTableName(pClass)
##class(%DeepSee.Generator).%GetSQLTableName(pClass) (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é:

Class count.sum.select Extends %Persistent SqlTableName "current_date.max" ]
{

ClassMethod TableName(which 0) [ CodeMode = objectgenerator ]
{
  set sch=%compiledclass.SqlSchemaNametab=%compiledclass.SqlTableName
  do %code.WriteLine($c(9)_"quit $p("""_sch_"."_tab_","_sch_","_tab_""","","",which+1)")
  quit $$$OK
}

/// d ##class(count.sum.select).Test()
ClassMethod Test()
{
  i=0:1:2 ..TableName(i),!

  pClass=$classname()
  !,##class(%DeepSee.Generator).%GetSQLTableName(pClass),!

  w $$TableName^%occLGUtil(pClass),!
  ##class(%DeepSee.Utils).%GetSQLTableName(pClass),!
  ##class(%ZEN.DataModelUtils).GetSQLTableName(pClass),!
}

}

USER>##class(count.sum.select).Test()
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()]:

select * from %SYS.GlobalQuery_Size('C:\InterSystems\Cache\mgr\samples','','*D,*S',0,0,1) order by "Allocated MB" desc
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>w $$Export^%qarDDLExport("Sample","*","C:\Temp\Sample.sql","WNS",1,0,0,0,0)
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:

<..> select a->b->c->into :r from table where %ID=:id <..>

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:

path="C:\Temp"

pExtension=1
pExtension(1)="*"

pTempNode=$i(^CacheTemp)
^CacheTemp(pTempNode)
   
##class(%SQL.Util.Import).getFiles(path,.pExtension,pTempNode,1)
dirlist=^CacheTemp(pTempNode)
^CacheTemp(pTempNode)

zw dirlist
Vitaliy Serdtsev · Nov 19, 2021 go to post

It's okay, I already have a minus.
It looks like this is my last comment here.

UPD:

  w $$Iso8601ToTimeStamp("2021-10-22T08:00:00+0900"),!
  w $$Iso8601ToTimeStamp("2021-11-04T11:10:00+0100"),!
  w $$Iso8601ToTimeStamp("2021-11-04T11:10:00+0200"),!
  w $$Iso8601ToTimeStamp("2021-11-04T11:10:00-0140"),!

Iso8601ToTimeStamp(ts) {
  r=##class(%TimeStamp).XSDToLogical($e(ts,1,22)_":"_$e(ts,*-1,*))
  r," => "
  q $zdth(r,3)
 }

Output:

USER>do ^test
2021-10-21 23:00:00 => 66038,82800
2021-11-04 10:10:00 => 66052,36600
2021-11-04 09:10:00 => 66052,33000
2021-11-04 12:50:00 => 66052,46200
Vitaliy Serdtsev · Nov 4, 2021 go to post

I know, that's why I gave a link to the documentation so that the author would do the rest of the work himself, since ISO 8601 has many forms.

Here is another variant of the ISO8601ToDateTime method.

Vitaliy Serdtsev · Nov 3, 2021 go to post

In this case, you can do this:

SELECT %TSQL.ZRAND(%ID+1e16) rnd,
IDCitizenshipDOBFirstNameGenderIDNumberLastNamePatientNumberPhoneNumber
FROM CDR.Patient

Type of rnd - DOUBLE.
Of course, you can convert it to NUMERIC or STRING

Vitaliy Serdtsev · Nov 3, 2021 go to post

For debugging purposes and further query optimization, why not?

I have a legacy code that I need to optimize.

Vitaliy Serdtsev · Nov 3, 2021 go to post

Try calling the ClearBuffers in the GLOBUFF system routine, e.g.:

USER>ClearBuffers^|"%SYS"|GLOBUFF()
Removed 65303 blocks
Vitaliy Serdtsev · Nov 3, 2021 go to post

Try Built-in Modal Groups

E.g.:

Class dc.test Extends %ZEN.Component.page
{

XData Contents [ XMLNamespace "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen">
  <tablePane id="tp" sql="select 1 id, '2021-11-03' DT union select 2, '2022-01-24'">
    <column colName="id"/>
    <column colName="DT" link="javascript:zenPage.modalGroupCalendar('#(%query.DT)#');"/>
  </tablePane>
</page>
}

ClientMethod modalGroupCalendar(val) [ Language = javascript ]
{
  var group zenPage.createComponent('modalGroup');
  group.setProperty('onaction','zenPage.calendarAction(group);');
  group.show('Select a date:','calendar',val);
}

ClientMethod calendarAction(group) [ Language = javascript ]
{
  alert("You selected: " group.getValue());
  // SaveOnServer(); !
}

}
Vitaliy Serdtsev · Nov 3, 2021 go to post

Try this:

Class dc.test Extends %ZEN.Component.page
{

XData Contents [ XMLNamespace "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen">
  <tablePane id="tp" sql="select 1 id, 'a' FollowUp union select 2,'b'">
    <column colName="id"/>
    <column colName="FollowUp" header="FollowUp Comments" width="9%" style="text-align:left;" OnDrawCell="txtFollowUp"/>
  </tablePane>
</page>
}

Method txtFollowUp(
  pTable As %ZEN.Component.tablePane,
  pName As %String,
  pSeed As %StringAs %Status
{
    &html<<textarea name="followup" rows="3" style=" width: 95%;" onchange="zenPage.saveFollowUp(this.value,#(%query("id"))#);">#(%query(pName))#</textarea>>
    Quit $$$OK
}

ClientMethod saveFollowUp(
  val,
  id) [ Language = javascript ]
{
  zenAlert(val,' <-> ',id);
}

}
Vitaliy Serdtsev · Nov 3, 2021 go to post

This functionality is available when working with ActiveX (however, ActiveX is not recommended for use in new applications):

PS: in the Caché distribution there was even a special library DelphiCallback.dll for Delphi, an example of working with which is in my blog.