Package web2py :: Package gluon :: Module sql :: Class KeyedTable
[hide private]
[frames] | no frames]

Class KeyedTable

source code

object --+        
         |        
      dict --+    
             |    
         Table --+
                 |
                KeyedTable

an instance of this class represents a database keyed table

Example:

   db = DAL(...)
   db.define_table('account',
     Field('accnum','integer'),
     Field('acctype'),
     Field('accdesc'),
     primarykey=['accnum','acctype'])
   db.users.insert(accnum=1000,acctype='A',accdesc='Assets')
   db.users.drop()

   db.define_table('subacct',
     Field('sanum','integer'),
     Field('refnum','reference account.accnum'),
     Field('reftype','reference account.acctype'),
     Field('sadesc','string'),
     primarykey=['sanum']))

Notes: 1) primarykey is a list of the field names that make up the primary key 2) all primarykey fields will have NOT NULL set even if not specified 3) references are to other keyed tables only 4) references must use tablename.fieldname format, as shown above 5) update_record function is not available

Instance Methods [hide private]
new empty dictionary

__init__(self, db, tablename, *fields, **args)
Initializes the table and performs checking on the provided fields.
source code
 
_create_references(self) source code
 
_build_query(self, key) source code
 
__getitem__(self, key)
x[y]
source code
 
__setitem__(self, key, value)
x[i]=y
source code
 
__delitem__(self, key)
del x[y]
source code
 
__repr__(self)
repr(x)
source code
 
_create(self, migrate=True, fake_migrate=False) source code
 
insert(self, **fields) source code

Inherited from Table: __getattr__, __iter__, __setattr__, __str__, bulk_insert, create, drop, import_from_csv_file, on, truncate, with_alias

Inherited from Table (private): _drop, _filter_fields, _insert, _migrate, _truncate

Inherited from dict: __cmp__, __contains__, __eq__, __ge__, __getattribute__, __gt__, __hash__, __le__, __len__, __lt__, __ne__, __new__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, db, tablename, *fields, **args)
(Constructor)

source code 

Initializes the table and performs checking on the provided fields.

If a field is of type Table, the fields (excluding 'id') from that table will be used instead.

:raises SyntaxError: when a supplied field is of incorrect type.

Returns:
new empty dictionary

Overrides: object.__init__

_create_references(self)

source code 
Overrides: Table._create_references

__getitem__(self, key)
(Indexing operator)

source code 

x[y]

Overrides: dict.__getitem__
(inherited documentation)

__setitem__(self, key, value)
(Index assignment operator)

source code 

x[i]=y

Overrides: dict.__setitem__
(inherited documentation)

__delitem__(self, key)
(Index deletion operator)

source code 

del x[y]

Overrides: dict.__delitem__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

_create(self, migrate=True, fake_migrate=False)

source code 
Overrides: Table._create

insert(self, **fields)

source code 
Overrides: Table.insert