Intersystemscaché - sqlStorage

时间:2015-03-04 15:11:36

标签: intersystems-cache objectscript

我需要将我的全局映射到sql。我有这样的全球结构:

^myGlob("mltab","main","Dta",idRow,idCol,"Index")

具体:

^myGlob("mltab","main","Dta",3,1)   =   20
^myGlob("mltab","main","Dta",3,2)   =   30
^myGlob("mltab","main","Dta",3,2,"Index")   =   "t|1320|30|62913"
^myGlob("mltab","main","Dta",3,3)   =   "01.04.2013"
^myGlob("mltab","main","Dta",3,4)   =   36
^myGlob("mltab","main","Dta",3,5)   =   166.8
^myGlob("mltab","main","Dta",4,1)   =   20
^myGlob("mltab","main","Dta",4,2)   =   30
^myGlob("mltab","main","Dta",4,3)   =   "01.04.2013"
^myGlob("mltab","main","Dta",4,4)   =   36
^myGlob("mltab","main","Dta",4,4,"Index")   =   "nextIndexVal"
^myGlob("mltab","main","Dta",4,5)   =   166.8
                             .
                             .
                             .

"mltab""main""Dta""Index"是不变的。 idRow是我的主要关键,而idCol对我来说并不重要,但会给我带来问题,因为它可能会发生变化。

我需要为某些表格列(地图类属性)提供类似 colId = 2 ^ index =" t | 1320 | 30 | 62913" 的值。我已映射的其他值。


我目前的代码如下:

Class Kza.NewClass1 Extends %Persistent [ Not ProcedureBlock, StorageStrategy = MySqlStorageStrategy ]
{

Property hyperlink As %String;

Property colId As %String;

Property id As %Integer;

Property prop1 As %String;

Property prop2 As %String;

Property prop3 As %String;

Property prop4 As %String;

Property prop5 As %String;

Index MyIndex1 On id [ IdKey, PrimaryKey, Unique ];

<Storage name="MySqlStorageStrategy">
<ExtentSize>100000</ExtentSize>
<SQLMap name="Map1">
<Global>^myGlob</Global>
<RowIdSpec name="1">
<Expression>{L2}</Expression>
<Field>id</Field>
</RowIdSpec>
<Subscript name="1">
<Expression>{id}</Expression>
</Subscript>
<Subscript name="2">
<Expression>{colId}</Expression>
</Subscript>
<Type>index</Type>
</SQLMap>
<SQLMap name="MyMasterMap">
<ConditionalWithHostVars></ConditionalWithHostVars>
<Data name="colId">
<Node>6</Node>
</Data>
<Data name="hyperlink">
<Node>"Index"</Node>
</Data>
<Data name="prop1">
<Node>1</Node>
</Data>
<Data name="prop2">
<Node>2</Node>
</Data>
<Data name="prop3">
<Node>3</Node>
</Data>
<Data name="prop4">
<Node>4</Node>
</Data>
<Data name="prop5">
<Node>5</Node>
</Data>
<Global>^myGlob</Global>
<RowIdSpec name="1">
<Expression>{L1}</Expression>
<Field>id</Field>
</RowIdSpec>
<Subscript name="1">
<Expression>"mltab"</Expression>
</Subscript>
<Subscript name="2">
<Expression>"main"</Expression>
</Subscript>
<Subscript name="3">
<Expression>"Dta"</Expression>
</Subscript>
<Subscript name="4">
<Expression>{id}</Expression>
</Subscript>
<Type>data</Type>
</SQLMap>
<StreamLocation>^Kza.testToTable1S</StreamLocation>
<Type>%CacheSQLStorage</Type>
</Storage>
}

我认为我的问题可能出在数据节点定义中:

<Data name="colId">
    <Node>6</Node>
</Data>
<Data name="hyperlink">
    <Node>"Index"</Node>
</Data>

但遗憾的是,我对这个问题并不熟悉...所以有人可以帮助我在我的sql表中获取列hyperlink,其值{3}和{{1}的行colId=2^index=t|1320|30|62913在行ID 4上?

2 个答案:

答案 0 :(得分:2)

如果修复了超链接属性的colId,你可以使用标签RetrievalCode尽可能编写一些COS代码,如果没有修复,你可以为retreive colId写一些东西,然后就像这里一样

<Data name="hyperlink">
  <RetrievalCode> s {hyperlink}=$g(^myGlob("mltab","main","Dta",{L4},2,"Index"))
  </RetrievalCode>
</Data>

并且你的RowIdSpec可能有误,因为4级下标的属性id,所以你使用L4表示。

<RowIdSpec name="1">
  <Expression>{L4}</Expression>
  <Field>id</Field>
</RowIdSpec>

和最新变体

<Data name="colId">
  <RetrievalCode>s {*}="" f { s {*}=$o(^myGlob({L1},{L2},{L3},{L4},{*})) quit:{*}=""  quit:$d(^myGlob({L1},{L2},{L3},{L4},{*},"Index"))}
  </RetrievalCode>
</Data>
<Data name="hyperlink">
  <RetrievalCode>s colId="" f { s colId=$o(^myGlob({L1},{L2},{L3},{L4},colId)) quit:colId=""  quit:$d(^myGlob({L1},{L2},{L3},{L4},colId,"Index"))}
s {*}=$g(^myGlob({L1},{L2},{L3},{L4},colId,"Index"))
  </RetrievalCode>
</Data>
<Data name="hyperlink2">
  <RetrievalCode>s colId="" f { s colId=$o(^myGlob({L1},{L2},{L3},{L4},colId)) quit:colId=""  quit:$d(^myGlob({L1},{L2},{L3},{L4},colId,"Index"))}
s {*}="colId="_colId_"^index="""_$g(^myGlob({L1},{L2},{L3},{L4},colId,"Index"))_""""
  </RetrievalCode>
</Data>

答案 1 :(得分:1)

SQLMap存储中的这段代码可以做到:

<Data name="hyperlink">
<RetrievalCode>
<![CDATA[set res=""
    set colId=""
    for
    {
        set colId = $order( ^myGlob("mltab","main","Dta",{L4},colId) )
        quit:(colId = "")

        set indexTab = $g(^myGlob("mltab","main","Dta",{L4},colId,"Index"))
        if indexTab'="" {
            set res = res_"colId="_colId_"index="_indexTab
        }
    }
    s {hyperlink}=res]]></RetrievalCode>
</Data>

{L4}是行标识,只需要一个SQLmap