Thanks!  Yea I posted there as well, thinking it could be sqlalchemy
specific. I later found out what was causing it and posted the solution
there.

On Wed, Aug 5, 2009 at 12:54 AM, Gaetan de Menten <[email protected]>wrote:

>
> For the record (this was already solved in the SQLAlchemy list), the
> problem was due to cherrypy being multi-threaded while SQLite
> in-memory database are thread-local, hence failing with a "table does
> not exist" when trying to access any table in another thread.
>
> On Tue, Aug 4, 2009 at 02:13, kportertx<[email protected]> wrote:
>
> > I cannot seem to use the session variable within a class
> >
> > here is the code
> >
> > #!/usr/bin/env python
> > ########################################################################
> > #
> > #
> > #                               MODEL
> > #
> > #
> > #
> > ########################################################################
> > from elixir import *
> >
> > global session, metadata
> > metadata.bind = 'sqlite:///:memory:'
> > metadata.echo = True
> >
> > class Test(Entity):
> >    """ ORM for Tests. """
> >    id = Field(Integer, primary_key = True)
> >    name = Field(Unicode(50), required = True)
> >    questions = OneToMany('Question')
> >    def __init__(self,name):
> >        """ Accepts a name for a test """
> >        #TODO: Ensure valid input
> >        self.name = name
> >
> > class Question(Entity):
> >    """ ORM for Questions. """
> >    id = Field(Integer, primary_key = True)
> >    question = Field(UnicodeText, required = True)
> >    test = ManyToOne('Test')
> >    answers = OneToMany('Answer')
> >    def __init__(self,test_id, question):
> >        """ Accepts a test_id and a question to sign that test """
> >        #TODO: Ensure valid input
> >        self.question = question
> >
> > class Answer(Entity):
> >    """ ORM for Answers. """
> >    id = Field(Integer, primary_key = True)
> >    answer = Field(UnicodeText, required = True)
> >    correct = Field(Unicode(1), required = True) # y for correct n for
> > not
> >    question = ManyToOne('Question')
> >    def __init__(self,question_id,answer,correct=0):
> >        """ Accepts a question_id and a answer to assign to that
> > question.
> >            Optionally it accepts correct, y for correct, n for not
> >            Default for correct is n"""
> >        #TODO: Ensure vaild input
> >        self.answer = answer
> >        self.correct = correct
> >
> > setup_all()
> > create_all()
> >
> > ########################################################################
> > #
> > #
> > #                          VIEW/CONTROLLER
> > #
> > #                        Will Seperate Later
> > #
> > #
> > #
> > ########################################################################
> >
> > import cherrypy
> >
> > class WebTest(object):
> >    """ Cherrypy server root """
> >    def header(self):
> >        """ Defines a header to be used for web pages... Should be
> > temporary """
> >        return '<html><head><title>pyWebTest</title></head><body>'
> >    def footer(self):
> >        """ Defines a footer to be used for web pages... Should also
> > be temporary """
> >        return '</body></html>'
> >    @cherrypy.expose()
> >    def index(self):
> >        """ Root page for pyWebTest server """
> >        output = 'BEGIN<br />'
> >        test = Test('network')
> >        output = output + 'The test ' + test.name + ' has been
> > initialized!<br />'
> >        test1 = Test('A+')
> >        output = output + str(session.new)+ '<br />'
> >        output = output + str(session.dirty) + '<br />'
> >        session.flush()
> >        session.commit()
> >        if test.id >=0:
> >            output = output + 'Test has been added<br />'
> >            output = output + str(test1.id) + '<br />'
> >        #session.query(Test).all()
> >        #session.query(Test).filter(Test.name.in_(['network
> > +','fake'])).all()
> >        output = output + 'DONE <br />'
> >        return self.header() + output + self.footer()
> >
> > def main():
> >    cherrypy.quickstart(WebTest())
> >    return 0
> >
> > if __name__ == '__main__': main()
>
> --
> Gaƫtan de Menten
> http://openhex.org
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to