On Nov 11, 2003, at 6:46 AM, <[EMAIL PROTECTED]> wrote:
just wondering whether there is any documentation which shows simple example
how to use sqlobject in webware ..


I am playing with it, and I am not sure where I should make a connection
(awake?), and when /how to close it (sleep?)....


Is this a proper way to work with sqlobject in webware:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from WebKit.Page import Page
from SQLObject import *

__connection__ = MySQLConnection(host='localhost', db='test', user='root',
passwd='', debug=1)


class Person(SQLObject):
    firstName       = StringCol(length=100)
    middleInitial   = StringCol(length=1, default=None)
    lastName        = StringCol(length=100)

The connections are implicit; you've already made the connection when you defined __connection__ and defined your class.


class Test(Page):
    def title(self):
        return 'Test'

    def awake(self, trans):
        Page.awake(self, trans)
        # should I do connection here???

So you don't need to do anything here, just use your Person objects.


    def sleep(self, trans):
        Page.sleep(self, trans)
        # should I close connection here???

    def writeContent(self):
        self.writeln('<h1>Test of webware with sqlobject</h1>')
        people=Person.select(Person.q.firstName=='Adam')
        for person in people:
            self.writeln('<li>',person.firstName,' ', person.lastName)
--
Ian Bicking | [EMAIL PROTECTED] | http://blog.ianbicking.org



-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to