Query, Set, Rows

□未翻訳

□翻訳中

■翻訳完了(細田謙二)

■レビュー(Omi Chiba)

Query, Set, Rows

再び、以前定義した(削除した)テーブルを考え、3つのレコードを挿入します:

Let's consider again the table defined (and dropped) previously and insert three records:

1.

2.

3.

4.

5.

6.

7.

>>> db.define_table('person', Field('name'))

>>> db.person.insert(name="Alex")

1

>>> db.person.insert(name="Bob")

2

>>> db.person.insert(name="Carl")

3

テーブルは変数に格納することができます。たとえば、person変数として利用することができます:

You can store the table in a variable. For example, with variable person, you could do:

1.

>>> person = db.person

フィールドも、nameのように変数に格納することができたとえば次のようにすることができます:

You can also store a field in a variable such as name. For example, you could also do:

1.

>>> name = person.name

クエリを(==, !=, <, >, <=, >=, like, belongsのような演算子を用いて)構築し、そのクエリを次のように変数qに格納することもできます:

You can even build a query (using operators like ==, !=, <, >, <=, >=, like, belongs) and store the query in a variable q such as in:

1.

>>> q = name=='Alex'

dbをクエリとともに呼び出すと、レコードセットを定義していることになります。次のように書いて、それを変数sに格納することができます:

When you call db with a query, you define a set of records. You can store it in a variable s and write:

1.

>>> s = db(q)

ここまでデータベースクエリが実行されていないことに注意してください。 DAL+クエリは、単に、このdbにおいてクエリにマッチするレコードセットを定義するだけです。web2pyはクエリからどの(複数の)テーブルが参加しているかを決めるので、実際、それを指定する必要はありません。

Notice that no database query has been performed so far. DAL + Query simply define a set of records in this db that match the query. web2py determines from the query which table (or tables) are involved and, in fact, there is no need to specify that.