[sqlalchemy] Re: PickleType and MySQL: want mediumblob instead of blob

2006-12-14 Thread [EMAIL PROTECTED]

Yes, that was exactly what I wanted!

Thanks a lot!


--~--~-~--~~~---~--~~
 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: AttributeError: 'ForeignKey' object has no attribute 'is_mutable'

2006-12-14 Thread Nebur


 Would there be any reason why someone might want to have a column type
 that's *not* derived from sqlalchemy.types.AbstractType?
...
 An exception message like Second argument to
 Column() should be a type, but (whatever) was found instead would
 probably have saved you some searching, right?

Yes, indeed, it would be fine when constructing the Column failed
immediately.
But Column.__init__ says: This can be any subclass of
types.AbstractType (...) or user-defined types.
So probably Column.__init__ is not the place where the check is
possible :-( and I'm not yet familiar with SA to say where it could
fail most early.
 Ruben

PS: Sorry it took much time until I could read and answer


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

2006-12-14 Thread jose

Hi all,

I'm trying to insert UTF8 characters (like this: perchè)
in PostgreSQL but...


  File build/bdist.linux-i686/egg/sqlalchemy/orm/attributes.py, line 589, in 
__init__
  File build/bdist.linux-i686/egg/sqlalchemy/orm/attributes.py, line 51, in 
is_equal
  File build/bdist.linux-i686/egg/sqlalchemy/orm/strategies.py, line 30, in 
lambda
  File build/bdist.linux-i686/egg/sqlalchemy/types.py, line 179, in 
compare_values
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 12: 
ordinal not in range(128)

jo




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

2006-12-14 Thread Marco Mariani

Lee McFadden wrote:
 Going from the line number in your exception that would be because
 your columns are of type String.  Change the columns to Unicode and it
 should solve your problem.

 foo_table = Table('foo', metadata,
 Column('id', Integer, primary_key=True),
 Column('bar', Unicode(255))
 )
   

In case you're using reflection:


  Overriding Reflected Columns

Individual columns can be overridden with explicit values when
reflecting tables; this is handy for specifying custom datatypes,
constraints such as primary keys that may not be configured within the
database, etc.

 mytable = Table('mytable', meta,
... Column('id', Integer, primary_key=True),   # override reflected 'id' to 
have primary key
... Column('mydata', Unicode(50)),# override reflected 'mydata' to be 
Unicode
... autoload=True)

http://www.sqlalchemy.org/docs/metadata.myt#metadata
or use convert_unicode=True in create_engine, as I do, it should help.

In my case, I have UTF8 as default encoding for postgres, and SA
reflects columns as PGString.


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

2006-12-14 Thread jose

Marco Mariani wrote:

Lee McFadden wrote:
  

Going from the line number in your exception that would be because
your columns are of type String.  Change the columns to Unicode and it
should solve your problem.

foo_table = Table('foo', metadata,
Column('id', Integer, primary_key=True),
Column('bar', Unicode(255))
)
  



In case you're using reflection:


  Overriding Reflected Columns

Individual columns can be overridden with explicit values when
reflecting tables; this is handy for specifying custom datatypes,
constraints such as primary keys that may not be configured within the
database, etc.

  

mytable = Table('mytable', meta,


... Column('id', Integer, primary_key=True),   # override reflected 'id' to 
have primary key
... Column('mydata', Unicode(50)),# override reflected 'mydata' to be 
Unicode
... autoload=True)

http://www.sqlalchemy.org/docs/metadata.myt#metadata
or use convert_unicode=True in create_engine, as I do, it should help.

In my case, I have UTF8 as default encoding for postgres, and SA
reflects columns as PGString.


  

Ciao Marco,

I replaced line 7 with line 8 in my model but the error is still there...


1 from turbogears import database
2 from sqlalchemy import Table, relation
3 from sqlalchemy.engine import create_engine
4 from sqlalchemy.ext.assignmapper import assign_mapper
5 database.bind_meta_data()
6 session = database.session
7 # engine = database.metadata.engine
8 engine = create_engine(postgres://username:[EMAIL PROTECTED]/sfera, 
convert_unicode=True, encoding='utf-8')
9 context = session.context
...

jo


--~--~-~--~~~---~--~~
 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: using mappers

2006-12-14 Thread Michael Bayer

i dont know if assigning tons of non_primary mappers to a single
class is going to work so well.  you might want to go with using
distinct entity_names for each one instead.


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

2006-12-14 Thread Michael Bayer

let me show you whats happening:

rawdata = 'Alors vous imaginez ma surprise, au lever du jour, quand une
dr\xc3\xb4le de petit voix m\xe2\x80\x99a r\xc3\xa9veill\xc3\xa9. Elle
disait: \xc2\xab S\xe2\x80\x99il vous pla\xc3\xaet\xe2\x80\xa6
dessine-moi un mouton! \xc2\xbb\n'

unicodedata = rawdata.decode('utf-8')

print rawdata == unicodedata

will give you that error message.  because you have
convert_unicode=True, the rows returned from your database will be as
unicode, not str, objects.  dealing with raw utf-8 strings on the other
side produces this mismatch.  so either dont use
convert_unicode/sqlalchemy.types.Unicode  or insure that you pass
only unicode() objects to your object properties.


--~--~-~--~~~---~--~~
 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: using mappers

2006-12-14 Thread Michael Bayer

I would question why even use mappers at all for this, since everything
that OO and classes have to offer is not being used here; you just want
to use dictionaries, which you can get with just result sets and
fetchall().

or you might want to try the sqlsoup extension, which has a nice
function class_for_table that does exactly what your looking for,
only in a way that will actually work (i.e. it makes a distinct class
instance for each table, complete with a mapper and query set up).

cls = sqlsoup.class_for_table(sometable)


--~--~-~--~~~---~--~~
 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] SA ORM delete efficiency

2006-12-14 Thread ml

Hi!

I have a little questions about how does the SA work:

Example:

I borrowed a model from SA documentation example User/Address. My mapper
is

mapper(Address, addresses_table)
mapper(User, users_table, properties = {
'addresses' : relation(Address, cascade=all, delete-orphan)
}
  )

My example code:

u = User(a, b)
u.addresses.append(Address(1,2,3,4))
u.addresses.append(Address(1,2,3,4))
session.save(u)
session.flush()
session.clear()
print **
u = session.query(User).get_by_user_name(a)
session.delete(u)
session.flush()

Output:
---
BEGIN
INSERT INTO users (user_name, password) VALUES (?, ?)
['a', 'b']
INSERT INTO addresses (user_id, street, city, state, zip) VALUES
(?, ?, ?, ?, ?)
[1, '1', '2', '3', '4']
INSERT INTO addresses (user_id, street, city, state, zip) VALUES
(?, ?, ?, ?, ?)
[1, '1', '2', '3', '4']
COMMIT
**
SELECT users.user_name AS users_user_name, users.password AS
users_password, users.user_id AS users_user_id 
FROM users 
WHERE users.user_name = ? ORDER BY users.oid 
 LIMIT 1 OFFSET 0
['a']
BEGIN
SELECT addresses.city AS addresses_city, addresses.address_id AS
addresses_address_id, addresses.user_id AS addresses_user_id,
addresses.zip AS addresses_zip, addresses.state AS addresses_state,
addresses.street AS addresses_street 
FROM addresses 
WHERE ? = addresses.user_id ORDER BY addresses.oid
[1]
DELETE FROM addresses WHERE addresses.address_id = ?
[[1], [2]]
DELETE FROM users WHERE users.user_id = ?
[1]
COMMIT

Question about deleting:

1) Why does the SA the second SELECT for addresses to obtain primary
keys? Why there is not a direct DELETE FROM addresses WHERE user_id=??
2) If it is neccessary to do this SELECT, why is the SA selecting all
columns? E.g. I will have 1 user with 10 addresses - an idea of
selecting all 10 addresses to get their id's is spooky :-)

Why is it so or em I missing something?

Thank you.

David



--~--~-~--~~~---~--~~
 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] Configuration of SelectResults: per Query, per Mapper, or per application?

2006-12-14 Thread Sanjay

I am implementing @paginate in a few places in a turbogears
application, which needs SelectResults. Wondering whether to configure
it for per Query, per Mapper, or per application mode. Seeking
suggestions on advantages and disadvantages of each. 

thanks
sanjay


--~--~-~--~~~---~--~~
 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: Configuration of SelectResults: per Query, per Mapper, or per application?

2006-12-14 Thread Michael Bayer

usually id go with per-mapper, but keep in mind it changes the behavior
of the results of select(), select_by() a little bit.  originally i was
just going to make SelectResults the default behavior but the users
complained :).


--~--~-~--~~~---~--~~
 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: Newbie: conflicting property error encountered

2006-12-14 Thread Michael Bayer

SA is not reporting this error clearly.  the primary_key keyword
attribute of your ItemFieldValue mapper is wrong; you can only include
columns from the table which the class is mapped to.


--~--~-~--~~~---~--~~
 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: Run initial code when object is created by the ORM

2006-12-14 Thread Michael Bayer

either put code in the __new__() method of the object, or use a
MapperExtension with create_instance().

http://www.sqlalchemy.org/trac/wiki/FAQ#whyisntmy__init__calledwhenIloadobjects


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

2006-12-14 Thread Michael Bayer

a few fixes i wanted to get out the door.  the passive_deletes flag
wasnt working, the lazy=None (a.k.a. noload) strategy was broken
after the 0.3 series, and the recent mysql enhancement of catching
2006/2014 errors was not reraising other OperationalError exceptions.

Also got two terrific user contributions:  QueuePool can now properly
recover from a bunch of failed connections, and rowcount now functions
with MySQL (and therefore ORM version checking during a flush, if you
specify version_id_col), utilizing various undocumented MySQLdb API
features.

The string-based FROM clause fix means you can now do something like
this:

   select([column('col1'), column('col2')], col1=5,
from_obj=[sometable])

i.e. constructing a SELECT from individual components, using nothing
but strings (you can even make a read-only mapper against it).  this is
what some of you want !  so now you have it.

0.3.3
- string-based FROM clauses fixed, i.e. select(...,
from_obj=[sometext])
- fixes to passive_deletes flag, lazy=None (noload) flag
- added example/docs for dealing with large collections
- added object_session() method to sqlalchemy namespace
- fixed QueuePool bug whereby its better able to reconnect to a
database
that was not reachable (thanks to Sébastien Lelong), also fixed
dispose()
method
- patch that makes MySQL rowcount work correctly! [ticket:396]
- fix to MySQL catch of 2006/2014 errors to properly re-raise
OperationalError
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
-~--~~~~--~~--~--~---