如何设置%Dictionary.StorageSQLMapDefinition类的Name属性? 我有这段代码:
set storMaps = ##class(%Dictionary.StorageSQLMapDefinition).%New()
set storMaps.Name = ?????
我不知道如何设置storMaps.Name。 Name prop的数据类型。根据文档是%Dictionary.SQLIdentifier。但我不知道如何设置这个属性。我收到一个错误:
SQL Map类型无效
答案 0 :(得分:1)
您可能忘记了%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>