「XMLDBのキーおよびインデックスの命名 (Dev docs)」の版間の差分

提供:MoodleDocs
移動先:案内検索
編集の要約なし
編集の要約なし
29行目: 29行目:


* '''[$CFG->prefix]''' は、すべてのオブジェクトに付加するプレフィックスになりますが、Oracle については [[XMLDBの問題 (Dev docs)#命名規則 II|命名規則 II]] を参照してください (30cc という制限に配慮して、このプレフィックスが 4cc より長くならないようにします) 。
* '''[$CFG->prefix]''' は、すべてのオブジェクトに付加するプレフィックスになりますが、Oracle については [[XMLDBの問題 (Dev docs)#命名規則 II|命名規則 II]] を参照してください (30cc という制限に配慮して、このプレフィックスが 4cc より長くならないようにします) 。
* '''tablename_abbreviated''' will be an abbreviated representation of the table name, automatically generated by spliting the table name is its words and getting the first '''4''' character of each word. For example, the table "<font color="red">glos</font>sary_<font color="red">entr</font>ies_<font color="red">cate</font>gories" will converted to the "<font color="red">glosentrcate</font>" abbreviation.
* '''tablename_abbreviated''' はテーブル名の省略形になります。テーブル名を単語に分割し、それぞれの単語の最初の '''4''' 文字を取得して自動的に生成されます。例えば、テーブル "<font color="red">glos</font>sary_<font color="red">entr</font>ies_<font color="red">cate</font>gories" "<font color="red">glosentrcate</font>" の略号に変換されます。
* '''columnames_abbreviated''' will be an abbreviated representation of the columns used by the object (index, key, sequence) generated by the concatenation of the first '''3''' chars of each field. For example, one index over the "<font color="red">nam</font>e, <font color="red">lev</font>el, <font color="red">con</font>text" fields be converted to the "<font color="red">namlevcon</font>" abbreviation.
* '''columnames_abbreviated''' will be an abbreviated representation of the columns used by the object (index, key, sequence) generated by the concatenation of the first '''3''' chars of each field. For example, one index over the "<font color="red">nam</font>e, <font color="red">lev</font>el, <font color="red">con</font>text" fields be converted to the "<font color="red">namlevcon</font>" abbreviation.
* ''''object_type''' will declare de type of object we are creating. It will be one of these:
* ''''object_type''' will declare de type of object we are creating. It will be one of these:

2023年1月25日 (水) 06:49時点における版

XMLDB ドキュメンテーション > XMLDBのキーおよびインデックスの命名


DB 内のオブジェクトにはそれぞれ名前がついています。テーブル名やフィールド名はわかりやすいですが、キー、インデックス、シーケンスなど、わかりにくい名前で作成されているものもあります。このページでは、これらのオブジェクトが XMLDB ジェネレータによって圧縮された方法で命名される方法を少し説明しようと思います。

まず知っておいていただきたいのは、XMLDB スキーマファイル のもとでは、主にいくつかの 厳密な規則 に従って、すべてが簡単に命名されていることです。基本的に、すべてのキーとインデックスには、オブジェクト内のすべてのフィールド名を "-" で区切って連結した1つの文字列の名前が付けられます。つまり、フィールド "fieldA" と "fieldB" に対して1つのインデックスがある場合、XMLDB ファイル内のインデックスは "fieldA-fieldB" という名前になるのです。簡単ですね!

しかし、これらの結果の名前は、XMLDB ジェネレータが DB 構造を作成するために使用される最終的な名前にはなりません。そこで、多くの DB アプリケーションで広く使われている、ある命名法に従います:

  1. 標準的な命名規則が1つ。
  2. ある キー/インデックス が何らかのエラーを投げているときに、何が問題なのかを知ることができること。
  3. 同じ DB で複数の Moodle サーバを動作させることができること。

また、これらのルールはすべて XMLDB ジェネレータによって自動的に適用されるため、オブジェクトは正しい名前で作成され、そのような名前を直接使用する必要はありませんが、いくつかの特殊な状況下では、そのような名前に注意する必要があります。

また、RDBMS はそれぞれ名前の最大長に制限を設けています。それらは:

  • MySQL: 64 cc.
  • PostgreSQL: 64 cc.
  • Oracle: 30 cc.
  • MSSQL: 128 cc.

そのため、最小の数字が決めるように、30cc 以下ですべての名前を付けられるようにしなければなりません。

XMLDB コンストラクタ (XMLDB 形式を実際の RDBMS 文に変換できる関数) に実装する形式は、この形式に従うことを提案しています:

[$CFG->prefix]tablename_abbreviated_columnames_abbreviated_object_type

場所:

  • [$CFG->prefix] は、すべてのオブジェクトに付加するプレフィックスになりますが、Oracle については 命名規則 II を参照してください (30cc という制限に配慮して、このプレフィックスが 4cc より長くならないようにします) 。
  • tablename_abbreviated はテーブル名の省略形になります。テーブル名を単語に分割し、それぞれの単語の最初の 4 文字を取得して自動的に生成されます。例えば、テーブル "glossary_entries_categories" は "glosentrcate" の略号に変換されます。
  • columnames_abbreviated will be an abbreviated representation of the columns used by the object (index, key, sequence) generated by the concatenation of the first 3 chars of each field. For example, one index over the "name, level, context" fields be converted to the "namlevcon" abbreviation.
  • 'object_type will declare de type of object we are creating. It will be one of these:
    • pk: For Primary Keys
    • uk: For Unique Keys
    • fk: For Foreign Keys
    • ck: For Check Constraints
    • ix: For Indexes
    • uix: For Unique Indexes
    • seq: For Sequences
    • trg: For Triggers

The method responsible to calculate this names will be shared by all the different XMLDB generators, so all objects will be uniformly named. If any of the calculated names excess the infamous 30cc. the name will be reduced by removing characters from the "columnames_abbreviated" part until if fits completely.

Names generated automatically by RDBMS won't be specified at all. They are:

  • sequences: for PostgreSQL, the SERIAL keyword generates one sequence with a different name schema than the specified above.
  • primary: for MySQL, the PRIMARY KEY must be named (or is named by default) "primary".

Also, don't forget that you never will have to create/modify these names by hand. The XMLDB layer will generate them automatically and they are pretty different from the conventions used to name elements in the XMLDB Editor.