[sqlalchemy] ORM and SQL expression package in same web app with use of threadlocal

2009-08-06 Thread n00b

greetings,

i've been using mysql, SA ORM (scoped_session) with cherrypy and all
is fine. however, i'm also using some MySQLdb-based connections and
getting pretty tired of the 'mysql gone away' issues and lame db.ping
() workarounds. hence, i want to move everything to SA using the
connection.execute(text()) approach. alas, not everything is ORM-able/
ORM-ed. do i have to define a separate engine object with threadlocal
strategy for the use of the expression package or is there a more
efficient way to accomplish my goals?

thanks!!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] mapping adjacency lists

2009-02-01 Thread n00b

g'day,

i wanted to give the adjacency pattern  a try in the context of a dog
pedigree database and used
http://groups.google.com/group/sqlalchemy/browse_thread/thread/d78357121da8014a/537377ff73bdede7?lnk=gstq=family+tree#537377ff73bdede7
as a reference.
the requirement at hand is to be abe to go back, say, 4-5 generations
but i don't seem to be able to change the mapper to successively yield
parents. here's a bit of code to illustrate.

persons = Table(persons, meta,
Column(person_id, Integer, primary_key=True),
Column(name, Unicode(40), nullable=False),
Column(mother_id, Integer, ForeignKey(persons.person_id)),
Column(father_id, Integer, ForeignKey(persons.person_id))
)


class Person(object):pass


mapper(Person, persons, properties={
'mom': relation(Person,
primaryjoin=persons.c.mother_id==persons.c.person_id,\
backref='children_m', lazy=False, join_depth=4),
'dad': relation(Person,
primaryjoin=persons.c.father_id==persons.c.person_id,\
backref='children_f', lazy=False, join_depth=4)
})

#meta.drop_all()
meta.create_all()

session = Session()

gd_1= Person()
gd_1.name =u'grand dad 1'
session.add(gd_1)
session.commit()

gm_1 = Person()
gm_1.name =u'grand ma 1'
session.add(gm_1)
session.commit()

gd_2 = Person()
gd_2.name =u'grand dad 2'
session.add(gd_2)
session.commit()

gm_2 = Person()
gm_2.name =u'grand ma 2'
session.add(gm_2)
session.commit()

d_1 = Person()
d_1.name =u'dad'
d_1.mother_id = gm_1.person_id
d_1.father_id = gd_1.person_id
session.add(d_1)
session.commit()

m_1 = Person()
m_1.name =u'mom'
m_1.mother_id = gm_2.person_id
m_1.father_id = gd_2.person_id
session.add(m_1)
session.commit()

c = Person()
c.name = u'child'
c.mother_id = m_1.person_id
c.father_id = d_1.person_id
session.add(c)
session.commit()

r = session.query(Person).filter(Person.name==u'child').one()
print u'name :', r.name
print u'mother, father id :', r.mother_id, r.father_id
print u'mother, father obj :', r.mom, r.dad
print u'backref children _m, _f :', r.children_m, r.children_f
print

r = session.query(Person).filter(Person.dad.contains(d_1)).one()
print u'name :', r.name
print u'mother, father id :', r.mother_id, r.father_id
print u'mother, father obj :', r.mom, r.dad[0].name
print u'backref children _m, _f :', r.children_m, r.children_f[0].name

session.close()

as you can see, the current mapper yields the children, if any, (and
only on the paternal side. i'd greatly appreciate insights to a) get
the list of parents and b) to get both maternal and paternal
references.

thx


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: delete failure with foreign key relations

2009-01-29 Thread n00b

sorry. i obviously didn't explain too well. it DOES work with ORM. i
don't have a problem at all.
however, i can't work with the tables using engine.conect or straight
MySQLdb, for that matter.
in fact, closer examination suggests that not only are the onupdate,
ondelete = CASCADE not set
in the tables but trying to set them manually also results in an
error:
Can't create table 'test2.#sql-a6_fb' (errno: 121)

following below, a stylized version of the code (which works with
ORM). however, i need to be able to
use 'straight' sql on all tables created with ORM.

thx

import 

engine = 
...
main_table = Table('main_table', meta,
Column(u'id', Integer, primary_key=True),
Column(u'data', Unicode(255)),
mysql_engine='InnoDB'
)

relation_table = Table('relation_table', meta,
   Column(u'id', Integer, primary_key=True),
   Column(u'data', Unicode(255)),
   mysql_engine='InnoDB'
)

main_relation_table = Table('main_relation_table', meta,
   Column(u'id', Integer, primary_key=True),
   Column(u'main_id', Integer, ForeignKey('main_table.id')),
   Column(u'relation_id', Integer, ForeignKey('relation_table.id')),
   mysql_engine='InnoDB'
)


class MainObj(object): pass
class RelObj(object): pass

mapper(MainObj, main_table, properties={
'relations': relation(RelObj, secondary=main_relation_table,
backref='main_obj',\
cascade=all, delete, delete-orphan)
})

mapper(RelObj, relation_table)

Session = sessionmaker(bind=engine)
meta.create_all()

session = Session()
mainobj = MainObj()
mainobj.data = u'test main'
relobj = RelObj()
relobj.data = u'relation object instance 1'
mainobj.relations.append(relobj)
session.add(mainobj)
session.commit()
session.close()

if __name__=='__main__':
session = Session()
obj = session.query(MainObj).all()
for o in obj:
#print o.id, o.relations
pass

obj = session.query(MainObj).filter(MainObj.id==1).all()
for m in obj:
print m.id, m.data, m.relations

obj = session.query(RelObj).filter(RelObj.id==1).all()
for r in obj:
print r.id, r.main_obj
session.close()
meta.drop_all()
sys.exit()

On Jan 29, 4:27 am, Alex K klizhen...@gmail.com wrote:
 Well, this error says that you have rows in other(or same) tables
 referring to this row you are going to delete,
 and you should delete referring rows first. If you want SQLA to do it
 automatically,
 you need to use sessions and mappers (not raw SQL expression engine),
 more info here:

 http://www.sqlalchemy.org/docs/05/ormtutorial.html#configuring-delete...

 Regards,
 Alex

 On Jan 29, 8:33 am, n00b pyn...@gmail.com wrote:

  back again, sorry.

  i specified a model with a few one-to-many and one many-to-many
  relations using SA 0.51 in MySql 5.1.25 rc; tables are all INNODB. all
  works well and as expected in the ORM realm. however, when i'm trying
  to use SQL Expression for a delete (row) operation, i get the dreaded

     IntegrityError: (IntegrityError) (1451, 'Cannot delete or update a
  parent row: a foreign key constraint fails

  specifically, i'm using:

  engine = create_engine('mysql://root:@localhost:3306/test2')
  connection = engine.connect()
  metadata = MetaData(bind=engine)
  main_table = Table('main_table', metadata, autoload=True)
  target_id = 1     #for illustrative purposes, primary key to delete
  connection.execute(main_table.delete().where(main_table.c.id
  ==target_id))

  where main_table is my main table and all other tables link to its id
  (primary key int) via
  foreign keys.

  thx for you help
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Getting ForeignKey Before Commit

2009-01-29 Thread n00b

why don't you work off the las/previous committed rec id?

On Jan 29, 4:05 am, Dejan Mayo dejan.m...@gmail.com wrote:
 Hi,

 My code is like that:

 try:
     for some_val in some_values:
         rec = SomeModel()
         rec.some_val = some_val
         session.save(rec)
     session.commit()
 except:
     session.rollback()

 For each record that I'm creating, I need to send an email right
 after. And each email includes some data about these records,
 especially the rec.id. Everything looks fine but the problem is
 getting the rec.id.

 I've tried:

 try:
     for some_val in some_values:
         rec = SomeModel()
         rec.some_val = some_val
         session.save(rec)
         email(rec=rec) # rec doesn't have id yet so it doesn't work
     session.commit()
 except:
     session.rollback()

 for some_val in some_values:
     rec = SomeModel()
     rec.some_val = some_val
     session.save()
     session.commit()
     email(rec=rec) # It works, but now I don't have a chance to
 rollback() anymore

 It seems like I need something whcih will trigger right after a new
 record is posted. I couldn't find any good solution. Now I need to
 learn what is the best way to do that.
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] delete failure with foreign key relations

2009-01-28 Thread n00b

back again, sorry.

i specified a model with a few one-to-many and one many-to-many
relations using SA 0.51 in MySql 5.1.25 rc; tables are all INNODB. all
works well and as expected in the ORM realm. however, when i'm trying
to use SQL Expression for a delete (row) operation, i get the dreaded

   IntegrityError: (IntegrityError) (1451, 'Cannot delete or update a
parent row: a foreign key constraint fails

specifically, i'm using:

engine = create_engine('mysql://root:@localhost:3306/test2')
connection = engine.connect()
metadata = MetaData(bind=engine)
main_table = Table('main_table', metadata, autoload=True)
target_id = 1 #for illustrative purposes, primary key to delete
connection.execute(main_table.delete().where(main_table.c.id
==target_id))

where main_table is my main table and all other tables link to its id
(primary key int) via
foreign keys.

thx for you help
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] session.merge()

2009-01-17 Thread n00b

greetings,

i'm batch processing xml documents to mysql using SA 0.5, ORM.

data extracted from xml docs may be new or an update in form of a
replacement of
the existing object (record). (one of the columns, product_id, is
unique=True). Hence,
SA throws, as expected, an IntegrityError (1062, duplicate Entry) when
i'm trying to commit the revised object via session.add(obj),
session.commit().

given the xml volume at hand, i thought i could use session.merge
rather than query every time for existence. alas, no go. get the same
1062 exception. obviously, i don't understand the session merge.

in fact, even if i query for the existence, then try and assign the
new object to the existing object (old_obj = session.query(OBJ).filter
(OBJ.product_id == new_obj.product.id).one(), old_obj = new_obj,
session.add(old_obj), session.commit()), i get the dreaded 1062.

any insights/suggestions?

thx
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: session.merge()

2009-01-17 Thread n00b

thanks. i'll give it a shot.

On Jan 17, 10:43 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jan 17, 2009, at 4:07 AM, n00b wrote:





  greetings,

  i'm batch processing xml documents to mysql using SA 0.5, ORM.

  data extracted from xml docs may be new or an update in form of a
  replacement of
  the existing object (record). (one of the columns, product_id, is
  unique=True). Hence,
  SA throws, as expected, an IntegrityError (1062, duplicate Entry) when
  i'm trying to commit the revised object via session.add(obj),
  session.commit().

  given the xml volume at hand, i thought i could use session.merge
  rather than query every time for existence. alas, no go. get the same
  1062 exception. obviously, i don't understand the session merge.

  in fact, even if i query for the existence, then try and assign the
  new object to the existing object (old_obj = session.query(OBJ).filter
  (OBJ.product_id == new_obj.product.id).one(), old_obj = new_obj,
  session.add(old_obj), session.commit()), i get the dreaded 1062.

  any insights/suggestions?

 you're on the right track, except that merge() is basing its do i  
 update an existing object based on primary keys, not just unique  
 constraints.  you'd have to merge() objects that match up to those you  
 want to update based on primary key.   if your tables don't look like  
 that, you can still configure the mapper() to consider any arbitrary  
 set of columns as primary key columns using the primary_key argument.
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: session.merge()

2009-01-17 Thread n00b

actually, this is exactly what i didn't want to do .. at least not
explicitly. thx.

On Jan 17, 3:24 am, Laurent Rahuel laurent.rah...@gmail.com wrote:
 Hi,

 Did you first load the entry to update into the session or do you  
 always create new objects to be saved ?
 I guess you need to:

 1 - try to get the record from the database using the product_id or
 another unique field
 2 - if the result set is not empty,
         update the record using values from the XML and session.commit()
 will update the database
      else
         create a new mapped object with values from the XML file,
 session.add(ob), and session.commit() will add the record into database

 Regards,

 Laurent

 n00b a écrit :

  greetings,

  i'm batch processing xml documents to mysql using SA 0.5, ORM.

  data extracted from xml docs may be new or an update in form of a
  replacement of
  the existing object (record). (one of the columns, product_id, is
  unique=True). Hence,
  SA throws, as expected, an IntegrityError (1062, duplicate Entry) when
  i'm trying to commit the revised object via session.add(obj),
  session.commit().

  given the xml volume at hand, i thought i could use session.merge
  rather than query every time for existence. alas, no go. get the same
  1062 exception. obviously, i don't understand the session merge.

  in fact, even if i query for the existence, then try and assign the
  new object to the existing object (old_obj = session.query(OBJ).filter
  (OBJ.product_id == new_obj.product.id).one(), old_obj = new_obj,
  session.add(old_obj), session.commit()), i get the dreaded 1062.

  any insights/suggestions?

  thx
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] session.add

2008-12-11 Thread n00b

hello,

i need to generate a unique number from a table based on the primary
key. i used to lock
the table (with write) and got what i needed. working with the ORM,
though, it seems that
session.add(object) functions just as well. at the time of the
session.add(), the primary key assigned to the object, which is still
in the session, is unique. calling the 'live' object.id get's me what
i need - a unique primary key. somehow this seems too good to be
true ... what am i missing here?

thx
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: utf hex instead of utf-8 return

2008-12-07 Thread n00b

thanks!!
you just confirmed my empirical observations, which puts me very much
at ease :)
for versions, 1.2.2 mysqldb, and v 5.0.67 and 6.0.7 (alpha) mysql
(community ed.)

thank again.

On Dec 7, 8:52 am, Michael Bayer [EMAIL PROTECTED] wrote:
 you should also be on MySQLdb 1.2.2.  Using the Unicode type in  
 conjunction with charset=utf8use_unicode=0 and always passing Python  
 unicode (u'') objects is the general recipe for unicode with MySQL.    
 All this means is that SQLA sends utf-8-encoded strings to MySQLdb,  
 MySQLdb does not try to encode them itself and makes MySQL aware the  
 data should be considered as utf-8.   I'm not sure what version of  
 MySQL you're on or how older versions of that might get in the way.

 On Dec 6, 2008, at 1:26 PM, n00b wrote:



  thanks for the quick reply. i kept trying with it and no have reached
  the utter state of confusion.
  the specification of Unicode versus String in the table def's coupled
  with actual str representation
  has my totally confused. here's a quick script, have a look at the
  mysql table itself to see character
  display:

  #!/usr/bin/env python
  # -*- coding: utf-8 -*-

  import os, sys
  import unicodedata

  from sqlalchemy import *
  from sqlalchemy.orm import *

  #set db
  import MySQLdb
  db = MySQLdb.connect(host='localhost', user='root', passwd='',
  db='xxx', use_unicode=True, charset='utf8')
  cur = db.cursor()
  cur.execute('SET NAMES utf8')
  cur.execute('SET CHARACTER SET utf8')
  cur.execute('SET character_set_connection=utf8')
  cur.execute('SET character_set_server=utf8')
  cur.execute('''SHOW VARIABLES LIKE 'char%'; ''')
  print cur.fetchall()

  utf_repr = '\xc3\xab'
  hex_repr = '\xeb'

  mysql_url = 'mysql://root:@localhost/xxx'
  connect_args = {'charset':'utf8', 'use_unicode':'0'}
  engine = create_engine(mysql_url, connect_args=connect_args)
  metadata = MetaData()

  test_table = Table('encoding_test', metadata,
     Column(u'id', Integer, primary_key=True),
     Column(u'unicode', Integer),
     Column(u'u_hex', Unicode(10)),
     Column(u'u_utf', Unicode(10)),
     Column(u'u_str', Unicode(10)),
     Column(u's_hex', String(10)),
     Column(u's_utf', String(10)),
     Column(u's_str', String(10))
  )

  class EncodingTest(object): pass

  mapper(EncodingTest, test_table)

  metadata.create_all(engine)
  Session = sessionmaker(bind=engine)

  session = Session()
  et = EncodingTest()
  et.unicode = 1
  et.u_str = u'ë'
  et.u_hex = u'\xeb'
  et.u_utf = u'\xc3\xab'
  et.s_str = u'ë'
  et.s_hex = u'\xeb'
  et.s_utf = u'\xc3\xab'
  session.add(et)
  session.commit()
  et = EncodingTest()
  et.unicode = 0
  et.u_str = 'ë'
  et.u_hex = '\xeb'
  et.u_utf = '\xc3\xab'
  et.s_str = 'ë'
  et.s_hex = '\xeb'
  et.s_utf = '\xc3\xab'
  session.add(et)
  session.commit()
  session.close()

  session = Session()
  results = session.query(EncodingTest).all()
  for result in results:
     print result.unicode
     print repr(result.u_hex), repr(result.u_utf), repr(result.u_str)
     print repr(result.s_hex), repr(result.s_utf), repr(result.s_str)
     print

  in addition, i don't seem to be able to run the mysql settings (# set
  db) from SA.
  any insights are greatly appreciated. btw, the use_unciode, either in
  MySQLdb or SA,
  doesn't seem to have any effect on results.

  thx

  On Dec 5, 3:25 pm, Michael Bayer [EMAIL PROTECTED] wrote:
  I'm not sure of the mechanics of what you're experiencing, but make
  sure you use charset=utf8use_unicode=0 with MySQL.

  On Dec 5, 2008, at 4:17 PM, n00b wrote:

  greetings,

  SA (0.5.0rc1) keeps returning utf hex in stead of utf-8 and in the
  process driving me batty.  all the mysql setup is fine, the chars  
  look
  good and are umlauting to goethe's delight. moreover, insert and
  select are working perfectly with the MySQLdb api on three different
  *nix systems, two servers, ... it works.

  where things fall apart is on the retrieval side of SA; inserts are
  fine (using the config_args = {'charset':'utf8'} dict in the
  create_engine call).

  for example, ë, the latin small letter e with diaeresis, is stored  
  in
  mysql hex as C3 AB; using the MySQldb client, this is exactly what i
  get back: '\xc3\xab' (in the # -*- coding: UTF-8 -*- environment) no
  further codecs work required. SA, on the other hand, hands me back  
  the
  utf-hex representation, '\xeb'.

  there must be some setting that i'm missing that'll give the
  appropriate utf-8 representation at the SA (api) level. any ideas,
  suggestions?

  thx

  yes, i could do  '\xeb'.encode('utf8) but it's not an option. we got
  too much data to deal with and MySQLdb is working perfectly well
  without the extra step. thx.
--~--~-~--~~~---~--~~
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

[sqlalchemy] Re: utf hex instead of utf-8 return

2008-12-06 Thread n00b

thanks for the quick reply. i kept trying with it and no have reached
the utter state of confusion.
the specification of Unicode versus String in the table def's coupled
with actual str representation
has my totally confused. here's a quick script, have a look at the
mysql table itself to see character
display:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, sys
import unicodedata

from sqlalchemy import *
from sqlalchemy.orm import *

#set db
import MySQLdb
db = MySQLdb.connect(host='localhost', user='root', passwd='',
db='xxx', use_unicode=True, charset='utf8')
cur = db.cursor()
cur.execute('SET NAMES utf8')
cur.execute('SET CHARACTER SET utf8')
cur.execute('SET character_set_connection=utf8')
cur.execute('SET character_set_server=utf8')
cur.execute('''SHOW VARIABLES LIKE 'char%'; ''')
print cur.fetchall()

utf_repr = '\xc3\xab'
hex_repr = '\xeb'

mysql_url = 'mysql://root:@localhost/xxx'
connect_args = {'charset':'utf8', 'use_unicode':'0'}
engine = create_engine(mysql_url, connect_args=connect_args)
metadata = MetaData()


test_table = Table('encoding_test', metadata,
Column(u'id', Integer, primary_key=True),
Column(u'unicode', Integer),
Column(u'u_hex', Unicode(10)),
Column(u'u_utf', Unicode(10)),
Column(u'u_str', Unicode(10)),
Column(u's_hex', String(10)),
Column(u's_utf', String(10)),
Column(u's_str', String(10))
)

class EncodingTest(object): pass

mapper(EncodingTest, test_table)

metadata.create_all(engine)
Session = sessionmaker(bind=engine)

session = Session()
et = EncodingTest()
et.unicode = 1
et.u_str = u'ë'
et.u_hex = u'\xeb'
et.u_utf = u'\xc3\xab'
et.s_str = u'ë'
et.s_hex = u'\xeb'
et.s_utf = u'\xc3\xab'
session.add(et)
session.commit()
et = EncodingTest()
et.unicode = 0
et.u_str = 'ë'
et.u_hex = '\xeb'
et.u_utf = '\xc3\xab'
et.s_str = 'ë'
et.s_hex = '\xeb'
et.s_utf = '\xc3\xab'
session.add(et)
session.commit()
session.close()

session = Session()
results = session.query(EncodingTest).all()
for result in results:
print result.unicode
print repr(result.u_hex), repr(result.u_utf), repr(result.u_str)
print repr(result.s_hex), repr(result.s_utf), repr(result.s_str)
print

in addition, i don't seem to be able to run the mysql settings (# set
db) from SA.
any insights are greatly appreciated. btw, the use_unciode, either in
MySQLdb or SA,
doesn't seem to have any effect on results.

thx

On Dec 5, 3:25 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 I'm not sure of the mechanics of what you're experiencing, but make  
 sure you use charset=utf8use_unicode=0 with MySQL.

 On Dec 5, 2008, at 4:17 PM, n00b wrote:



  greetings,

  SA (0.5.0rc1) keeps returning utf hex in stead of utf-8 and in the
  process driving me batty.  all the mysql setup is fine, the chars look
  good and are umlauting to goethe's delight. moreover, insert and
  select are working perfectly with the MySQLdb api on three different
  *nix systems, two servers, ... it works.

  where things fall apart is on the retrieval side of SA; inserts are
  fine (using the config_args = {'charset':'utf8'} dict in the
  create_engine call).

  for example, ë, the latin small letter e with diaeresis, is stored in
  mysql hex as C3 AB; using the MySQldb client, this is exactly what i
  get back: '\xc3\xab' (in the # -*- coding: UTF-8 -*- environment) no
  further codecs work required. SA, on the other hand, hands me back the
  utf-hex representation, '\xeb'.

  there must be some setting that i'm missing that'll give the
  appropriate utf-8 representation at the SA (api) level. any ideas,
  suggestions?

  thx

  yes, i could do  '\xeb'.encode('utf8) but it's not an option. we got
  too much data to deal with and MySQLdb is working perfectly well
  without the extra step. thx.
--~--~-~--~~~---~--~~
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] utf hex instead of utf-8 return

2008-12-05 Thread n00b

greetings,

SA (0.5.0rc1) keeps returning utf hex in stead of utf-8 and in the
process driving me batty.  all the mysql setup is fine, the chars look
good and are umlauting to goethe's delight. moreover, insert and
select are working perfectly with the MySQLdb api on three different
*nix systems, two servers, ... it works.

where things fall apart is on the retrieval side of SA; inserts are
fine (using the config_args = {'charset':'utf8'} dict in the
create_engine call).

for example, ë, the latin small letter e with diaeresis, is stored in
mysql hex as C3 AB; using the MySQldb client, this is exactly what i
get back: '\xc3\xab' (in the # -*- coding: UTF-8 -*- environment) no
further codecs work required. SA, on the other hand, hands me back the
utf-hex representation, '\xeb'.

there must be some setting that i'm missing that'll give the
appropriate utf-8 representation at the SA (api) level. any ideas,
suggestions?

thx

yes, i could do  '\xeb'.encode('utf8) but it's not an option. we got
too much data to deal with and MySQLdb is working perfectly well
without the extra step. thx.

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