Oops -- the __str__() method should be:

    def __repr__(self):
        return self.name

Sorry about that stupid mistake...  Here's the corrected code:

-----------------------------------------------------------------------------

import cherrypy
from elixir import *

metadata.bind = 'sqlite:///:memory:'      # this fails
#metadata.bind = 'sqlite:///database.db3'  # this works
metadata.bind.echo = True

class Department(Entity):
    name = Field(String(30))
    def __repr__(self):
        return self.name

setup_all(create_tables=True)
Department(name='Accounting')
Department(name='Finance')
session.commit()

# This displays on the console just fine either way (memory
# or disk database).
print '====> Departments: %s' % str(entities.Department.query.all())

class WebServer(object):
    def index(self):
        # This displays on the browser only if the database is
        # in a disk file.  It fails if the database is in memory.
        return 'Departments: %s' %
str(entities.Department.query.all())
    index.exposed = True

cherrypy.quickstart(WebServer())

-----------------------------------------------------------------------------

On Sep 4, 3:39 pm, Jim Slack <[EMAIL PROTECTED]> wrote:
> Here is a small program that works fine if the SQLite database is on
> disk, but doesn't if it is in memory:
>
> -----------------------------------------------------
> import cherrypy
> from elixir import *
>
> metadata.bind = 'sqlite:///:memory:'      # this fails
> #metadata.bind = 'sqlite:///database.db3'  # this works
> metadata.bind.echo = True
>
> class Department(Entity):
>     name = Field(String(30))
>     def __str__(self):
>         return name
>
> setup_all(create_tables=True)
> Department(name='Accounting')
> Department(name='Finance')
> session.commit()
>
> # This displays on the console just fine either way (memory or disk
> db).
> print '====> Departments: %s' % str(entities.Department.query.all())
>
> class WebServer(object):
>     def index(self):
>         # This displays on the browser only if the database is in a
>         # disk file.  It fails if the database is in memory.
>         return 'Departments: %s' %
> str(entities.Department.query.all())
>     index.exposed = True
>
> cherrypy.quickstart(WebServer())
>
> -----------------------------------------------------
>
> Here is the error that shows in the browser, but only when the
> database is in memory:
>
> File "c:\python25\lib\site-packages\sqlalchemy-0.5.0beta3-py2.5.egg
> \sqlalchemy\engine\base.py", line 946, in _handle_dbapi_exception
>     raise exc.DBAPIError.instance(statement, parameters, e,
> connection_invalidated=is_disconnect)
> OperationalError: (OperationalError) no such table:
> __main___department u'SELECT __main___department.id AS
> __main___department_id, __main___department.name AS
> __main___department_name \nFROM __main___department' []
>
> What am I doing wrong?
>
> Thanks.

--~--~---------~--~----~------------~-------~--~----~
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