Written by

Senior Software Engineer
MOD
Question Ashok Kumar T · Sep 29, 2023

SQL ObjectSelectMode for Object properties

Hello Community,

I have couple of question about the DynamicSQL.

1. The %ObjectSelectMode is working perfectly in the DynamicSQL for the object property in direct query. However this is not supported for class query. Is there any way to resolve this / Get the object value for class query result.

2. What is the reason behind for a stored query prepared using %PrepareClassQuery() you must use the %Get("fieldname") method.

Class Samples.DB.NewClass1 Extends%Persistent
{
Property Address As NewClass3;ClassMethod TestQuery()
{ 
	set statement = ##class(%SQL.Statement).%New()
	set statement.%ObjectSelectMode=1set tSC = statement.%PrepareClassQuery("Learning.DB.NewClass1","GetAddressQuery",0)
	set tResult = statement.%Execute()
	do tResult.%Next()
	write !,"MyObjPrope :",tResult.%Get("Address"),"  object:",$isobject(tResult.%Get("Address"))
	quit
}

Query GetAddressQuery() As%SQLQuery(ROWSPEC = "Address") [ SqlProc ]
{
	SELECT Address FROM Samples_DB.NewClass1 Where Id=3
}


}
Product version: IRIS 2023.2
$ZV: IRIS for Windows (x86-64) 2023.2

Comments

David Hockenbroch · Sep 29, 2023

Where you have your query defined, does it work if you change the definition to include the SELECTMODE as RUNTIME?

Query GetAddressQuery() As%SQLQuery(ROWSPEC = "Address",SELECTMODE = "RUNTIME") [ SqlProc ]
0
Ashok Kumar T  Sep 29, 2023 to David Hockenbroch

Hi @David Hockenbroch 

Thanks for the response. The SELECTMODE = "RUNTIME" is not works to retrieve the object as a value from the object properties.

0
Joel Solon · Oct 16, 2023

The three techniques for using SQL in your code (Class queries, Dynamic SQL, Embedded SQL) each have their pros and cons. The %ObjectSelectMode and tResult.<column> (instead of tResult.%Get("<column>") ) features only work with Dynamic SQL.

0