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
}
}Comments
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 ]Thanks for the response. The SELECTMODE = "RUNTIME" is not works to retrieve the object as a value from the object properties.
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.