Skip to main content

This documentation is for an older version of this product. See the latest version of this content.Opens in a new tab

ストレージ・メソッド (2)

Store() のこのセクションは、格納された回答に対して複数のインデックスを作成します。インデックスもグローバルであり、Set を使用して作成しますが、その構造は異なります。インデックスには ^PersonI を使用します。メソッドのこれら 3 つの文は、添え字にデータを格納するため、一見奇妙に見えるかもしれません。2 つの文の値は、等号の右側にある空文字列 ("") だけです。理由は、これらの文で構築されるツリー構造にあります。


    set ^PersonI("Name", last, first, id) = ""  // index last and first name
    set ^PersonI("Phone", phone) = id           // index the UNIQUE phone
    set ^PersonI("DOB", intdob, id) = ""        // index the internal DOB

例えば、姓、名、ID は添え字に格納されます。姓と名前は自動的にアルファベット順に並べ替えられるため、データベースには姓、名の順でインデックスが作成されます。電話番号と誕生日のインデックスも同様に作成されます。^PersonI は 3 つの大きな枝に分かれ、各枝にインデックスがあるツリーになります。電話番号インデックスを構築する行は異なるため、電話番号の固有データを利用できます (ID は添え字に格納されません)。

これらの行は、Set $Bit を使用して ID 番号のビットマップ・インデックスを作成します。このビットマップ・インデックスには、64000 ビットの "チャンク" が 1 つ以上あります。ID が 1 ~ 63999 の人はチャンク 1、64000~ 127999 の人はチャンク 2 というようにビットを持ちます。この使い方は第 3 章で説明します。


    set chunk = (id\64000) + 1, position = (id#64000) + 1
    set $bit(^PersonI("Bitmap-ID", chunk), position) = 1

メソッドが完成したら、このプロシージャを実行して、グローバルへのデータの追加を開始します。その際、各グローバルのツリーを紙に描くと、わかりやすくなることがあります。いずれにしても、データを追加したら、管理ポータルを使用します。[システムエクスプローラ][グローバル] をクリックし、[表示] をクリックして、2 つのグローバル (^PersonD^PersonI) を確認します。

VS Code - ObjectScript


Class ObjectScript.DataEntry4
{

/// store the data
ClassMethod Store(answers as %String)
{
    read !, "Store? (y/n): ", yn  // ask if user wants to store
    // only go on if user says yes
    if ((yn '= "y") && (yn '= "Y")) {
        write "...not stored."
        quit
    }

    set id = $increment(^PersonD)  // use $increment to generate a new ID
    set ^PersonD(id) = answers  // store the answers
   
    set $listbuild(name, phone, intdob) = answers
    // split name into last and first for storage in index
    set last = $piece(name, ",", 1), first = $piece(name, ",", 2)

    /* the next three statements store data in subscripts.
       because of the automatic sorting of subscripts,
       this has the effect of building 3 indexes: name, phone, and DOB */
    set ^PersonI("Name", last, first, id) = ""  // index last and first name
    set ^PersonI("Phone", phone) = id           // index the UNIQUE phone
    set ^PersonI("DOB", intdob, id) = ""        // index the internal DOB

    /* these statements turn the id into a "chunk #" and a "position #"
       and set a bit into the bitmap index */
    set chunk = (id\64000) + 1, position = (id#64000) + 1
    set $bit(^PersonI("Bitmap-ID", chunk), position) = 1
    write "...stored"    
}
}
FeedbackOpens in a new tab