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

主页 > 来自海外的问题: 使用自身作为参数的%Persistent类中的查询方法

问题
Michael Lei · 五月 5, 2021

来自海外的问题: 使用自身作为参数的%Persistent类中的查询方法

大家好,

我想知道是否有可能获取自身的值来运行查询。

我想创建一些查询以在%Persistent类中找到一个值,但是每个查询都使用不同的值。

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
}

}

然后我这样调用它:

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)

但是我有以下错误

%Message = "ERROR #5002: Error de cache: <OBJECT DISPATCH>zGetInfoFunc+5^Kurro.MyClass1 *Property 'KeyProcess' in class 'Kurro.MyClass' must be MultiDimensional "

很奇怪,因为此属性是一个简单的%String参数。

然后,我尝试获取自身的值,并使用相同的实例进行调用

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
}

并使用

set result = obj.GetInfoFunc()

但是是行不通的

%Message = "ERROR #5002: Error de cache: <PARAMETER>zGetInfo+1^Kurro.MyClass.1


是否有可能获取该对象的值以用作查询的参数?

此致,
库罗

 

Query method in a class %Persistent using itself as parameters

Hi all,

I'm wondering if is possible to get the values of itself to run a query.

I want to create some query to find a value into a %Persistent class but each one use diferent values.

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
}

}

Then I call it by this way:

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)

But I have the following error

%Message = "ERROR #5002: Error de cache: <OBJECT DISPATCH>zGetInfoFunc+5^Kurro.MyClass1 *Property 'KeyProcess' in class 'Kurro.MyClass' must be MultiDimensional "

It's weird, because this property is a simple %String param.

Then, I've tried to get itself values, and call using the same instance

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
}

and call it using

set result = obj.GetInfoFunc()

But is doesn't work

%Message = "ERROR #5002: Error de cache: <PARAMETER>zGetInfo+1^Kurro.MyClass.1"

is it possible to get the values of the object to use as parameter of the query?

Best regards,
Kurro

#SQL #Caché #Ensemble

源 URL:https://cn.community.intersystems.com/post/%E6%9D%A5%E8%87%AA%E6%B5%B7%E5%A4%96%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%9A-%E4%BD%BF%E7%94%A8%E8%87%AA%E8%BA%AB%E4%BD%9C%E4%B8%BA%E5%8F%82%E6%95%B0%E7%9A%84%EF%BC%85persistent%E7%B1%BB%E4%B8%AD%E7%9A%84%E6%9F%A5%E8%AF%A2%E6%96%B9%E6%B3%95