On 7 avr, 16:31, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
> you're free to access the raw connection and use the pysqlite
> create_collation method.  If you'd like to assemble this on all
> connections, look into the PoolListener API described 
> inhttp://www.sqlalchemy.org/docs/05/reference/sqlalchemy/interfaces.htm...
> and implement the "connect" method.

Ok, I've appended my collation function with dbapi_con.create_collation
("my_collate", my_collate) but I don't know how can I use my collation
in query statement.

::

    import locale
    from sqlalchemy.interfaces import PoolListener
    from sqlalchemy import Table, MetaData
    from sqlalchemy import create_engine
    from sqlalchemy.orm import sessionmaker
    from sqlalchemy.orm import mapper

    locale.setlocale(locale.LC_ALL,"fr_FR.UTF-8")

    def my_collate(string1, string2):
        return locale.strcoll(string1, string2)

    class MyListener(PoolListener):
        def connect(self, dbapi_con, con_record):
            dbapi_con.create_collation("my_collate", my_collate)

    engine = create_engine('sqlite:///development.db', echo=True,
listeners = [MyListener()])

    metadata = MetaData()
    metadata.bind = engine
    clients = Table('client', metadata, autoload = True)

    Session = sessionmaker(bind=engine)
    session = Session()

    class Client(object):
        pass

    mapper(Client, clients)

    result = session.query(Client).order_by("brand_name")

How can I add collation this query ?

Regards,
Stephane
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to