Question
· Jun 28, 2019

Getting The Value of The Property of Instance or Getting The Value for the Column of The Record

Hi guys!

As you know there are two (at least) ways to get the stored value of the property of InterSystems IRIS class if you know the ID of an instance (or a record).

1. Get it by as a property of an instance with "Object access":

ClassMethod GetPropertyForID(stId As %Integer) As %String

{

set obj=..%OpenId(stId)

return obj.StringData

}

2. Get it as a value of a column of the record with "SQL access":

ClassMethod GetColumnForID(stId As %Integer) As %String

{

&sql(select StringData into :sd from Ideal.StoredData where id = :stId)

return sd

}

What do you prefer?

And why?

To reproduce the case and play with it on InterSystems IRIS 2019.2 you can use the ObjectScript repo.  
It is the persistent class Ideal.StoredData with one property StringData and simple populating util.

To set up the case on your laptop do the following (e.g. on mac, expecting you have git and docker installed):


# clone git@github.com:evshvarov/objectscript.git

# docker-compose build

# docker-compose up -d

# docker-compose exec iris iris session iris

USER>zn "OSCRIPT"

OSCRIPT>d ##class(Ideal.StoredData).AddRecords()       

OSCRIPT>w ##class(Ideal.StoredData).GetPropertyForID(1)
Value1
OSCRIPT>w ##class(Ideal.StoredData).GetColumnForID(1)  
Value1
OSCRIPT>
What Data Model Do you use with InterSystems IRIS?
Discussion (18)1
Log in or sign up to continue

Agreed with Danny. It really depends on the use case you are working on and what you really need from a table or object and how frequently it is retrieved.

So many you can ask your question a little bit different Evgeny.

The first approach I often use when building API and need to return a lot of values of the object. SQL when I need a few just as Danny mentioned and the GetStored when I need some value fast .