See my old article on my blog: Examples of generating and sending Email using the Caché DBMS (this is machine translation)
- Log in to post comments
See my old article on my blog: Examples of generating and sending Email using the Caché DBMS (this is machine translation)
ClassMethod testvalidator(
class As %String,
value As %String) As %Status
{
set validator = "(out){set out = ##class("class").IsValid("""value""")}"
xecute (validator,.sc)
write sc,!
quit sc
}Use $CLASSMETHOD and you won't have such issues:
USER>set sc=$CLASSMETHOD("%Numeric","IsValid","BLAH")
or
ClassMethod testvalidator(class As %String, value As %String) As %Status
{
set sc=$CLASSMETHOD(class,"IsValid",value)
write sc,!
quit sc
}Set object = ##class(%ZEN.proxyObject).%New() set object.city = "New York" set object.Target = "TEST" set object.Details = "TEST" set object.RefCode = "123" set object.Reason = "123TTTT" set string=object.%Serialize() ;write string,! set anotherObj=##class(%ZEN.proxyObject).%New() do anotherObj.%ZENDeserialize(string) write anotherObj.Reason ; ==> 123TTTT
codemode = code:
ClassMethod AddWater(
s,
t = {$lb("",1,22,333,4444,55555,666666,7777777,88888888,999999999)},
r = "") As %String
{
f i=1:1:$l(s) s r=r_$li(t,$e(s,i)+1)
q r
}codemode = expression:
ClassMethod AddWater(
s,
r = {"" s r="" f i=1:1:$l(s) s t=$e(s,i) s:t r=r_$tr($j(t,t)," ",t)}) As %String [ CodeMode = expression ]
{
r
}Required mapping ISCDC.inc from CACHESYS:
Include ISCDC
Class dc.test [ Abstract ]
{
ClassMethod AddWater(s) As %String
{
f i=$l(s):-1:1 s t=$e(s,i),$e(s,i)=$$DC(t,t)
q s
}
}For more details, see the documentation on Caché, for example: Namespace tab of the Studio Workspace window (and not Project tab)
And more (see screenshot)
Installing a Development Environment
Using Studio (Class Browser)
Those experienced with encryption systems for databases may have concerns about encryption having dire effects on performance, but, with Caché, these concerns are unfounded. Encryption and decryption have been optimized, and their effects are both deterministic and small for any Caché platform; in fact, there is no added time at all for writing to the database.
InterSystems recommends using its encryption management tools:About Encryption Management Operations
- When built-in hardware instructions are available for encryption-related activities, these activities are considerably faster then when using software-based encryption. The encryption management tools use hardware instructions when they are available.
- The encryption management tools can use keys stored on a KMIP server.
- The encryption management tools can run in FIPS mode.
High-Performance Encryption for Databases in Financial Services (PDF)
But in new Native API for IRIS there are no proxies, just class methods/functions are called from app and I think, it should be pretty the same as calling this methods/functions from terminal window.
Introduction to the Native APIUsing .NET Reverse Proxy Objects
The Native API allows you to create instances of ObjectScript classes on InterSystems IRIS and generate Object Gateway proxy objects for them at runtime. Your .NET application can use proxies to work with ObjectScript objects as easily as if they were native .NET objects.
Yes, most likely this is a feature of the API. Here's what I found about it in the "old" documentation:
In some situations, caching may not be desirable. For example, if an object is opened with Concurrency Level 4 (Exclusive Lock), the lock will not be released until the next server call. To destroy the object immediately, you can call Close() with the optional useCache parameter set to false
PS: by the way, for ActiveX, Factory.ForceSync() method serves the same purpose.
I did a test and that's what found out.
It is assumed that the data has already been generated.
COS
Class dc.test Extends %Persistent
{
ClassMethod Checking(CardNo As %String) As %String
{
s tmp=..%OpenId(CardNo,4)
q "test"
}
}If executed from the terminal, the lock is removed automatically immediately after the method is completed:
USER>w ##class(dc.test).Checking("1")
testC#
// ...
string json = iris.ClassMethodString("dc.test", "Checking", "1");
// here the lock is still present
db.ReleaseIRISObjects(); // or iris.ReleaseAllLocks();
// here already more is no lockExample:
IRISConnection db; IRIS iris; IRISObject person; // ... using (person = (IRISObject)iris.ClassMethodObject("Sample.Person", "%OpenId", "1", "4")) { } /* or person = (IRISObject)iris.ClassMethodObject("Sample.Person", "%OpenId", "1", "4") person.Dispose(); person = null; */ db.ReleaseIRISObjects();
And if so?
ClassMethod TestLock() As %Status
{
New id,obj
Set id = $Order(^ZUser.NewClass1D(""))
If id = "" {
Set obj = ##class(ZUser.NewClass1).%New()
Do obj.%Save()
}
Set id = $Order(^ZUser.NewClass1D(""))
Set obj = ##class(ZUser.NewClass1).%OpenId(id, 4)
; in case of usage Not ProcedureBlock you should
; kill obj or set obj="" (and all others variables with this object reference) to release the lock
Return $$$OK
}COS:
Class dc.DPasarela Extends %RegisteredObject
{
Property STREAM As %Stream.TmpBinary;
Method PostMsg()
{
s s=$tr($j("",$$$MaxStringLength)," ",$c(0))
f i=1:1:5 d ..STREAM.Write(s)
}
}C#
IRISObject STREAM;
MemoryStream stream = new MemoryStream();
string len1, len2;
IRISObject pasarela = (IRISObject)iris.ClassMethodObject("dc.DPasarela", "%New");
pasarela.InvokeVoid("PostMsg");
STREAM = (IRISObject) pasarela.Get("STREAM");
while (!Convert.ToBoolean(STREAM.GetBool("AtEnd")))
{
stream.Write(STREAM.InvokeBytes("Read", 3641144),0, 3641144);
}
len1 = STREAM.GetString("Size"); // 18205720 (3641144*5)
len2 = stream.Length.ToString(); // 18205720 (3641144*5)
// =========== AGAIN ===========
STREAM.InvokeVoid("MoveToEnd");
pasarela.InvokeVoid("PostMsg");
stream.SetLength(0);
while (!Convert.ToBoolean(STREAM.GetBool("AtEnd")))
{
stream.Write(STREAM.InvokeBytes("Read", 3641144), 0, 3641144);
}
len1 = STREAM.GetString("Size"); // 36411440 (18205720*2)
len2 = stream.Length.ToString(); // 36411440 (18205720*2)
byte[] bytesS = stream.ToArray();COS:
Class dc.DPasarela Extends %RegisteredObject
{
Property Value As %Numeric;
Property Title As %String;
Property Message As %String;
Property STREAM As %Stream.TmpCharacter;
Method PostMsg(
SessionId As %String,
Msg As %String,
bytesS As %Binary,
STREAMin As %Stream.TmpCharacter,
Output STREAMout As %Stream.TmpCharacter)
{
set ..Value = 5,
..Title = SessionId,
..Message = Msg_" "_bytesS
do:$IsObject(STREAMin) ..STREAM.CopyFrom(STREAMin)
set STREAMout=##class(%Stream.TmpCharacter).%New()
do STREAMout.Write("bla-bla-bla")
}
}C#:
IRISObject pasarela = (IRISObject)iris.ClassMethodObject("dc.DPasarela", "%New");
byte[] bytesS = new byte[3]; // In real world this is a BASE64 encoded JSON
bytesS[0] = 233; // é
bytesS[1] = 234; // ê
bytesS[2] = 59; // ;
IRISReference refSTREAMout = new IRISReference(null);
IRISObject STREAMin = (IRISObject)iris.ClassMethodObject("%Stream.TmpCharacter", "%New");
STREAMin.InvokeString("Write","blablabla");
pasarela.InvokeVoid("PostMsg", "aSession", "aMsg", bytesS, STREAMin, refSTREAMout);
int aValue = Convert.ToInt32(pasarela.GetLong("Value")); // 5
string aTitle = pasarela.GetString("Title"); // aSession
string aMessage = pasarela.GetString("Message"); // aMsg éê;
string aSTREAMout = ((IRISObject)refSTREAMout.value).InvokeString("Read"); // bla-bla-bla
string aSTREAM = ((IRISObject)pasarela.GetObject("STREAM")).InvokeString("Read"); // blablablaSee %SYS.GlobalQuery_NameSpaceList().
Example:
select Name,Location from %SYS.GlobalQuery_NameSpaceList(,'*',0,,,1,1)
select Name,Location from %SYS.GlobalQuery_NameSpaceList('SAMPLES','*',0,,,1,1)and second, I would like to read the doc everywhere! For example, I have a 10 hour flight, and want to work. And in case, a server only has a local LAN access, then you have no docu!).I fully support it. But I'm afraid now, apart from reading the documentation in PDF format, you can forget about local documentation ("DOCBOOK" database) with normal search and navigation. It's a pity..
No. I couldn't find how to do this in the documentation (probably I searched badly), so I don't publish here undocumented features anymore. But you can easily determine this from the source code.
Yes. By default, a strictly defined list of packages/classes is displayed in IRIS for security purposes, but you can change this behavior locally.
Or so:
set tmp = ##class(%IO.StringStream).%New()
do tmp.Write("This is my text")
do tmp.Seek(11)
do tmp.Write(" NEW")
do tmp.Rewind()
write tmp.Read(tmp.Size) ;This is my NEW textSee %SQL.StatementResult:%DisplayFormatted()
Simple sample (for namespace "SAMPLES"):
set st = ##class(%SQL.Statement).%New(2,"Sample")
set sql = 3
set sql(1) = "select TOP 5 %ID as id, Name, DOB, Home_State"
set sql(2) = "from Person where Age > 40"
set sql(3) = "order by 2"
do st.%Prepare(.sql)
for type="txt","pdf","csv","html","xml" {
set rs = st.%Execute()
do rs.%DisplayFormatted(type,"C:\Temp\report")
}As a result, the following files are generated:
report.csv report.html report.pdf report.txt report.xml
Instead of
set str=$e(str,1,*-1)
, will be a little faster
set $e(str,*)=""
But this is already saving on matches.
PS: for the sake of interest, I checked on a special version of Caché (very old) with server-side JavaScript (not to be confused with Node.js)
Source code
Include %occInclude
Class dc.test [ Abstract ]
{
ClassMethod MakeStringOnJS(N) [ Language = javascript]
{
var myval="a", arr=[], stop, str, start=(new Date()).getTime();
for (var i=0;i<N;i++) arr[i]=myval;
str=arr.join();
stop=(new Date()).getTime();
Cache.Console.WriteLine("[JavaScript] execution: ",stop-start,"(ms) len(str): ",str.length);
// Force a Garbage Collection
Cache.Class.$JavaScript_Runtime.$GarbageCollect();
}
ClassMethod MakeStringOnCOS(N)
{
s myval="a",
str="",
time=$zh
f i=1:1:N s str=str_myval_","
s $e(str,$l(str))="" ; not supported $e(str,*)
w $$$FormatText("[COS] execution: %1(ms) len(str): %2",$zh-time*1000,$l(str)),!
}
/// d ##class(dc.test).Test()
ClassMethod Test(N = 10)
{
d ..MakeStringOnJS(N),
..MakeStringOnCOS(N)
}
}USER>d ##class(dc.test).Test(1800000) [JavaScript] execution: 99(ms) len(str): 3599999 [COS] execution: 126.683(ms) len(str): 3599999
By the way, the JS code has almost no limit on the string size.
An example without complex formulas and very fast
Include %DeepSee
Class dc.test [ Abstract ]
{
ClassMethod FirstLastDayMonth(
year = 2015,
month = 2)
{
s mm=$$$iscPadZero(month,2),
firstDay=$zdh(year_mm_"01",8),
lastDay=$zdh(year_mm_$$$iscDaysInMonth(year,month),8),
firstDayName=$zd(firstDay,12,,,,,,,,1),
lastDayName=$zd(lastDay,12,,,,,,,,1)
w $$$FormatText("firstDay = %1 (%2), lastDay = %3 (%4)",$zd(firstDay),firstDayName,$zd(lastDay),lastDayName),!
}
/// d ##class(dc.test).Test()
ClassMethod Test()
{
d ..FirstLastDayMonth(2015,2),
..FirstLastDayMonth(2021,9)
}
}USER>d ##class(dc.test).Test()
firstDay = 01.02.2015 (Sunday), lastDay = 28.02.2015 (Saturday)
firstDay = 01.09.2021 (Wednesday), lastDay = 30.09.2021 (Thursday)
See %SYSTEM.SQL (LASTDAY, DAYOFMONTH, etc.)
Did you look in the direction of %Stream.GlobalCharacterSearchable?
See also Scalar Functions and Streams
SELECT Notes Stream,DATALENGTH(Notes) lenStream,SUBSTRING(Notes,DATALENGTH(Notes)-9) AS StreamLast10Chars FROM Sample.Employee WHERE Notes IS NOT NULL
Simple sample:
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,'Western branch' Branch,{d '2021-03-15'} "Date",35 Suma
union
select 2,'Eastern branch',{d '2020-12-11'},37"
/>
<button caption="Row unselect" onclick="zenPage.rowUnselect()"/>
</page>
}
ClientMethod rowUnselect() [ Language = javascript ]
{
var tp=zen('tp');
row=tp.selectedIndex;
if (tp.rowSelect && row>=0) {
var old=tp.enableToggleSelect;
tp.enableToggleSelect=true;
tp.selectRow(row);
tp.enableToggleSelect=old;
}
}
}I also will insert my five kopecks.
The %Library package also includes stream classes, but those are deprecated. The class library includes additional stream classes, but those are not intended for general use. Working with Streams
I have %Stream.FileCharacter was an order of magnitude faster than %[Library.]File
Sample
Class dc.test [ Abstract ]
{
ClassMethod ReadCSVStream(fCSV As %String) As %String
{
s stream = ##class(%Stream.FileCharacter).%New()
d stream.LinkToFile(fCSV)
s time1=$zh
While 'stream.AtEnd {
s line=stream.ReadLine($$$MaxLocalLength)
}
s diff=$zh-time1
q diff
}
ClassMethod ReadCSVStreamBlock(fCSV As %String) As %String
{
s stream = ##class(%Stream.FileCharacter).%New()
d stream.LinkToFile(fCSV)
s i=0,time1=$zh
While 'stream.AtEnd {
s chunks($i(i))=stream.Read($$$MaxLocalLength)
// do parsing chunk to lines
}
s diff=$zh-time1
q diff
}
ClassMethod ReadCSVOURC(fCSV As %String) As %String
{
o fCSV::1
e q "Missing File"
s eof=$zu(68,40,1)
u fCSV
s time1=$zh
f {
r line
q:$zeof
// do something with line
}
s diff=$zh-time1
c fCSV
d $zu(68,40,eof)
q diff
}
/// d ##class(dc.test).Test()
ClassMethod Test()
{
s ptr=0,
clnm=$classname()
&sql(select %dlist(Name) into :list
from %Dictionary.CompiledMethod
where Parent=:clnm and Name %startswith 'ReadCSV'
group by Parent
order by SequenceNumber)
while $listnext(list,ptr,m) {
w !,"[",m,"]",?20,"execution: ",$classmethod(clnm,m,"data.csv"),!
}
}
}Who do you think in the article above was faster when reading 1e7+ lines: Fortran or C++ ?
Addition to the above: Speedup SQL pagination