<type>integer</type> <notnull>1</notnull> <unsigned>1</unsigned> <default>0</default> </field> <field> <name>handle</name> <type>text</type> <length>20</length> <notnull>1</notnull> <default></default> </field> <field> <name>is_active</name> <type>boolean</type> <notnull>1</notnull> <default>N</default> </field> </declaration> </table>
As you can see, things can get a bit lengthy here as to be expected when using XML. No need to worry: We are working on a browser based tool called MDB_frontend that will make this process much easier. I will talk about this project further down into this article a bit more. Hopefully, the advantage of this pretty verbose representation of the table is that things are somewhat self explanatory. The table in the last example is called users and we have defined 3 fields: user_id of type integer, handle of type text and is_active of type boolean. Remember that MDB handles the type abstraction for you if you pass it the necessary metadata as shown in the previous section. You also need not to worry about what MDB maps these types to in your RDBMS. The other tags you can use in each of the field declarations are optional: length, notnull, unsigned and default. 如你能看到的,如使用 XML 时可以预期的,东西变得有一些冗长。不用担心:我们有一个基于浏览器的工具称为 MDB_frontend 使得这个过程更加简单。我将在这篇文章的后面谈论这个工程。可能这极其详细地表格描述的优点是非常明显。前面例子中的表格被称为 users 并且我们定义了 3 个域:类型为整数的 user_id,类型为文本的 handle 和类型为逻辑型的 is_active。记住如果你如前一节那样传递了必要的元数据 MDB 为你处理类型抽象。你还不需要 MDB 把这些类型映射为你的 RDBMS 中的什么。在每个域声明中还能使用的其他标签是可选的:length,notnull,unsigned 和 default。
The next thing that we now need to do is to ensure that the user_id is unique by placing the proper index on the user_id field. The index definition goes within the declaration tag (Listing 3). 下一件我们现在需要做的事情是通过在 user_id 域放置恰当的索引确保 user_id 是唯一的。索引定义就在声明标签之内(Listing 3)。
Listing 3:
<table> <name>users</name> <declaration> <index> <unique>1</unique> <name>user_id_index</name> <field> <name>user_id</name> <sorting>ascending</sorting> </field> </index> </declaration> </table>
The definition in listing 3 would create a unique ascending index named user_id_index on the field user_id. Of course, we could have specified more than one field in the index definition by simply adding another field tag. What we are still missing now is a sequence to generate unique user id''s for us: 在 listing 3 中的定义在域 user_id 中创建一个唯一的上升排序的名为 user_id_index 的索引。当然,我们可以简单地添加另外一个域标签在索引定义中指定多于一个的域。我们现在 |