Intersystems caché - 关系映射(自定义 sql 存储)
Intersystems caché - relationale mapping (custom sql storage)
我在缓存数据库中有更多具有相同数据结构的全局变量。对于每个全局变量,我都用 SQL 存储映射定义了 class,但我需要对所有全局变量进行通用处理。是否可以定义一个 class 和 sql 存储映射,它将在每次 SQL 查询执行之前用于映射?我需要避免为每个需要通过 SQL 访问的全局变量声明 class。我使用 ODBC 执行 SQL 语句。
如果有人能帮助我,我将不胜感激
我的全局变量是这样的:
^glob1("x","y","SL",1) = "Name"
^glob1("x","y","SL",1,"Format") = "myFormat"
^glob1("x","y","SL",1,"Typ") = "my Type"
^glob1("x","y","SL",2) = "Name2"
^glob1("x","y","SL",2,"Format") = "myFormat2"
^glob1("x","y","SL",2,"Typ") = "Type2"
^nextGlob("x","y","SL",1) = "Next Name"
^nextGlob("x","y","SL",1,"Format") = "Next myFormat"
^nextGlob("x","y","SL",1,"Typ") = "my Type"
^another("x","y","SL",13) = "Another Name"
^another("x","y","SL",13,"Format") = "Another myFormat"
^another("x","y","SL",13,"Typ") = "Another Type"
我想使用一个 ObjectScript sql 访问全局变量 class。
如果所有全局变量都相同,那么您可以这样做,但很可能您的全局变量都不同,因此不太可能出现单个存储映射。您是否已经拥有描述现有全局变量的数据 dictionary/meta 数据系统?如果是这样,我会考虑将现有数据字典定义的转换写入缓存 类.
如果您只需要通过ODBC 从Caché 中读取数据。所以,在 ODBC 中你可以使用 CALL 语句。并且可以写一些SqlProc,可以被ODBC调用。
如我所见,您所有的全局变量都具有相同的结构。如果是这样,那将很容易。你可以把这样的东西放在你的 class.
Query Test() As %Query(ROWSPEC = "ID:%String,Global:%String,Name:%String,Typ:%String,Format:%String") [ SqlProc ]
{
}
ClassMethod TestExecute(ByRef qHandle As %Binary) As %Status
{
#; Initial settings
#; List of Globals
set $li(qHandle,1)=$lb("glob1","nextGlob","another")
#; Current Global index
set $li(qHandle,2)=1
#; Current ID in global
set $li(qHandle,3)=""
Quit $$$OK
}
ClassMethod TestClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = TestExecute ]
{
Quit $$$OK
}
ClassMethod TestFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = TestExecute ]
{
set globals=$lg(qHandle,1)
set globalInd=$lg(qHandle,2)
set id=$lg(qHandle,3)
set AtEnd=1
for {
set global=$lg(globals,globalInd)
quit:global=""
set globalData="^"_global
set globalData=$na(@globalData@("x","y","SL"))
set id=$o(@globalData@(id),1,name)
if id'="" {
set AtEnd=0
set typ=$get(@globalData@(id,"Typ"))
set format=$get(@globalData@(id,"Format"))
set Row=$lb(id,global,name,typ,format)
set $li(qHandle,3)=id
quit
} elseif $i(globalInd) {
set id=""
set $li(qHandle,2)=globalInd
}
}
Quit $$$OK
}
然后你可以像这样执行语句
CALL pkg.classname_test()
结果就是这张照片上的样子
我在缓存数据库中有更多具有相同数据结构的全局变量。对于每个全局变量,我都用 SQL 存储映射定义了 class,但我需要对所有全局变量进行通用处理。是否可以定义一个 class 和 sql 存储映射,它将在每次 SQL 查询执行之前用于映射?我需要避免为每个需要通过 SQL 访问的全局变量声明 class。我使用 ODBC 执行 SQL 语句。
如果有人能帮助我,我将不胜感激
我的全局变量是这样的:
^glob1("x","y","SL",1) = "Name"
^glob1("x","y","SL",1,"Format") = "myFormat"
^glob1("x","y","SL",1,"Typ") = "my Type"
^glob1("x","y","SL",2) = "Name2"
^glob1("x","y","SL",2,"Format") = "myFormat2"
^glob1("x","y","SL",2,"Typ") = "Type2"
^nextGlob("x","y","SL",1) = "Next Name"
^nextGlob("x","y","SL",1,"Format") = "Next myFormat"
^nextGlob("x","y","SL",1,"Typ") = "my Type"
^another("x","y","SL",13) = "Another Name"
^another("x","y","SL",13,"Format") = "Another myFormat"
^another("x","y","SL",13,"Typ") = "Another Type"
我想使用一个 ObjectScript sql 访问全局变量 class。
如果所有全局变量都相同,那么您可以这样做,但很可能您的全局变量都不同,因此不太可能出现单个存储映射。您是否已经拥有描述现有全局变量的数据 dictionary/meta 数据系统?如果是这样,我会考虑将现有数据字典定义的转换写入缓存 类.
如果您只需要通过ODBC 从Caché 中读取数据。所以,在 ODBC 中你可以使用 CALL 语句。并且可以写一些SqlProc,可以被ODBC调用。
如我所见,您所有的全局变量都具有相同的结构。如果是这样,那将很容易。你可以把这样的东西放在你的 class.
Query Test() As %Query(ROWSPEC = "ID:%String,Global:%String,Name:%String,Typ:%String,Format:%String") [ SqlProc ]
{
}
ClassMethod TestExecute(ByRef qHandle As %Binary) As %Status
{
#; Initial settings
#; List of Globals
set $li(qHandle,1)=$lb("glob1","nextGlob","another")
#; Current Global index
set $li(qHandle,2)=1
#; Current ID in global
set $li(qHandle,3)=""
Quit $$$OK
}
ClassMethod TestClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = TestExecute ]
{
Quit $$$OK
}
ClassMethod TestFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = TestExecute ]
{
set globals=$lg(qHandle,1)
set globalInd=$lg(qHandle,2)
set id=$lg(qHandle,3)
set AtEnd=1
for {
set global=$lg(globals,globalInd)
quit:global=""
set globalData="^"_global
set globalData=$na(@globalData@("x","y","SL"))
set id=$o(@globalData@(id),1,name)
if id'="" {
set AtEnd=0
set typ=$get(@globalData@(id,"Typ"))
set format=$get(@globalData@(id,"Format"))
set Row=$lb(id,global,name,typ,format)
set $li(qHandle,3)=id
quit
} elseif $i(globalInd) {
set id=""
set $li(qHandle,2)=globalInd
}
}
Quit $$$OK
}
然后你可以像这样执行语句
CALL pkg.classname_test()
结果就是这张照片上的样子