Business Service para consultar base de datos interna de IRIS
IRIS tiene adaptadores de entrada SQL para usar con SQL gateways como EnsLib.SQL.InboundAdapter para consultar repetidamente las conexiones de SQL Gateway. Apareció un escenario en el que queríamos consultar una base de datos interna para obtener algunos datos, pero no vimos un "servicio listo para usar" para esto.
Tener un servicio genérico que pueda sondear SQL interno para trabajar con otros componentes.
Lo que no estaba claro era "¿Cómo envío un conjunto de resultados en sentido descendente?". No estaba muy claro ya que un resultset en sí mismo no es una clase persistente y el objeto no puede ser "Swizzled", un error como ese
<METHOD DOES NOT EXIST>zNewRequestMessage+4^Ens.MessageHeader.1 *%GetSwizzleObject,%sqlcq.SRFT.cls535 -- logged as '-'
number - @''La solución fue usar el objeto.
EnsLib.SQL.SnapshotEsto luego se puede utilizar como un Business Operation para enviar un conjunto de resultados en sentido descendente al usar la función. ImportFromResultSet
set result=##class(EnsLib.SQL.Snapshot).%New()
// Some SQL query here resulting in resultset where rset is the resultset objectset tSC=result.ImportFromResultSet(rset)Luego podrá enviarlo a otra operación
set tSC=..SendRequestAsync(..ForwardComponentName,result,0) Quit:$$$ISERR(tSC)
Tenga en cuenta el código subido a open exchange disponible aquí a través de github. El ejemplo puedes abrirlo y consultarlo. El siguiente ejemplo es el método de clase que se utiliza para colocar en un html. Esto difiere ligeramente del ejemplo publicado, ya que se tomó de una implementación real.
ClassMethod GetDataTable(pRequest As EnsLib.SQL.Snapshot, html As%String) As%String
{
//first html obj can be if the styling needs passedif$ISOBJECT(html){set html=""}
//loop get column titles set ColumnIteration=1set ColumnCount=pRequest.%ResultColumnCountGet()
set html=html_" <table class=""tg"">"set html= html_ " " _"<tr>"set meta=pRequest.%GetMetadata() //this is like raw text of the result using it to get the column titles outif ColumnCount>0{
while ColumnIteration<=ColumnCount{
set html= html_ " <th>"_ meta.columns.GetAt(ColumnIteration).colName _" </th>"set ColumnIteration=ColumnIteration+1
}
}
set html= html_ " " _"</tr>"//not get the data from each row. In html need a <tr> and a td. set coldataiteration=1While pRequest.%Next() {
set html= html_ " <tr>"while coldataiteration <=ColumnCount{
set html= html_ " <td> "_pRequest.%GetData(coldataiteration) _" </td>"set coldataiteration=coldataiteration+1
}
set html= html_ " </tr>"set coldataiteration=1
}
set html= html_ " " _"</table>"$$$TRACE(html)
return html
}