Hey,

I'm running the following test as I wanted to move my app from using
Sqlite (which works fine) to MySQL

import elixir
from events import *
from entities import *

elixir.metadata.bind = "mysql://my_user:my_p...@localhost/testdb"
elixir.metadata.echo = True
print 'setup...'
elixir.setup_all()
print 'create...'
elixir.create_all()

When I call elixir.create_all() I get the following traceback:

$ python test_mysql.py
setup...
/usr/lib/python2.6/site-packages/elixir/entity.py:412:
SADeprecationWarning: Session.mapper is deprecated.  Please see
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper
for information on how to replicate its behavior.
  *args, **kwargs)
create...
Traceback (most recent call last):
  File "test_mysql.py", line 10, in <module>
    elixir.create_all()
  File "/usr/lib/python2.6/site-packages/elixir/__init__.py", line
127, in create_all
    md.create_all(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/schema.py", line
1811, in create_all
    bind.create(self, checkfirst=checkfirst, tables=tables)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 1129, in create
    self._run_visitor(self.dialect.schemagenerator, entity,
connection=connection, **kwargs)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 1158, in _run_visitor
    visitorcallable(self.dialect, conn, **kwargs).traverse(element)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py",
line 89, in traverse
    return traverse(obj, self.__traverse_options__,
self._visitor_dict)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py",
line 200, in traverse
    return traverse_using(iterate(obj, opts), obj, visitors)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py",
line 194, in traverse_using
    meth(target)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/sql/compiler.py",
line 831, in visit_metadata
    self.traverse_single(table)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py",
line 79, in traverse_single
    return meth(obj)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/sql/compiler.py",
line 870, in visit_table
    self.execute()
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 1812, in execute
    return self.connection.execute(self.buffer.getvalue())
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 824, in execute
    return Connection.executors[c](self, object, multiparams, params)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 888, in _execute_text
    return self.__execute_context(context)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 896, in __execute_context
    self._cursor_execute(context.cursor, context.statement,
context.parameters[0], context=context)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 950, in _cursor_execute
    self._handle_dbapi_exception(e, statement, parameters, cursor,
context)
  File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
line 931, in _handle_dbapi_exception
    raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, "You have
an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ' \n\tstart
INTEGER, \n\tsize INTEGER, \n\tlow_addr INTEGER, \n\thigh_addr
INTEGER, \n\tent' at line 4") '\nCREATE TABLE entities_image (\n
\tentity_id INTEGER NOT NULL, \n\tid INTEGER, \n\tname VARCHAR, \n
\tstart INTEGER, \n\tsize INTEGER, \n\tlow_addr INTEGER, \n\thigh_addr
INTEGER, \n\tentry INTEGER, \n\tPRIMARY KEY (entity_id), \n\t FOREIGN
KEY(entity_id) REFERENCES entities_entity (id) ON DELETE cascade\n)\n
\n' ()

I'm guessing there is some error in the translation of my Python class
'Image' into a CREATE TABLE request acceptable by MySQL. Here is that
entities.py file for the sake of completeness (I can upload the
events.py file as well if needed):

$ cat entities.py
import elixir
from elixir import Field, ManyToOne, OneToMany, using_options
from elixir import Boolean, String, Integer

FUNCTION = 1
IMAGE = 2

class Entity(elixir.Entity):
    using_options(inheritance='multi')
    active = Field(Boolean)

    def __init__(self):
        self.active = True

class Function(Entity):

    using_options(inheritance='multi')
    addr = Field(Integer)
    name = Field(String)
    size = Field(Integer)
    img = ManyToOne('Image')
    calls = OneToMany('FunctionCall', inverse='src_func')
    called_by = OneToMany('FunctionCall', inverse='dst_func')

    def __init__(self, addr, name='', size=0x0):
        super(Function, self).__init__()

        self.addr = addr
        self.name = name
        self.size = size

        imgs = Image.query.filter(Image.low_addr <= self.addr)
        imgs = imgs.filter(Image.high_addr >= self.addr).all()

        if len(imgs) > 1:
            raise Exception("Multiple images occupying the range 0x
%x-0x%x" % \
                    (imgs[0].low_addr, imgs[0].high_addr))
        elif len(imgs) == 1:
            self.img = imgs[0]
        else:
            raise Exception("Attempting to reference a function (0x%x)
that isn't part of any loaded image" % addr)


class Image(Entity):

    ID_KEY = 'img_id'
    NAME_KEY = 'img_name'
    START_ADDR_KEY = 'start_addr'
    SIZE_KEY = 'size'
    LOW_ADDR_KEY = 'low_addr'
    HIGH_ADDR_KEY = 'high_addr'
    ENTRY_KEY = 'entry'

    using_options(inheritance='multi')
    id = Field(Integer)
    name = Field(String)
    start = Field(Integer)
    size = Field(Integer)
    low_addr = Field(Integer)
    high_addr = Field(Integer)
    entry = Field(Integer)
    functions = OneToMany('Function')
    loads = OneToMany('ImageLoad')

    def __init__(self, img_id, name, start, size, low_addr, high_addr,
entry):
        super(Image, self).__init__()

        self.img_id = id
        self.name= name
        self.start = start
        self.size = size
        self.low_addr = low_addr
        self.high_addr = high_addr
        self.entry = entry

Any help/suggestions are appreciated. I'm using Python 2.5, SqlAlchemy
0.5.8 and Elixir 0.6.1.

Cheers :)

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