NodeBox

Create visual output with Python programming code
Home Download Reference Tutorial Library Gallery About

database.Table.find()

Syntax

find(q, operator="=", fields="*", key=None)

Description

Returns records from the table that match a given query. By default, returns the record whose id is equal to q. The q parameter can contain an asterisk (*) at the start or at the end as a wildcard character. The key parameter allows you to specify a different field to search in. The operator parameter allows you to specify a different comparison, greater-than or less-than for example. By default, all fields from the record are returned, or you can define a list of field names in the fields parameter. See also the fieldname() command.

Example

Get the record from the pages table whose title field is "introduction":

db = ximport("database")
book = db.connect("book")
r = book.pages.find("introduction", key="title")
for record in r:
  print r
>>>(1, u'introduction', u'...', None, 1)

As you can see the returned value is a list of tuple-values, which is easy to unpack:

r = book.pages.find("introduction", key="title")
for id, title, text, image, pagenumber  in r:
  print title
>>>introduction

Get all the pages whose title starts with the word "chapter":

db = ximport("database")
book = db.connect("book")
r = book.pages.find("chapter *", key="title")