Published on InterSystems Developer Community (https://community.intersystems.com)

Página Inicial > Método de consulta em uma classe %Persistent usando como parâmetro

Pergunta
Guilherme Koerber · Abr. 29, 2021

Método de consulta em uma classe %Persistent usando como parâmetro

Olá a todos,

Estou me perguntando se é possível obter os valores de si mesmo para executar uma consulta.

Eu quero criar uma consulta para encontrar um valor em uma classe %Persistent, mas cada uma usa valores diferentes.

Class Kurro.MyClass Extends %Persistent
{

/// Key of process
Property KeyProcess As %String(MAXLEN = "");

/// Specialist
Property CodeSpecialist As %String;

/// Provider
Property CodeProvider As %String;

/// Center
Property CodeCenter As %String;

/// Date
Property Date As %TimeStamp;

/// IdList
Property IdList As %String;

/// IdProcess
Property IdProcess As %String;

/// Duration
Property Duration As %String;

Query GetInfo(pObject AS Kurro.MyClass) As %SQLQuery(CONTAINID = 1, ROWSPEC = "IdList:%String,IdProcess:%String,Duration:%String")
{
    SELECT IdList, IdProcess, Duration
    FROM Kurro.MyClass
    WHERE KeyProcess = :pObject.KeyProcess
    AND CodeSpecialist = :pObject.CodeSpecialist
    AND CodeProvider = :pObject.CodeProvider
    AND CodeCenter = :pObject.CodeCenter
    AND Date = :pObject.Date
}

}

Então eu chamo desta forma:

set obj=##class(Kurro.MyClass).%New()
set obj.KeyProcess="1033004-1#"
set obj.CodeSpecialist = "surgery"
set obj.CodeProvider = "PR002"
set obj.CodeCenter = "CENTER-01"
set obj.Date = $ZDATETIME($ZDATETIMEH("2021-04-30 15:45:00",3,1),3,1)

set result = obj.GetInfoFunc(obj)

Mas eu tenho o seguinte erro

% Message = "ERROR # 5002: Error de cache: <OBJECT DISPATCH> zGetInfoFunc + 5 ^ Kurro.MyClass1 * Propriedade 'KeyProcess' na classe 'Kurro.MyClass' deve ser MultiDimensional"

É estranho, porque essa propriedade é um parâmetro %String simples.

Em seguida, tentei obter valores para si mesmo e chamar usando a mesma instância

Query GetInfo() As %SQLQuery(CONTAINID = 1, ROWSPEC = "IdList:%String,IdProcess:%String,Duration:%String")
{
    SELECT IdList, IdProcess, Duration
    FROM Kurro.MyClass
    WHERE KeyProcess = KeyProcess
    AND CodeSpecialist = CodeSpecialist
    AND CodeProvider = CodeProvider
    AND CodeCenter = CodeCenter
    AND Date = Date
}

e chamá-lo usando

set result = obj.GetInfoFunc()

Mas não funciona

% Message = "ERROR # 5002: Erro de cache: <PARAMETER> z GetInfo + 1 ^ Kurro.MyClass.1"


é possível obter os valores do objeto para usar como parâmetro da consulta?

Atenciosamente,
Kurro

#SQL #Caché #Ensemble

URL de origem:https://pt.community.intersystems.com/post/m%C3%A9todo-de-consulta-em-uma-classe-persistent-usando-como-par%C3%A2metro