%session.Data with unlimited amount of indexes
Let's imagine you have to implement a method with a definition
/// Set value to %session.Data ClassMethod setValue(params...) As %Status { }
How it should work
do ..setValue("key1", "val")
is equal to
set %session.Data("key1") = "val"
and
do ..setValue("key1", "key2", "key3", "key4", "val")
is equal to
set %session.Data("key1", "key2", "key3", "key4") = "val"
so, quite simple, any amount of arguments, while the latest one is a value, and any previous is an index, should accept at least 2 arguments.
How would you implement this method?
Quite simple, but could be even better, with no useless quotations
did you mean that ?
Nope, still not what I mean, I have a better solution, just would like to see if the community will find it.
it doesn' trap this cases yet
It's easier ?
```
ClassMethod setValue(params...) As %Status
{
quit:params<2 0
s name="%session.Data"
for i=1:1:params-1 set:$GET(params(i))'="" name=$NA(@name@(params(i)))
set @name=params(params)
quit $$$OK
}
```
Yes, this is better, I would even use this
@Sergey Mikhailenko
Check your code:
with error trapping
I'm not sure about what you mean with "unlimited amount of indexes"...
first, there is a limit of 255 for the parameters, this means you can have
but you can't have
second, if you meant to have many-many values (in sense of, we have to much data)
then, at some point you will reach the and of the available RAM (incl. swap/paging space. Usually swap/paging space is much less then the space for the real data).
thirdly, if you meant variable number of indexes (in sense of variable number of parameters) then I can just refine Robert's solution to
In case, you have both, variable number of indices and too much data then you could use a mix of the above with data placed in a temp file.
Somewhere, at the program start, let you point %sessionData to a temp file
and then consider this in the setValue method
Of course, in your application, you have to change only those %session.Data(...) to @%sessionData@(...) which uses the "variable-big-data" part of %session.Data(). All other (the standard ones) stay unchanged.
For sure, you have good points, but some points just out of scope at all. Yes, it's limited anyway.
My main point is to not have a limited number of parameters like below
And I was just curious if the community knows how to deal with MultiDimensional property, in such a case.
Sorry, I don't quite get you.
One used to say, if I don't understand something, then this something is either too complicated or very simple. So where belongs your case?
Sorry, it's just for discussion, to see how people would do some simple task.
I'd mimic %DispatchSetMultidimProperty signature. Shame local cannot be casted into a multi-argument call. Wrap in $g if values can be skipped.
Another option just for the fun:
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue