[sqlalchemy] Sharded query stops working with 0.4.6

2008-06-06 Thread Andrew Stromnov

After upgrading from 0.4.5 to 0.4.6 Session.execute(query,
shard_id=shard_id),
where Session is ShardedSession, throws exception:

File '/var/lib/python-support/python2.5/sqlalchemy/orm/scoping.py',
line 98 in do
  return getattr(self.registry(), name)(*args, **kwargs)
TypeError: execute() got an unexpected keyword argument 'shard_id'
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: expensive .rollback() in pool implementation?

2008-05-05 Thread Andrew Stromnov

Ordered by: internal time
List reduced from 178 to 20 due to restriction 20

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
# 2150.3710.0020.3710.002 {method 'query' of
'_mysql.connection' objects}
*  2150.3060.0010.3060.001 {method 'rollback' of
'_mysql.connection' objects}
   2150.0290.0000.0290.000 {method 'store_result' of
'_mysql.connection' objects}
   2150.0280.0000.0480.000 sqlalchemy/engine/base.py:
1425(_init_metadata)
   2150.0220.0000.0220.000 {method 'next_result' of
'_mysql.connection' objects}
   2320.0200.0000.2460.001 utils.py:278(new_fun)
   2320.0170.0001.3050.006 RecentActions.py:
197(GetCounter)
   2150.0130.0000.4980.002 MySQLdb/cursors.py:
129(execute)
   2150.0120.0000.0500.000 MySQLdb/cursors.py:
107(_do_get_result)
   2110.0110.0000.0370.000 decimal.py:516(__new__)
   2150.0090.0000.0360.000 sqlalchemy/engine/
default.py:136(__init__)
   2320.0090.0001.3150.006 utils.py:178(protected)
   2150.0080.0000.0090.000 MySQLdb/cursors.py:
40(__init__)
   4300.0080.0000.0140.000 threading.py:93(acquire)
   6410.0080.0000.0080.000 {built-in method match}
   2110.0060.0000.0140.000 decimal.py:
3092(_string2exact)
* 2150.0060.0000.3460.002 sqlalchemy/pool.py:
276(_finalize_fairy)
   2150.0060.0000.6130.003 sqlalchemy/engine/base.py:
853(_execute_text)
   6620.0060.0000.0060.000 logging/__init__.py:
1158(getEffectiveLevel)

This is cumulative log for 215 requests. '#' - query to DB, '*' -
returning connection to the pool.
Times for query() and rollback() execution are comparable.

Query is SELECT person_id, type, sum(count) FROM CommentCounter WHERE
person = %d AND type = '%s' and answered in (0, 1) group by person_id

On May 4, 7:52 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On May 4, 2008, at 9:41 AM, Andrew Stromnov wrote:



  Recently I'd switched to SA MySQL connection pool implementation.
  Every time, when app returns connection to pool (through .close()
  method), SA triggers .rollback() on this connection (http://
 www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/lib/sqlalchemy/pool)
  .
  In my case ROLLBACK is rather expensive operation and waste too much
  MySQL time. I'm using MySQL 5.1 and set autocommit=1 on
  initialization.

  How to disable this .rollback() triggering?

 its necessary so that any transactional state existing on the  
 connection is discarded.   autocommit=1 is not part of DBAPI so SQLA  
 is not built around that modelbut even if it is switched on, it  
 says nothing about table or row locks which may exist on the  
 connection which also would need to be released via ROLLBACK.

 do you have any profiling data that illustrate ROLLBACK being  
 expensive ?  its generally an extremely cheap operation particularly  
 if little or no state has been built up on the connection.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] expensive .rollback() in pool implementation?

2008-05-04 Thread Andrew Stromnov

Recently I'd switched to SA MySQL connection pool implementation.
Every time, when app returns connection to pool (through .close()
method), SA triggers .rollback() on this connection (http://
www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/lib/sqlalchemy/pool.py#L291).
In my case ROLLBACK is rather expensive operation and waste too much
MySQL time. I'm using MySQL 5.1 and set autocommit=1 on
initialization.

How to disable this .rollback() triggering?


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



[sqlalchemy] SQLAlchemy and SQLRelay

2008-01-14 Thread Andrew Stromnov

Is it possible to use SA with SQLRelay?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Stats implementation question.

2007-12-07 Thread Andrew Stromnov

I think it shoud be done throught mapping against arbitrary select
( 
http://www.sqlalchemy.org/docs/04/documentation.html#advdatamapping_mapper_selects
).

Thanks.

On 7 дек, 13:23, Andrew Stromnov [EMAIL PROTECTED] wrote:
 How to implement this stat behaviour (RPG-like stats):

 players_table = Table('player',
   Column('id', Integer, primary_key=True),
   Column('name', String),
   Column('level', Integer),
 )

 # SELECT 'level', count('level') as 'count' FROM player ORDER BY
 'level' GROUP BY 'level'
 #

 class Stats(object): pass

 mapper(Stats, players_table, include_properties=['level'], properties
 = {
   'count': column_property(  func.count('level).label('count') )

 })

 this fails with error...

 And where 'ORDER BY' and 'GROUP BY' must be placed?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Key error when mapping against arbitrary select

2007-12-07 Thread Andrew Stromnov

persons_table = Table(u'persons', dbconfig.metadata,
Column(u'person_id', Integer(20), primary_key=True,
autoincrement=True, nullable=False, default=0),
Column(u'level', Integer(11), nullable=False, default=1),
autoload = False)

class Person(object):
pass

mapper(Person, persons_table)

stat_by_level = select([Person.level,
func.count(Person.level).label('count')],
order_by=[Person.level],
group_by=[Person.level]).alias('stats')

class StatByLevel(object):
pass

mapper(StatByLevel, stat_by_level)


desktop:~/Projects/test$ python model.py
Traceback (most recent call last):
  File model.py, line 58, in module
mapper(StatByLevel, stat_by_level)
  File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.2dev_r3866-
py2.5.egg/sqlalchemy/orm/__init__.py, line 518, in mapper
return Mapper(class_, local_table, *args, **params)
  File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.2dev_r3866-
py2.5.egg/sqlalchemy/orm/mapper.py, line 153, in __init__
self._compile_pks()
  File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.2dev_r3866-
py2.5.egg/sqlalchemy/orm/mapper.py, line 421, in _compile_pks
if len(self._pks_by_table[self.mapped_table]) == 0:
KeyError: sqlalchemy.sql.expression.Alias object at 0x842c98c

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



[sqlalchemy] Stats implementation question.

2007-12-07 Thread Andrew Stromnov

How to implement this stat behaviour (RPG-like stats):

players_table = Table('player',
  Column('id', Integer, primary_key=True),
  Column('name', String),
  Column('level', Integer),
)

# SELECT 'level', count('level') as 'count' FROM player ORDER BY
'level' GROUP BY 'level'
#

class Stats(object): pass

mapper(Stats, players_table, include_properties=['level'], properties
= {
  'count': column_property(  func.count('level).label('count') )
})

this fails with error...

And where 'ORDER BY' and 'GROUP BY' must be placed?

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



[sqlalchemy] How to use GROUP BY and HAVING in orm?

2007-11-13 Thread Andrew Stromnov

I have this SQL expression (from 
http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html)

SELECT b.*
FROM tagmap bt, bookmark b, tag t
WHERE bt.tag_id = t.tag_id
AND (t.name IN ('bookmark', 'webservice', 'semweb'))
AND b.id = bt.bookmark_id
GROUP BY b.id
HAVING COUNT( b.id )=3

How to implement this HAVING COUNT(b.id) = 3 in ORM?


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



[sqlalchemy] create_instance() documentation typo?

2007-11-08 Thread Andrew Stromnov

At 
http://www.sqlalchemy.org/docs/04/sqlalchemy_orm.html#docstrings_sqlalchemy.orm_MapperExtension
:


def create_instance(self, mapper, selectcontext, row, class_)

Receive a row when a new object instance is about to be created from
that row.

The method can choose to create the instance itself, or it can return
None to indicate normal object creation should take place.



but in code no 'None' value accepted (mapper.py line 1414):

# plugin point
if 'create_instance' in extension.methods:
instance = extension.create_instance(self, context,
row, self.class_)
if instance is EXT_CONTINUE:
instance =
attribute_manager.new_instance(self.class_)
else:
instance = attribute_manager.new_instance(self.class_)

instance._entity_name = self.entity_name


if extension.create_instance() produces None, then last string should
raise AttributeError exception


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



[sqlalchemy] Re: create_instance() documentation typo?

2007-11-08 Thread Andrew Stromnov

Done.

http://www.sqlalchemy.org/trac/ticket/859

On Nov 8, 8:55 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 its a typo.  if you could place a ticket in trac (with milestone
 0.4xx) that would be helpful.

 On Nov 8, 2007, at 12:31 PM, Andrew Stromnov wrote:



  Athttp://www.sqlalchemy.org/docs/04/sqlalchemy_orm.html#docstrings_sqla...
  :

  
  def create_instance(self, mapper, selectcontext, row, class_)

  Receive a row when a new object instance is about to be created from
  that row.

  The method can choose to create the instance itself, or it can return
  None to indicate normal object creation should take place.

  

  but in code no 'None' value accepted (mapper.py line 1414):
  
 # plugin point
 if 'create_instance' in extension.methods:
 instance = extension.create_instance(self, context,
  row, self.class_)
 if instance is EXT_CONTINUE:
 instance =
  attribute_manager.new_instance(self.class_)
 else:
 instance = attribute_manager.new_instance(self.class_)

 instance._entity_name = self.entity_name
  

  if extension.create_instance() produces None, then last string should
  raise AttributeError exception


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



[sqlalchemy] Re: Ascii codec instead of unicode ?

2007-08-15 Thread Andrew Stromnov

Hi,

I have two questions:

  1) what exact versions of MySQL (i.e. 4.1.22) and py-mysqldb?

  2) how many databases and/or tables (an encodings) used in your
application?

On Aug 15, 9:57 pm, Arun Kumar PG [EMAIL PROTECTED] wrote:
 Any other clue that may be helpful in troubleshooting the cause ?

 On 8/15/07, Arun Kumar PG [EMAIL PROTECTED] wrote:





  Yes. it's being done. I create the engine and then set convert unicode =
  True.

  On 8/15/07, Michael Bayer  [EMAIL PROTECTED] wrote:

   are you using convert_unicode=True and/or the Unicode type ?
   On Aug 15, 2007, at 12:01 PM, Arun Kumar PG wrote:

   All tables are having a charset of utf8. Additionally, I am issuing SET
   NAMES 'utf8' statement as a part of connection establishment.

   Anything that is wrong here or missing ?

   On 8/15/07, jason kirtland [EMAIL PROTECTED] wrote:

Arun Kumar PG wrote:
 Hi All,

 Recently I upgraded to the version 3.9 of SA. Post that whenever I
am
 trying to save characters in different language in the table I am
 getting the below exception:

 File /src/sqlalchemy/engine/base.py,
 line 601, in _execute
 raise exceptions.SQLError(context.statement, context.parameters, e)
 SQLError: (UnicodeDecodeError) 'ascii' codec can't decode byte 0xc3
in
 position 1: ordinal not in range(128)

 I am wondering why it is using ascii codec instead of unicode ?

 FYI: I am using MySQL 4.1 and the charset of table is utf-8.

Odd to see ascii there instead of latin1. Is your database configured
for utf-8 client connections?

   --
   Cheers,

   - A

  --
  Cheers,

  - A

 --
 Cheers,

 - A


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



[sqlalchemy] Cannot autoreflect MySQL table with minus sign ('-') in table name.

2007-07-11 Thread Andrew Stromnov

Configuration: CentOS 5 (64bit), SA (trunk), Python 2.4.4, py-
MySQLdb-1.2.1, MySQL 5.1-current

Traceback (most recent call last):
  File ./indexer.py, line 79, in ?
table[database][conf] = Table(conf, metadata, autoload=True)
  File /usr/lib/python2.4/site-packages/sqlalchemy/schema.py, line
166, in __call__
  File /usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py,
line 809, in reflecttable
  File /usr/lib/python2.4/site-packages/sqlalchemy/databases/
mysql.py, line 1095, in reflecttable
sqlalchemy.exceptions.NoSuchTableError: 'ford-focus'

Plain SQL works perfectly:

 SELECT *
FROM `ford-focus`
WHERE 1
ORDER BY `ford-focus`.`date` DESC
LIMIT 0 , 30


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



[sqlalchemy] Re: Cannot autoreflect MySQL table with minus sign ('-') in table name.

2007-07-11 Thread Andrew Stromnov

Dirty fix (works for me):

Index: mysql.py
===
--- mysql.py(revision 2873)
+++ mysql.py(working copy)
@@ -1090,7 +1090,7 @@
 table.name = table.name.lower()
 table.metadata.tables[table.name]= table
 try:
-c = connection.execute(describe  + table.fullname, {})
+c = connection.execute(describe ` + table.fullname +
`, {})
 except:
 raise exceptions.NoSuchTableError(table.name)
 found_table = False
@@ -1153,7 +1153,7 @@
 runs SHOW CREATE TABLE to get foreign key/options
information about the table.

 
-c = connection.execute(SHOW CREATE TABLE  + table.fullname,
{})
+c = connection.execute(SHOW CREATE TABLE ` + table.fullname
+ `, {})
 desc_fetched = c.fetchone()[1]

 if not isinstance(desc_fetched, basestring):


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



[sqlalchemy] Re: Designing a permission system

2007-04-10 Thread Andrew Stromnov

look at http://code.google.com/p/spiff/ - SpiffGuard

On Apr 10, 11:36 am, Kaali [EMAIL PROTECTED] wrote:
 Hi,

 I'm designing a permission system to our messaging platform. The
 platform has different channels which contains messages. Every
 different user can have different permissions on a channel. The
 permissions are create, modify, delete.

 With these permissions, we can define that some users can create
 messages in a specific channel, and others can create, modify and
 delete them, etc.

 How would you design a database for this, and how would you implement
 it with SA?

 I'm thinking about making a many-to-many table which includes the
 permissions, but i have no idea on how to implement this in SA.

 Database schema:
 Channel =
 - Id (integer)
 - Title (unicode)
 - Messages (many-to-many)

 Channel_Permissions =
 - User Id (integer foreignkey)
 - Channel Id (integer foreignkey)
 - create (boolean)
 - modify (boolean)
 - delete (boolean)

 With simple many-to-many table, SA makes a Python list of the links.
 Is there a way to get these extra boolean variables somehow and still
 use the automatic list?

 Thanks and regards,
 K


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



[sqlalchemy] Unicode URL error

2007-03-30 Thread Andrew Stromnov

ascii-encoded string:

 url = 'mysql://login:[EMAIL PROTECTED]/adverts?charset=cp1251'
 engine = sqlalchemy.create_engine(url, convert_unicode=True, pool_recycle=4)
 metadata = sqlalchemy.BoundMetaData(engine)
 ad_table = sqlalchemy.Table('adverts', metadata, autoload=True)


unicode string:

 url = u'mysql://login:[EMAIL PROTECTED]/adverts?charset=cp1251'
 engine = sqlalchemy.create_engine(url, convert_unicode=True, pool_recycle=4)
 metadata = sqlalchemy.BoundMetaData(engine)
 ad_table = sqlalchemy.Table('adverts', metadata, autoload=True)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\schema.py, line
167, in __call__
metadata.get_engine().reflecttable(table)
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\engine\base.py,
line 754, in reflecttable
conn = self.contextual_connect()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\engine\base.py,
line 748, in contextual_connect
return Connection(self, close_with_result=close_with_result,
**kwargs)
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\engine\base.py,
line 374, in __init__
self.__connection = connection or engine.raw_connection()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\engine\base.py,
line 769, in raw_connection
return self.connection_provider.get_connection()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\engine
\default.py, line 19, in get_connection
return self._pool.connect()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\pool.py, line
147, in connect
return _ConnectionFairy(self).checkout()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\pool.py, line
232, in __init__
self._connection_record = pool.get()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\pool.py, line
160, in get
return self.do_get()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\pool.py, line
429, in do_get
con = self.create_connection()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\pool.py, line
143, in create_connection
return _ConnectionRecord(self)
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\pool.py, line
180, in __init__
self.connection = self.__connect()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\pool.py, line
210, in __connect
connection = self.__pool._creator()
  File c:\python24\develop\sqlalchemy\lib\sqlalchemy\engine
\strategies.py, line 71, in connect
raise exceptions.DBAPIError(Connection failed, e)
DBAPIError: (Connection failed) (TypeError) Connect() keywords must be
strings



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



[sqlalchemy] Re: matz blogged us

2007-03-10 Thread Andrew Stromnov

babelfish.altavista.com (JP to EN):

_SQLAlchemy - The Database Toolkit for Python

The library which synthesizes SQL from usual system. As for such
technology you think that well enough it is convenient.



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



[sqlalchemy] Re: SQLAlchemy + MySQL encoding error (probably wrong charset=... handling)

2007-02-02 Thread Andrew Stromnov

On 2/2/07, Michael Bayer [EMAIL PROTECTED] wrote:

 are you saying that executing a particular statement is changing some
 state on the local connection ?

Not exactly what I had in mind. Execution of first appeared statement
assigns (underlying ?) charset for all following queries for all
connections (in current program scope).

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



[sqlalchemy] Re: SQLAlchemy + MySQL encoding error (probably wrong charset=... handling)

2007-02-01 Thread Andrew Stromnov

cities = cities.select(limit=1).execute().fetchall() works well with
this configuration, but leads to error in nregion =
places.select(places.c.name == iv2).execute()

if nregion = places.select(places.c.name == iv2).execute() used
first, then string conversion error appear at cities =
cities.select(limit=1).execute().fetchall()

Probably, MySQL charset setting is library-wide, but not connection-
wide.


On Feb 2, 1:44 am, Michael Bayer [EMAIL PROTECTED] wrote:
 dont use the Unicode type if your MySQL client and/or server is
 converting unicode for you.  convert_unicode=False has no effect on
 the Unicode type.

 also note theres a bug in MySQLDB related to this:

 http://sourceforge.net/tracker/index.php?func=detailaid=1592353grou...http://www.sqlalchemy.org/trac/ticket/340

 On Feb 1, 7:28 am, Andrew Stromnov [EMAIL PROTECTED] wrote:

  Python 2.4.4 (win32) + SQLAlchemy (r2285) + MySQLdb 1.2.1

  Code:

  from sqlalchemy import create_engine, BoundMetaData
  from sqlalchemy import Table, Column, Integer, String, SmallInteger,
  Unicode

  dburl1 = 'mysql://login:[EMAIL PROTECTED]/geobase?
  use_unicode=1charset=cp1251compress=1'
  engine1 = create_engine(dburl1, echo=False)
  metadata1 = BoundMetaData(engine1)
  cities = Table('cities', metadata1,
  Column('id', Integer, autoincrement=True, primary_key=True),
  Column('region_id', Integer, nullable=False, default=0),
  Column('country_id', Integer, nullable=False, default=0),
  Column('dialcode', String(7), nullable=False, default=''),
  Column('name', String(64), nullable=False, default=''),
  Column('mask', String(5), nullable=False, default=''),
  Column('metro', SmallInteger, nullable=False, default='0') )

  dburl2 = 'mysql://login:[EMAIL PROTECTED]/geobase?
  use_unicode=1charset=utf8'
  engine2 = create_engine(dburl2, echo=False, convert_unicode=False)
  metadata2 = BoundMetaData(engine2)

  places = Table('places', metadata2,
  Column('id', Integer, autoincrement=True, primary_key=True),
  Column('name', Unicode(64), nullable=False, default=''),
  Column('parent', Integer, nullable=False, default=0),
  Column('left', Integer, nullable=False, default=0),
  Column('right', Integer, nullable=False, default=0),
  Column('depth', Integer, nullable=False, default=0),
  Column('type', Integer, nullable=False, default=0),
  Column('dialcode', Unicode(7), nullable=True),
  Column('mask', Unicode(5), nullable=True),
  Column('code', Integer, nullable=True),
  Column('domain', Unicode(5), nullable=True),
  )

  # BLOCK
  cities = cities.select(limit=1).execute().fetchall()
  # BLOCK

  iv2 = u'\u0418\u0432\u0430\u043d\u043e\u0432\u0441\u043a\u0430\u044f
  \u043e\u0431\u043b.'
  nregion = places.select(places.c.name == iv2).execute()

  

  Traceback (most recent call last):
File e.py, line 37, in ?
  nregion = places.select(places.c.name == iv2).execute()
File \Python24\Lib\site-packages\sqlalchemy\sql.py, line 476, in
  execute
File \Python24\Lib\site-packages\sqlalchemy\sql.py, line 414, in
  execute
File C:\Python24\lib\site-packages\sqlalchemy\engine\base.py, line
  492, in execute_compiled
  return connection.execute_compiled(compiled, *multiparams,
  **params)
File C:\Python24\lib\site-packages\sqlalchemy\engine\base.py, line
  303, in execute_compiled
  proxy(str(compiled), parameters)
File C:\Python24\lib\site-packages\sqlalchemy\engine\base.py, line
  299, in proxy
  self._execute_raw(statement, parameters, cursor=cursor,
  context=context)
File C:\Python24\lib\site-packages\sqlalchemy\engine\base.py, line
  337, in _execute_raw
  self._execute(cursor, statement, parameters, context=context)
File C:\Python24\lib\site-packages\sqlalchemy\engine\base.py, line
  356, in _execute
  raise exceptions.SQLError(statement, parameters, e)
  sqlalchemy.exceptions.SQLError: (UnicodeDecodeError) 'charmap' codec
  can't decode byte 0x98 in position 1: character maps to undefined
  'SELECT places.id, places.name, places.parent, places.`left`,
  places.`right`, places.depth, places.type, places.dialcode,
  places.mask, places.code, places.domain \nFROM places \nWHERE
  places.name = %s' ['\xd0\x98\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xbe
  \xd0\xb2\xd1\x81\xd0\xba\xd0\xb0\xd1\x8f \xd0\xbe\xd0\xb1\xd0\xbb.']


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