Forum Home
Welcome to the new pyForum.org.
A message board system written in pure python using the web2py framework.
pyForum is sporting a new, completely re-designed interface and back-end
Download pyForum from https://bitbucket.org/speedbird/pyforum
DAL.define_table()
By: rochacbruno
Rank: Starfleet Ensign
Postings: 9
From:
Posted: Mon, 12 July, 2010 - 01:41 AM

The most important method of a DAL is define_table:


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

It defines, stores and returns a Table object called "person" containing a field (column) "name". This object can also be accessed via db.person, so you do not need to catch the return value. define_table checks whether or not the corresponding table exists. If it does not, it generates the SQL to create it and executes the SQL. If the table does exist but differs from the one being defined, it generates the SQL to alter the table and executes it. If a field has changed type but not name, it will try to convert the data(If you do not want this, you need to redefine the table twice, the first time, letting web2py drop the field by removing it, and the second time adding the newly defined field so that web2py can create it.). If the table exists and matches the current definition, it will leave it alone. In all cases it will create the db.person object that represents the table.


[code - imagine code formatting, syntax highlighting here ]

db.define_table(
'mytable',
Field('myfield1','string',required=true),
Field('myfield2','integer',requires=IS_NOT_EMPTY())
)




[table]

imagine a table listing all parameters and validators
each entry will be linked with the relative thread.
[/table]
By: rochacbruno
Rank: Starfleet Ensign
Postings: 9
From:
Posted: Mon, 12 July, 2010 - 01:43 AM

Another member of documentation team can post more examples, or moderate/edit the first.

--

People can post examples too, but this will be hardly moderated!
By: rochacbruno
Rank: Starfleet Ensign
Postings: 9
From:
Posted: Mon, 12 July, 2010 - 01:44 AM

Just Like PHP Manual..

--

TO DO:

Markmin or Markdown to run.
Code syntax highlighting.
attached files.
A good INDEX system.

Welcome
System Announcements
Latest Posts
Support pyForum