隐藏的系统间 - sql 存储定义

Intersystems caché - sql storage definition

如何设置 %Dictionary.StorageSQLMapDefinition class 的名称 属性? 我有这个代码:

set storMaps = ##class(%Dictionary.StorageSQLMapDefinition).%New()
set storMaps.Name = ?????

而且我不知道如何设置 storMaps.Name。 Name 属性的数据类型。根据文档是 %Dictionary.SQLIdentifier。但我不知道如何设置这个 属性。我收到一个错误:

SQL Map type is invalid

你可能忘记了 %Dictionary.StorageDefintion.

    set clsDef=##class(%Dictionary.ClassDefinition).%OpenId("User.Test")

    set storage=##class(%Dictionary.StorageDefinition).%New()
    set storage.Name="Test"
    set storage.Type="%CacheSQLStorage" // this is important

    set storageMap=##class(%Dictionary.StorageSQLMapDefinition).%New()
    set storageMap.Name="MasterMap"
    set storageMap.Global="^global"
    do storage.SQLMaps.Insert(storageMap)

    set data=##class(%Dictionary.StorageSQLMapDataDefinition).%New()
    set data.Name="name"
    set data.Node=1
    do storageMap.Data.Insert(data)

    set data=##class(%Dictionary.StorageSQLMapDataDefinition).%New()
    set data.Name="type"
    set data.Node=2
    do storageMap.Data.Insert(data)

    set subscript=##class(%Dictionary.StorageSQLMapSubDefinition).%New()
    set subscript.Name=1
    set subscript.Expression="""test"""
    do storageMap.Subscripts.Insert(subscript)

    set subscript=##class(%Dictionary.StorageSQLMapSubDefinition).%New()
    set subscript.Name=2
    set subscript.Expression="{ID}"
    do storageMap.Subscripts.Insert(subscript)

    set rowidspec=##class(%Dictionary.StorageSQLMapRowIdSpecDefinition).%New()
    set rowidspec.Name=1
    set rowidspec.Expression="{L2}"
    set rowidspec.Field="ID"
    do storageMap.RowIdSpecs.Insert(rowidspec)

    do clsDef.Storages.Insert(storage)
    set tSC=clsDef.%Save()

上面的代码将创建这样的存储空间

<Storage name="Test">
<SQLMap name="MasterMap">
<Data name="name">
<Node>1</Node>
</Data>
<Data name="type">
<Node>2</Node>
</Data>
<Global>^global</Global>
<RowIdSpec name="1">
<Expression>{L2}</Expression>
<Field>ID</Field>
</RowIdSpec>
<Subscript name="1">
<Expression>"test"</Expression>
</Subscript>
<Subscript name="2">
<Expression>{ID}</Expression>
</Subscript>
</SQLMap>
<Type>%CacheSQLStorage</Type>
</Storage>