Home

  Documentation

  Download

  News

  Examples

builder.py Source Code

C:/Work/Lemon/Backups/Lemon-0.2.10/Lemon-0.2.10/../../doc/examples/code/builder.py
#!/usr/bin/env python

"The builder module doesn't work with Gadfly. If you would like to see it running edit the source code in the obvious way."
print "Content-type: text/html

<html><body><p>The builder module doesn't work with Gadfly. If you would like to see it running edit the source code in the obvious way.</p></body></html>"

# To run the code:
# 1. Uncomment the code below (leaving comments on the DateTime fields.
# 2. Comment the two lines above
# 3. Edit the database connect line

#~ import cgitb; cgitb.enable()
#~ import sys
#~ sys.path.append('../')
#~ sys.path.append('../../../')
#~ import lemon.db, lemon.db.builder, lemon.html.form

#~ conn = lemon.db.connect(type="mysql", database="test") # XXX EDIT THIS LINE
#~ database = conn.cursor(autoConvert=True)
        
#~ class Person(lemon.db.builder.Table):
    #~ database = database
    #~ table = 'Person'
    
    #~ #mystringCol         = MyStringCol()
    
    #~ normal_int          = lemon.db.builder.IntegerCol()
    #~ normal_float        = lemon.db.builder.FloatCol()
    #~ normal_char         = lemon.db.builder.CharCol()
    #~ normal_string       = lemon.db.builder.StringCol()
    #~ normal_text         = lemon.db.builder.TextCol()
    #~ #normal_dateTime     = lemon.db.builder.DateTimeCol() DateTime Fields are broken use date and time instead!
    #~ normal_date         = lemon.db.builder.DateCol()
    #~ normal_time         = lemon.db.builder.TimeCol()
    
    #~ notNULL_int         = lemon.db.builder.IntegerCol(notNULL=True)
    #~ notNULL_float       = lemon.db.builder.FloatCol(notNULL=True)
    #~ notNULL_char        = lemon.db.builder.CharCol(notNULL=True)
    #~ notNULL_string      = lemon.db.builder.StringCol(notNULL=True)
    #~ notNULL_text        = lemon.db.builder.TextCol(notNULL=True)
    #~ #notNULL_dateTime    = lemon.db.builder.DateTimeCol(notNULL=True) DateTime Fields are broken use date and time instead!
    #~ notNULL_date        = lemon.db.builder.DateCol(notNULL=True)
    #~ notNULL_time        = lemon.db.builder.TimeCol(notNULL=True)

#~ personTable = Person()

#~ if personTable.exists():
    #~ personTable.drop()
#~ personTable.create()

#~ person = personTable.emptyRow()
#~ form = person.form()


#~ print lemon.header()
#~ print '<html><head><title>Builder Example</title></head><body>'

#~ if len(lemon.cgi)>0:
    #~ form.populate(lemon.cgi)
    #~ if form.valid():
        #~ newRow = personTable.add(all=form.dict())
        #~ print '<h1>Added!</h1>'
        #~ print newRow.form().frozen()
    #~ else:
        #~ print form.html()
#~ else:
    #~ print form.html()
#~ print '</body></html>'

© 2002-2003 James Gardner