[sqlalchemy] PG8000 UnicodeDecodeError
So, I'm using PG8000 1.07 and SqlAlchemy 0.6beta1dev_r6718 and I get this error: UnicodeDecodeError: 'ascii' codec can't decode byte 0x8d in position 3: ordinal not in range(128) I saw a past message about this same thing that said to use a newer version of PG8000 Well, as far as I can tell, version 1.07 should be new enough right? Also, I have the following version of SQLAlchemy: SQLAlchemy-0.6beta1dev_r6718-py2.6.egg And finally, some code: from elixir import * metadata.bind = "postgresql+pg8000://postgres:p...@localhost:port/db" class Table(Entity): entry_date = Field(DateTime, primary_key=True) setup_all() create_all() And, the error: Traceback (most recent call last): File "database.py", line 36, in create_all() File "...Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixi r\__init__.py", line 76, in create_all File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\schema.py", line 1934, in create_all bind.create(self, checkfirst=checkfirst, tables=tables) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\base.py", line 1393, in create self._run_visitor(ddl.SchemaGenerator, entity, connection=connection, **kwar gs) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\base.py", line 1424, in _run_visitor visitorcallable(self.dialect, conn, **kwargs).traverse(element) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\sql\visitors.py", line 86, in traverse return traverse(obj, self.__traverse_options__, self._visitor_dict) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\sql\visitors.py", line 197, in traverse return traverse_using(iterate(obj, opts), obj, visitors) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\sql\visitors.py", line 191, in traverse_using meth(target) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\ddl.py", line 36, in visit_metadata collection = [t for t in sql_util.sort_tables(tables) if self._can_create(t) ] File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\ddl.py", line 29, in _can_create return not self.checkfirst or not self.dialect.has_table(self.connection, ta ble.name, schema=table.schema) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\dialects\postgresql\base.py", line 655, in has_table type_=sqltypes.Unicode)] File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\base.py", line 1035, in execute return Connection.executors[c](self, object, multiparams, params) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\base.py", line 1097, in _execute_clauseelement return self.__execute_context(context) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\base.py", line 1120, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0 ], context=context) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\base.py", line 1180, in _cursor_execute self.dialect.do_execute(cursor, statement, parameters, context=context) File "...Python\lib\site-packages\sqlalchemy-0.6beta1dev_r6718 -py2.6.egg\sqlalchemy\engine\default.py", line 220, in do_execute cursor.execute(statement, parameters) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\dbapi .py", line 243, in _fn return fn(self, *args, **kwargs) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\dbapi .py", line 312, in execute self._execute(operation, args) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\dbapi .py", line 317, in _execute self.cursor.execute(new_query, *new_args) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\inter face.py", line 303, in execute self._stmt = PreparedStatement(self.connection, query, statement_name="", *[ {"type": type(x), "value": x} for x in args]) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\inter face.py", line 108, in __init__ self._parse_row_desc = self.c.parse(self._statement_name, statement, types) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\proto col.py", line 918, in _fn return fn(self, *args, **kwargs) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\proto col.py", line 1069, in parse self._send(Parse(statement, qs, param_types)) File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\proto col.py", line 975, in _send data = msg.serialize() File "...Python\lib\site-packages\pg8000-1.07.egg\pg8000\proto col.py", line 121, in serialize val = struct.pack("!i", len(val) + 4) + val UnicodeDecodeError: 'ascii' codec can't decode byte 0x8d in positi
[sqlalchemy] Re: 0.6b1 and pymssql
I've been using pymssql for years. There's no special reason. If this means the end of pymssql in sqlalchemy I have no problem, I'll change to pyodbc. Thanks for your help. On Feb 5, 9:21 pm, Michael Bayer wrote: > On Feb 5, 2010, at 10:18 PM, Domingo Aguilera wrote: > > > > > > > After r6731 > > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > > __init__.py", line 223, in create_engine > > return strategy.create(*args, **kwargs) > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > > strategies.py", line 65, in create > > dialect = dialect_cls(**dialect_args) > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ > > mssql/pymssql.py", line 25, in __init__ > > super(MSDialect_pymssql, self).__init__(**params) > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ > > mssql/base.py", line 1121, in __init__ > > super(MSDialect, self).__init__(**opts) > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > > default.py", line 89, in __init__ > > self.paramstyle = self.dbapi.paramstyle > > AttributeError: 'module' object has no attribute 'paramstyle' > > thats a pymssql bug. DBAPI requires this param to be present. > > Whats the reason you can't just use pyodbc ? > > > > > > > On Feb 5, 7:36 pm, Michael Bayer wrote: > >> r 6731. > > >> sorry i dont have pymssql installed to test these extremely trivial > >> glitches > > >> On Feb 5, 2010, at 7:17 PM, Domingo Aguilera wrote: > > >>> Michael, > > >>> after testing r6730 this is what I gethttp://gist.github.com/296416 > > >>> stack trace > > >>> File "prueba.py", line 3, in > >>> engine = sa.create_engine("mssql+pymssql://foo/b...@host/pruebas" ) > >>> File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > >>> __init__.py", line 223, in create_engine > >>> return strategy.create(*args, **kwargs) > >>> File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > >>> strategies.py", line 65, in create > >>> dialect = dialect_cls(**dialect_args) > >>> File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ > >>> mssql/pymssql.py", line 25, in __init__ > >>> super(MSSQLDialect_pymssql, self).__init__(**params) > >>> NameError: global name 'MSSQLDialect_pymssql' is not defined > > >>> On Feb 4, 7:12 am, Michael Bayer wrote: > On Feb 4, 2010, at 1:13 AM, Domingo Aguilera wrote: > > > I am trying to use 0.6b1 with pymssql ( latest version 1.0.2 ). For > > it I use create_engine with an uri like mssql+pymssql:// > > > It seems 0.6b1 looks for a dbapi attribute that is not present in > > pymssql. Is there a workaround for this? > > theres two things going on there. one is that pymssql has been > rewritten recently. well, thats actually pretty much it - we havent > done any testing with pymssql. If you can provide details we can > commit a patch. In 0.6 we can probably just shoot for supporting the > "new" pymssql since its supposed to be much better than the old. > > > Tks. > > > -- > > You received this message because you are subscribed to the Google > > Groups "sqlalchemy" group. > > To post to this group, send email to sqlalch...@googlegroups.com. > > To unsubscribe from this group, send email to > > sqlalchemy+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/sqlalchemy?hl=en. > > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "sqlalchemy" group. > >>> To post to this group, send email to sqlalch...@googlegroups.com. > >>> To unsubscribe from this group, send email to > >>> sqlalchemy+unsubscr...@googlegroups.com. > >>> For more options, visit this group > >>> athttp://groups.google.com/group/sqlalchemy?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "sqlalchemy" group. > > To post to this group, send email to sqlalch...@googlegroups.com. > > To unsubscribe from this group, send email to > > sqlalchemy+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: 0.6b1 and pymssql
On Feb 5, 2010, at 10:18 PM, Domingo Aguilera wrote: > After r6731 > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > __init__.py", line 223, in create_engine >return strategy.create(*args, **kwargs) > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > strategies.py", line 65, in create >dialect = dialect_cls(**dialect_args) > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ > mssql/pymssql.py", line 25, in __init__ >super(MSDialect_pymssql, self).__init__(**params) > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ > mssql/base.py", line 1121, in __init__ >super(MSDialect, self).__init__(**opts) > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > default.py", line 89, in __init__ >self.paramstyle = self.dbapi.paramstyle > AttributeError: 'module' object has no attribute 'paramstyle' thats a pymssql bug. DBAPI requires this param to be present. Whats the reason you can't just use pyodbc ? > > On Feb 5, 7:36 pm, Michael Bayer wrote: >> r 6731. >> >> sorry i dont have pymssql installed to test these extremely trivial glitches >> >> On Feb 5, 2010, at 7:17 PM, Domingo Aguilera wrote: >> >> >> >>> Michael, >> >>> after testing r6730 this is what I gethttp://gist.github.com/296416 >> >>> stack trace >> >>> File "prueba.py", line 3, in >>>engine = sa.create_engine("mssql+pymssql://foo/b...@host/pruebas" ) >>> File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ >>> __init__.py", line 223, in create_engine >>>return strategy.create(*args, **kwargs) >>> File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ >>> strategies.py", line 65, in create >>>dialect = dialect_cls(**dialect_args) >>> File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ >>> mssql/pymssql.py", line 25, in __init__ >>>super(MSSQLDialect_pymssql, self).__init__(**params) >>> NameError: global name 'MSSQLDialect_pymssql' is not defined >> >>> On Feb 4, 7:12 am, Michael Bayer wrote: On Feb 4, 2010, at 1:13 AM, Domingo Aguilera wrote: >> > I am trying to use 0.6b1 with pymssql ( latest version 1.0.2 ). For > it I use create_engine with an uri like mssql+pymssql:// >> > It seems 0.6b1 looks for a dbapi attribute that is not present in > pymssql. Is there a workaround for this? >> theres two things going on there. one is that pymssql has been rewritten recently. well, thats actually pretty much it - we havent done any testing with pymssql.If you can provide details we can commit a patch. In 0.6 we can probably just shoot for supporting the "new" pymssql since its supposed to be much better than the old. >> > Tks. >> > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/sqlalchemy?hl=en. >> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To post to this group, send email to sqlalch...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> sqlalchemy+unsubscr...@googlegroups.com. >>> For more options, visit this group >>> athttp://groups.google.com/group/sqlalchemy?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: 0.6b1 and pymssql
After r6731 File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ __init__.py", line 223, in create_engine return strategy.create(*args, **kwargs) File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ strategies.py", line 65, in create dialect = dialect_cls(**dialect_args) File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ mssql/pymssql.py", line 25, in __init__ super(MSDialect_pymssql, self).__init__(**params) File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ mssql/base.py", line 1121, in __init__ super(MSDialect, self).__init__(**opts) File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ default.py", line 89, in __init__ self.paramstyle = self.dbapi.paramstyle AttributeError: 'module' object has no attribute 'paramstyle' On Feb 5, 7:36 pm, Michael Bayer wrote: > r 6731. > > sorry i dont have pymssql installed to test these extremely trivial glitches > > On Feb 5, 2010, at 7:17 PM, Domingo Aguilera wrote: > > > > > Michael, > > > after testing r6730 this is what I gethttp://gist.github.com/296416 > > > stack trace > > > File "prueba.py", line 3, in > > engine = sa.create_engine("mssql+pymssql://foo/b...@host/pruebas" ) > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > > __init__.py", line 223, in create_engine > > return strategy.create(*args, **kwargs) > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > > strategies.py", line 65, in create > > dialect = dialect_cls(**dialect_args) > > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ > > mssql/pymssql.py", line 25, in __init__ > > super(MSSQLDialect_pymssql, self).__init__(**params) > > NameError: global name 'MSSQLDialect_pymssql' is not defined > > > On Feb 4, 7:12 am, Michael Bayer wrote: > >> On Feb 4, 2010, at 1:13 AM, Domingo Aguilera wrote: > > >>> I am trying to use 0.6b1 with pymssql ( latest version 1.0.2 ). For > >>> it I use create_engine with an uri like mssql+pymssql:// > > >>> It seems 0.6b1 looks for a dbapi attribute that is not present in > >>> pymssql. Is there a workaround for this? > > >> theres two things going on there. one is that pymssql has been rewritten > >> recently. well, thats actually pretty much it - we havent done any > >> testing with pymssql. If you can provide details we can commit a patch. > >> In 0.6 we can probably just shoot for supporting the "new" pymssql since > >> its supposed to be much better than the old. > > >>> Tks. > > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "sqlalchemy" group. > >>> To post to this group, send email to sqlalch...@googlegroups.com. > >>> To unsubscribe from this group, send email to > >>> sqlalchemy+unsubscr...@googlegroups.com. > >>> For more options, visit this group > >>> athttp://groups.google.com/group/sqlalchemy?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "sqlalchemy" group. > > To post to this group, send email to sqlalch...@googlegroups.com. > > To unsubscribe from this group, send email to > > sqlalchemy+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy with Central DB & Shards
On Feb 5, 2010, at 7:37 PM, En Snare wrote: > This is my current code with the error I keep receiving: > > class Central(): > >def __init__(self,id): > >self.db = create_engine('sqlite:Users/adam/topic/central.db') >self.db.echo = False >self.metadata = MetaData(self.db) >self.session = scoped_session(sessionmaker(bind=self.db)) > > > s = DBConnect.Central(1) s.id = 5 s.session.add(s) > sqlalchemy.orm.exc.UnmappedInstanceError: Class '__builtin__.instance' > is not mapped > > Any pointers to get back on track would be greatly appreciated. I think before you start getting into the sharding example you should get a basic understanding of classes and mappings. Above, youd want Central to be mapped and you'd also be doing all the stuff with engines/metadata/sessions outside of your class, at the module level since that stuff should happen only once when your app starts up. The ORM tutorial moves pretty quickly and youd get the idea of how to define table metadata and mappings at http://www.sqlalchemy.org/docs/ormtutorial.html . SQLAlchemy does have a bit of a learning curve and time spent with the tutorial will ultimately save you a lot of time later on, if you're planning to use SQLA effectively. > > > > > On Fri, Feb 5, 2010 at 6:25 PM, En Snare wrote: >> Hi Michael -- Thanks. I took a look through the code but am having >> trouble instantiating the database objects from within a class. Is >> there any sample code that shows how this is done? >> >> - En >> >> On Fri, Feb 5, 2010 at 4:13 PM, Michael Bayer >> wrote: >>> En Snare wrote: I'm new to Python and am trying to get a sense of SQLAlchemy, particularly how to get it to work with our database infrastructure. I followed the Shard tutorial but didn't find it helpful for a beginner switching to this infrastructure. We have a central database that stores the locations of our shards. I would like to create a class that initiates a connection to the Central database only when necessary. As well as one that connects directly to a specific shard when supplied with an id. For example: class Central(): def __init__(self): //Connect to Central DB class Shard(): def __init__(self,id): //Connect to Central DB and fetch the connection info for the shard that contains user with id //Connect to that shard What is the proper way of doing something like this? Any sample code is greatly appreciated. Thank you. >>> >>> the sample code we have for sharding is in the downloaded SQLAlchemy >>> distribution in examples/sharding. We follow roughly the same sharding >>> model as that of Hibernate. >>> >>> >>> -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To post to this group, send email to sqlalch...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> sqlalchemy+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/sqlalchemy?hl=en. >>> >>> >> > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: 0.6b1 and pymssql
r 6731. sorry i dont have pymssql installed to test these extremely trivial glitches On Feb 5, 2010, at 7:17 PM, Domingo Aguilera wrote: > Michael, > > after testing r6730 this is what I get http://gist.github.com/296416 > > stack trace > > File "prueba.py", line 3, in >engine = sa.create_engine("mssql+pymssql://foo/b...@host/pruebas" ) > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > __init__.py", line 223, in create_engine >return strategy.create(*args, **kwargs) > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ > strategies.py", line 65, in create >dialect = dialect_cls(**dialect_args) > File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ > mssql/pymssql.py", line 25, in __init__ >super(MSSQLDialect_pymssql, self).__init__(**params) > NameError: global name 'MSSQLDialect_pymssql' is not defined > > On Feb 4, 7:12 am, Michael Bayer wrote: >> On Feb 4, 2010, at 1:13 AM, Domingo Aguilera wrote: >> >>> I am trying to use 0.6b1 with pymssql ( latest version 1.0.2 ). For >>> it I use create_engine with an uri like mssql+pymssql:// >> >>> It seems 0.6b1 looks for a dbapi attribute that is not present in >>> pymssql. Is there a workaround for this? >> >> theres two things going on there. one is that pymssql has been rewritten >> recently. well, thats actually pretty much it - we havent done any testing >> with pymssql.If you can provide details we can commit a patch. In 0.6 >> we can probably just shoot for supporting the "new" pymssql since its >> supposed to be much better than the old. >> >> >> >> >> >>> Tks. >> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To post to this group, send email to sqlalch...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> sqlalchemy+unsubscr...@googlegroups.com. >>> For more options, visit this group >>> athttp://groups.google.com/group/sqlalchemy?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy with Central DB & Shards
This is my current code with the error I keep receiving: class Central(): def __init__(self,id): self.db = create_engine('sqlite:Users/adam/topic/central.db') self.db.echo = False self.metadata = MetaData(self.db) self.session = scoped_session(sessionmaker(bind=self.db)) >>>s = DBConnect.Central(1) >>>s.id = 5 >>>s.session.add(s) sqlalchemy.orm.exc.UnmappedInstanceError: Class '__builtin__.instance' is not mapped Any pointers to get back on track would be greatly appreciated. On Fri, Feb 5, 2010 at 6:25 PM, En Snare wrote: > Hi Michael -- Thanks. I took a look through the code but am having > trouble instantiating the database objects from within a class. Is > there any sample code that shows how this is done? > > - En > > On Fri, Feb 5, 2010 at 4:13 PM, Michael Bayer > wrote: >> En Snare wrote: >>> I'm new to Python and am trying to get a sense of SQLAlchemy, >>> particularly how to get it to work with our database infrastructure. >>> I followed the Shard tutorial but didn't find it helpful for a >>> beginner switching to this infrastructure. >>> >>> We have a central database that stores the locations of our shards. I >>> would like to create a class that initiates a connection to the >>> Central database only when necessary. As well as one that connects >>> directly to a specific shard when supplied with an id. >>> >>> For example: >>> >>> class Central(): >>> >>> def __init__(self): >>> >>> //Connect to Central DB >>> >>> >>> class Shard(): >>> def __init__(self,id): >>> >>> //Connect to Central DB and fetch the connection info for the >>> shard that contains user with id >>> >>> //Connect to that shard >>> >>> >>> What is the proper way of doing something like this? Any sample code >>> is greatly appreciated. Thank you. >> >> the sample code we have for sharding is in the downloaded SQLAlchemy >> distribution in examples/sharding. We follow roughly the same sharding >> model as that of Hibernate. >> >> >> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To post to this group, send email to sqlalch...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> sqlalchemy+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/sqlalchemy?hl=en. >>> >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to sqlalch...@googlegroups.com. >> To unsubscribe from this group, send email to >> sqlalchemy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. >> >> > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy with Central DB & Shards
Hi Michael -- Thanks. I took a look through the code but am having trouble instantiating the database objects from within a class. Is there any sample code that shows how this is done? - En On Fri, Feb 5, 2010 at 4:13 PM, Michael Bayer wrote: > En Snare wrote: >> I'm new to Python and am trying to get a sense of SQLAlchemy, >> particularly how to get it to work with our database infrastructure. >> I followed the Shard tutorial but didn't find it helpful for a >> beginner switching to this infrastructure. >> >> We have a central database that stores the locations of our shards. I >> would like to create a class that initiates a connection to the >> Central database only when necessary. As well as one that connects >> directly to a specific shard when supplied with an id. >> >> For example: >> >> class Central(): >> >> def __init__(self): >> >> //Connect to Central DB >> >> >> class Shard(): >> def __init__(self,id): >> >> //Connect to Central DB and fetch the connection info for the >> shard that contains user with id >> >> //Connect to that shard >> >> >> What is the proper way of doing something like this? Any sample code >> is greatly appreciated. Thank you. > > the sample code we have for sharding is in the downloaded SQLAlchemy > distribution in examples/sharding. We follow roughly the same sharding > model as that of Hibernate. > > > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to sqlalch...@googlegroups.com. >> To unsubscribe from this group, send email to >> sqlalchemy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: 0.6b1 and pymssql
Michael, after testing r6730 this is what I get http://gist.github.com/296416 stack trace File "prueba.py", line 3, in engine = sa.create_engine("mssql+pymssql://foo/b...@host/pruebas" ) File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ __init__.py", line 223, in create_engine return strategy.create(*args, **kwargs) File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/engine/ strategies.py", line 65, in create dialect = dialect_cls(**dialect_args) File "/home/smartics/myenv/src/sqlalchemy/lib/sqlalchemy/dialects/ mssql/pymssql.py", line 25, in __init__ super(MSSQLDialect_pymssql, self).__init__(**params) NameError: global name 'MSSQLDialect_pymssql' is not defined On Feb 4, 7:12 am, Michael Bayer wrote: > On Feb 4, 2010, at 1:13 AM, Domingo Aguilera wrote: > > > I am trying to use 0.6b1 with pymssql ( latest version 1.0.2 ). For > > it I use create_engine with an uri like mssql+pymssql:// > > > It seems 0.6b1 looks for a dbapi attribute that is not present in > > pymssql. Is there a workaround for this? > > theres two things going on there. one is that pymssql has been rewritten > recently. well, thats actually pretty much it - we havent done any testing > with pymssql. If you can provide details we can commit a patch. In 0.6 > we can probably just shoot for supporting the "new" pymssql since its > supposed to be much better than the old. > > > > > > > Tks. > > > -- > > You received this message because you are subscribed to the Google Groups > > "sqlalchemy" group. > > To post to this group, send email to sqlalch...@googlegroups.com. > > To unsubscribe from this group, send email to > > sqlalchemy+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy with Central DB & Shards
En Snare wrote: > I'm new to Python and am trying to get a sense of SQLAlchemy, > particularly how to get it to work with our database infrastructure. > I followed the Shard tutorial but didn't find it helpful for a > beginner switching to this infrastructure. > > We have a central database that stores the locations of our shards. I > would like to create a class that initiates a connection to the > Central database only when necessary. As well as one that connects > directly to a specific shard when supplied with an id. > > For example: > > class Central(): > > def __init__(self): > > //Connect to Central DB > > > class Shard(): > def __init__(self,id): > > //Connect to Central DB and fetch the connection info for the > shard that contains user with id > > //Connect to that shard > > > What is the proper way of doing something like this? Any sample code > is greatly appreciated. Thank you. the sample code we have for sharding is in the downloaded SQLAlchemy distribution in examples/sharding. We follow roughly the same sharding model as that of Hibernate. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] SQLAlchemy with Central DB & Shards
I'm new to Python and am trying to get a sense of SQLAlchemy, particularly how to get it to work with our database infrastructure. I followed the Shard tutorial but didn't find it helpful for a beginner switching to this infrastructure. We have a central database that stores the locations of our shards. I would like to create a class that initiates a connection to the Central database only when necessary. As well as one that connects directly to a specific shard when supplied with an id. For example: class Central(): def __init__(self): //Connect to Central DB class Shard(): def __init__(self,id): //Connect to Central DB and fetch the connection info for the shard that contains user with id //Connect to that shard What is the proper way of doing something like this? Any sample code is greatly appreciated. Thank you. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] eagerload -- unknown column None in field list
diana wrote: > I only seem to get this error when I I try to eager load a child > collection -- eager loading one child item works fine. > > I've tried: > > lazy=False on the relation > > as well as eagerload on the query: > > query.options(eagerload('foo')) > > but each time I get: > > (OperationalError) (1054, "Unknown column 'None' in 'field list'") > > Any ideas off the top your head? > > PS. I can traverse lazily to the child collection, no problem. never seen that before nope. probably something to do with your primaryjoin though. > > Cheers, > > --diana > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] eagerload -- unknown column None in field list
I only seem to get this error when I I try to eager load a child collection -- eager loading one child item works fine. I've tried: lazy=False on the relation as well as eagerload on the query: query.options(eagerload('foo')) but each time I get: (OperationalError) (1054, "Unknown column 'None' in 'field list'") Any ideas off the top your head? PS. I can traverse lazily to the child collection, no problem. Cheers, --diana -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] AttributeError: 'MySQLCompiler' object has no attribute 'mapped_table'
Hi Michael, On 02/05/2010 04:16 PM, Michael Bayer wrote: > Simone Orsi wrote: > >> Hi all, >> can anybody explain why this: >> >> session.query(Answer).all() -> [> >> works, but this: >> >> session.query(func.sum(Answer.close_answer1)).all() >> >> throws the following error? >> >> *** AttributeError: 'MySQLCompiler' object has no attribute >> 'mapped_table' >> >> The class 'Answer' is mapped correctly since I can search/insert/ >> update any records. >> >> Thanks in advance >> >> PS: sqlalchemy-0.5.8 >> > there is likely an object being passed to the library at some point > incorrectly.Can't go any further without a complete stack trace. > > here's the class class Answer(object): def __init__(self, **kwargs): self.title = kwargs.get('title') self.isMandatory = kwargs.get('isMandatory') self.qtype = kwargs.get('qtype') self.close_answer1 = kwargs.get('close_answer1') self.close_answer2 = kwargs.get('close_answer2') self.close_answer3 = kwargs.get('close_answer3') self.close_answer4 = kwargs.get('close_answer4') self.close_answer5 = kwargs.get('close_answer5') self.close_answer0 = kwargs.get('close_answer0') self.open_answer = kwargs.get('open_answer') def __repr__(self): return "" % (self.title) the table tables['answers_table'] = Table('answers', metadata, Column('id', Integer, primary_key=True), Column('title', String), Column('isMandatory', Boolean), Column('qtype', String), Column('close_answer1', Integer, default=0), Column('close_answer2', Integer, default=0), Column('close_answer3', Integer, default=0), Column('close_answer4', Integer, default=0), Column('close_answer5', Integer, default=0), Column('close_answer0', Integer, default=0), Column('open_answer', Text), Column('question', Integer, ForeignKey('questions.id')), Column('questionnaire', Integer, ForeignKey('questionnaires.id')), ) and the mapper mappers['answers_table'] = sa.orm.mapper(Answer, tables['answers_table'], allow_column_override=True, properties = { '_question' : sa.orm.relation(Question), '_questionnaire' : sa.orm.relation(Questionnaire), }) What I'm tryin to do is to take the sum of every column "column_answer*" for the entire table. As I said I can do this session.query(Answer).filter_by(questionnaire=questionnaire_sql_id,qtype='closed').all() as well as other operations w/ that class but when I try to do this sum = session.query([func.sum(Answer.close_answer1), ...]).filter_by(questionnaire=questionnaire_sql_id,qtype='closed').all() no way... here's the log: [...] Module sqlalchemy.orm.session, line 763, in query Module sqlalchemy.orm.query, line 68, in __init__ Module sqlalchemy.orm.query, line 74, in __init_mapper AttributeError: 'MySQLCompiler' object has no attribute 'mapped_table' Previous lines are Plone-related thus unuseful in this case... -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] exceptions.TypeError: bad operand type for unary -: 'InstrumentedAttribute'
Chris Withers wrote: > Michael Bayer wrote: >> Chris Withers wrote: >>> Hi All, >>> >>> When will InstrumentedAttribute support unary minus? >>> >>> Feels clunky having to write -1*field ;-) >> >> nobody ever asked. r6727. > > Cool, thanks :-) > > When will r6727 land? 0.6 or 0.7? 0.6beta2. > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] exceptions.TypeError: bad operand type for unary -: 'InstrumentedAttribute'
Michael Bayer wrote: Chris Withers wrote: Hi All, When will InstrumentedAttribute support unary minus? Feels clunky having to write -1*field ;-) nobody ever asked. r6727. Cool, thanks :-) When will r6727 land? 0.6 or 0.7? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] exceptions.TypeError: bad operand type for unary -: 'InstrumentedAttribute'
Chris Withers wrote: > Hi All, > > When will InstrumentedAttribute support unary minus? > > Feels clunky having to write -1*field ;-) nobody ever asked. r6727. > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] manytomany optimisations
Excellent thanks, I had looked at this before but not got it work. The following now works: query.options(eagerload_all("parents"),eagerload_all("children")).all() Cheers, Andrew On 5 February 2010 08:38, Gaetan de Menten wrote: > On Thu, Feb 4, 2010 at 17:25, Andrew wrote: > > > I have a table of "tasks" which contain references to multiple > > children and parents (tasks can have multiple children and multiple > > parents in this example). These are defined as ManyToMany and so I get > > an extra table containing the links. > > > > If I select all tasks, how can I then see a particular tasks children > > without sqlalchemy making another query every time. > > I have a case where I want to get a list of say 500 tasks and their > > children but end up with 500 extra queries. > > Search for "eagerloading"/lazy=False in the documentation. You can > configure it either on the relation, or on the query. > > HTH, > -- > Gaëtan de Menten > http://openhex.org > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] AttributeError: 'MySQLCompiler' object has no attribute 'mapped_table'
Simone Orsi wrote: > Hi all, > can anybody explain why this: > > session.query(Answer).all() -> [ > works, but this: > > session.query(func.sum(Answer.close_answer1)).all() > > throws the following error? > > *** AttributeError: 'MySQLCompiler' object has no attribute > 'mapped_table' > > The class 'Answer' is mapped correctly since I can search/insert/ > update any records. > > Thanks in advance > > PS: sqlalchemy-0.5.8 there is likely an object being passed to the library at some point incorrectly.Can't go any further without a complete stack trace. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] exceptions.TypeError: bad operand type for unary -: 'InstrumentedAttribute'
Hi All, When will InstrumentedAttribute support unary minus? Feels clunky having to write -1*field ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] AttributeError: 'MySQLCompiler' object has no attribute 'mapped_table'
Hi all, can anybody explain why this: session.query(Answer).all() -> [http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] manytomany optimisations
On Thu, Feb 4, 2010 at 17:25, Andrew wrote: > I have a table of "tasks" which contain references to multiple > children and parents (tasks can have multiple children and multiple > parents in this example). These are defined as ManyToMany and so I get > an extra table containing the links. > > If I select all tasks, how can I then see a particular tasks children > without sqlalchemy making another query every time. > I have a case where I want to get a list of say 500 tasks and their > children but end up with 500 extra queries. Search for "eagerloading"/lazy=False in the documentation. You can configure it either on the relation, or on the query. HTH, -- Gaëtan de Menten http://openhex.org -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] 0.6b1 - meta.create_all with FB
On 05/02/2010 00:27, Michael Bayer wrote: On Feb 4, 2010, at 3:39 PM, werner wrote: OK i see the point about the constructor, though I want to get across that yes the constructor is optional with declarative, but you can still make one. Could the constructor be done in a similar way as you suggested to do the "__repr__"? it certainly can, but I'm really trying to make the tutorial look like "regular Python objects like any Python beginner is familiar with". you'd be surprised how thrown off people get even by a simple "for k in kwargs: setattr(k, kwargs[k])" type of thing. No I woudn't as I am one of them :-) , also by now I can figure this one out. Thanks for the doc change, now even I will not overlook that section when I browse over the doc instead of reading it. :-[ Werner -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: mapper class with multiple tables
Hi I found a solution: orm.mapper(AccAccountUserAddress, acc_account_table.join(acc_user_table).join(acc_address_book_table), properties={ 'account_id': [ acc_account_table.c.account_id, acc_user_table.c.account_id, acc_address_book_table.c.account_id]} ) Now its working. Thanks, Thomas -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.