[sqlalchemy] bulk deleting rows based on query result

2009-07-28 Thread nivya

I'm trying to run the following sql using sqlalchemy ORM -

delete from feed_items where feed_id=27 order by published_on asc
limit 10;

I tried -

session.query(FeedItem).filter_by(feed_id=27).order_by
(FeedItem.published_on.asc()).limit(10).delete()

But this is deleting all rows instead of limiting the deletion to 10
rows. This was unexpected.

I also tried -

connection.execute(feed_items_table.delete().where
(feed_items_table.c.feed_id == 27).order_by
(feed_items_table.c.published_on.asc()).limit(10))

This throws an error saying order_by is not an attribute of Delete.

Is engine.execute(delete from feed_items where feed_id=27 order by
published_on asc limit 10) the only option?

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] Attribute inheritance problem.

2009-07-28 Thread Tefnet Developers

Hi all,

i have a problem with attribute inheritance as seen here:

# Fails with Python-2.5.4 and SQLAlchemy-0.5.5
# There is happening something very strange, which causes
DeliveryTask.result not to cover Task.result even though DeliveryTask is
a child of Task.

import sqlalchemy
import sqlalchemy.ext.declarative

class TefDeclarativeMeta(sqlalchemy.ext.declarative.DeclarativeMeta):
def __init__(cls, classname, bases, dict_):
if '_decl_class_registry' in cls.__dict__:
return type.__init__(cls, classname, bases, dict_)

base = bases[0]

cls.__tablename__ = cls.__name__

if 'Id' not in dict_.keys():
cls.Id = sqlalchemy.Column(sqlalchemy.types.Integer,
sqlalchemy.ForeignKey(base.Id), primary_key=True)


if hasattr(base, 'Id'):
cls.__mapper_args__ = {'inherit_condition': cls.Id ==
base.Id, 'polymorphic_identity': cls.__name__}

sqlalchemy.ext.declarative._as_declarative(cls, classname,
dict_)

return type.__init__(cls, classname, bases, dict_)

Base =
sqlalchemy.ext.declarative.declarative_base(metaclass=TefDeclarativeMeta, 
mapper=sqlalchemy.orm.mapper)

class TefEx(object):
def __init__(self, enumDict):
self.enumDict = enumDict

def set(self, state, value, oldvalue, initiator):
import sys; sys.stderr.write(SET %s on %s\n % (value,
self.enumDict))
if value not in self.enumDict.keys():
raise ValueError(value %s not in %s % (value,
self.enumDict))
return value

class Task(Base):
Id = sqlalchemy.Column( sqlalchemy.types.Integer, primary_key=True,
autoincrement=True)
objectType = sqlalchemy.Column( sqlalchemy.types.String(128),
nullable=False)
__mapper_args__ = {'polymorphic_on': objectType}

result =
sqlalchemy.orm.column_property(sqlalchemy.Column(sqlalchemy.types.Integer), 
extension = TefEx({0: 'Success', 1: 'Failure'}))


class DeliveryTask(Task):
result =
sqlalchemy.orm.column_property(sqlalchemy.Column(sqlalchemy.types.Integer), 
extension = TefEx({0: 'Delivered', 1: 'Rejected', 2: 'Redirected', 3: 
'Recipient dead'}))

task = DeliveryTask()

task.result = 3



An extension doesn't get inherited properly - a child class instance
still uses parent class extension...

Am I doing something wrong here? Is there a proper way to redefine
extensions?

thanks for reading this,
Filip Zyzniewski
Tefnet


--~--~-~--~~~---~--~~
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: bulk deleting rows based on query result

2009-07-28 Thread Michael Bayer

nivya wrote:

 I'm trying to run the following sql using sqlalchemy ORM -

 delete from feed_items where feed_id=27 order by published_on asc
 limit 10;

 I tried -

 session.query(FeedItem).filter_by(feed_id=27).order_by
 (FeedItem.published_on.asc()).limit(10).delete()

 But this is deleting all rows instead of limiting the deletion to 10
 rows. This was unexpected.

you can't use LIMIT with delete().  delete() only works with WHERE
criterion.   I'm a little surprised its not checking for that so I've
added ticket #1487.

your best bet on this is to say

q =
session.query(FeedItem.id).filter_by(feed_id=27).order_by...).limit(10).subquery()
session.query(FeedItem).filter(FeedItem.id.in_(q)).delete()



 connection.execute(feed_items_table.delete().where
 (feed_items_table.c.feed_id == 27).order_by
 (feed_items_table.c.published_on.asc()).limit(10))

 This throws an error saying order_by is not an attribute of Delete.

same answer applies.


 Is engine.execute(delete from feed_items where feed_id=27 order by
 published_on asc limit 10) the only option?

this is a MySQL-only syntax that is a syntactical replacement for the
subquery approach outlined above and it would require strings.  If you're
ambitious you can try making your own enhanced delete() construct by
subclassing Delete() and using ext.compiler, described at
http://www.sqlalchemy.org/docs/05/reference/ext/compiler.html .



--~--~-~--~~~---~--~~
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: Attribute inheritance problem.

2009-07-28 Thread Michael Bayer

Tefnet Developers wrote:
sqlalchemy.orm.column_property(sqlalchemy.Column(sqlalchemy.types.Integer),
 extension = TefEx({0: 'Delivered', 1: 'Rejected', 2: 'Redirected', 3:
 'Recipient dead'}))

 task = DeliveryTask()

 task.result = 3
 


 An extension doesn't get inherited properly - a child class instance
 still uses parent class extension...

A few things here.  First is, I'm not observing the extension not getting
inherited.  Task().result = 3 raises the error, DeliveryTask().result = 3
does not, and the value is assigned to 3.  This is with 0.5.5 as well as
trunk.

The second thing is, the approach is likely still incorrect.  The Column()
object represents the physical column in the database, so in this approach
the DeliveryTask table will get its own column named result, and I get
the impression you're looking to have two different validators for the
same column on the base table.   So the sub column_property() needs to
reference the original Column:

class Task(Base):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
primary_key=True,autoincrement=True)
objectType = sqlalchemy.Column(
sqlalchemy.types.String(128),nullable=False)
__mapper_args__ = {'polymorphic_on': objectType}

result
=sqlalchemy.orm.column_property(sqlalchemy.Column(sqlalchemy.types.Integer),
extension = TefEx({0: 'Success', 1: 'Failure'}))


class DeliveryTask(Task):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
sqlalchemy.ForeignKey(Task.Id), primary_key=True,autoincrement=True)
result =sqlalchemy.orm.column_property(Task.result, extension =
TefEx({0: 'Delivered', 1: 'Rejected', 2: 'Redirected', 3:
'Recipientdead'}))

What I think is even simpler is to have the extension or validator just
look at the class itself for the desired state:


class Task(Base):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
primary_key=True,autoincrement=True)
objectType = sqlalchemy.Column(
sqlalchemy.types.String(128),nullable=False)
result = sqlalchemy.Column(sqlalchemy.types.Integer)
__mapper_args__ = {'polymorphic_on': objectType}

enumDict = {0: 'Success', 1: 'Failure'}

@validates('result')
def set(self, key, value):
import sys; sys.stderr.write(SET %s on %s\n %
(value,self.enumDict))
if value not in self.enumDict.keys():
raise ValueError(value %s not in %s % (value,self.enumDict))
return value


class DeliveryTask(Task):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
sqlalchemy.ForeignKey(Task.Id), primary_key=True,autoincrement=True)
enumDict = {0: 'Delivered', 1: 'Rejected', 2: 'Redirected', 3:
'Recipientdead'}





--~--~-~--~~~---~--~~
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: Hierarchical data: Get all (sub-) children? Parents?

2009-07-28 Thread Michael Bayer

AF wrote:

 Hello,

 Given hierarchical data similar to:
 http://www.sqlalchemy.org/docs/05/mappers.html?#adjacency-list-relationships

 With out resorting to brute force recursive queries in my objects:

 1) Is there any way to retrieve all a node's children / sub-children?

 2) Is there a way to retrieve the list of a nodes parents?


choice 1.   Assign all nodes some common identifier that identifies the
whole sub-tree, and load all nodes of that subtree into memory on that
identifier.   This is IMHO the most pragmatic approach for most cases
assuming your tree isnt huge.   I'll note that even high volume websites
like Reddit use this approach to load all comments for a story (I
checked).

choice 2.  Use recursive operators, like in oracle CONNECT BY.  Not sure
if this is what you meant by brute force.  SQLAlchemy doesn't have
native support for these as of yet but you can use literal text
expressions.

choice 3.  Use joins.  SQLA's eager loading operators can automatically
construct the joins to load parent/children along relation(), but you need
to pre-determine the depth ahead of time.  Using joins with recursive
trees can easily lead to overly large results and excessive joins so I'd
be cautious/sparing with this approach.

choice 4. use nested sets.  this schema is the standard way to represent
trees in SQL when you want in-SQL navigability of descendants and parents,
but its a beast to persist. there is an example of this in the SQLA
distribution and I think I also saw a 3rd party implementation on Pypi at
some point.


--~--~-~--~~~---~--~~
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: Hierarchical data: Get all (sub-) children? Parents?

2009-07-28 Thread Michael Bayer

AF wrote:

 Hello,

 Given hierarchical data similar to:
 http://www.sqlalchemy.org/docs/05/mappers.html?#adjacency-list-relationships

 With out resorting to brute force recursive queries in my objects:

 1) Is there any way to retrieve all a node's children / sub-children?

 2) Is there a way to retrieve the list of a nodes parents?


oh and also I forgot materialized path.  that's what I saw on pypi too: 
http://sqlamp.angri.ru/



--~--~-~--~~~---~--~~
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: Hierarchical data: Get all (sub-) children? Parents?

2009-07-28 Thread David Gardner
Just thought I would toss in my 2-cents here, since I have lots of 
hierarchical data and have
at one time or another used most of the below methods.

Choice #1 is the option that I have found that works the best.
I Use a file path-like primary key (actually I am storing data about 
files), this allows me to easily do
things like:
nodes=session.query(Node).filter(Node.path.like('root/path/sub/%')).order_by(Node.path).all()

Choice #2, I don't use Oracle, but there is an implementation of CONNECT 
BY in PostgreSQL's contrib module tblfunc.
Using this its somewhat easy to given a leaf node, return all of the 
ancestors up to the root, the downside is I don't
believe it works in the other direction.  My experience is that this is 
really fast to retrieve data the first time, but since
your fetching your objects via text strings, SQLAlchemy isn't aware of 
what has been fetched, in practice I found I was
duplicating fetches. I haven't used the new recursive queries in PG 8.4.
http://www.postgresql.org/docs/8.4/static/tablefunc.html

Choice #3 works well with Choice #1, especially if you are interested in 
a particular node, and know ahead of time
you also want that node's grandparent.


Michael Bayer wrote:
 AF wrote:
   
 Hello,

 Given hierarchical data similar to:
 http://www.sqlalchemy.org/docs/05/mappers.html?#adjacency-list-relationships

 With out resorting to brute force recursive queries in my objects:

 1) Is there any way to retrieve all a node's children / sub-children?

 2) Is there a way to retrieve the list of a nodes parents?

 

 choice 1.   Assign all nodes some common identifier that identifies the
 whole sub-tree, and load all nodes of that subtree into memory on that
 identifier.   This is IMHO the most pragmatic approach for most cases
 assuming your tree isnt huge.   I'll note that even high volume websites
 like Reddit use this approach to load all comments for a story (I
 checked).

 choice 2.  Use recursive operators, like in oracle CONNECT BY.  Not sure
 if this is what you meant by brute force.  SQLAlchemy doesn't have
 native support for these as of yet but you can use literal text
 expressions.

 choice 3.  Use joins.  SQLA's eager loading operators can automatically
 construct the joins to load parent/children along relation(), but you need
 to pre-determine the depth ahead of time.  Using joins with recursive
 trees can easily lead to overly large results and excessive joins so I'd
 be cautious/sparing with this approach.

 choice 4. use nested sets.  this schema is the standard way to represent
 trees in SQL when you want in-SQL navigability of descendants and parents,
 but its a beast to persist. there is an example of this in the SQLA
 distribution and I think I also saw a 3rd party implementation on Pypi at
 some point.


 

   


-- 
David Gardner
Pipeline Tools Programmer
Jim Henson Creature Shop
dgard...@creatureshop.com


--~--~-~--~~~---~--~~
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: More SA, pyodbc, *nux and MSSQL problems

2009-07-28 Thread Ed Singleton


On 25 Jul 2009, at 03:17, mtrier wrote:

 On Jul 23, 8:30 am, Ed Singleton singleto...@gmail.com wrote:
 I've managed to get SA (0.6 branch) and pyodbc connecting to anMSSQL
 db on Mac OS X, but I've recently been trying to get it working on
 linux (Debian Lenny) and have been hitting some problems.


 Any luck on this? I'm using both with OSX and Ubuntu without
 differences in behavior.  Do you have an isolated test case that
 duplicates this behavior?

I've been working on trying to create some test cases, but when I do I  
start to get new errors and get distracted.  I'm pretty certain it's  
working as fully as I can expect on the Mac.  I'm also pretty certain  
that my problems with Linux are character encoding issues.  I'm  
currently trying to find out more about dialect.encoding to see if  
that helps.

I'll post as soon as I've got some good tests.  In the meantime if you  
are having any specific problems, let me know, and I'll see if I can  
think of anything.

Ed

--~--~-~--~~~---~--~~
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: More SA, pyodbc, *nux and MSSQL problems

2009-07-28 Thread Ed Singleton

On 26 Jul 2009, at 14:33, Timothy N. Tsvetkov wrote:

 Please, tell me about using it in OS X? What driver do u use, versions
 etc.

I've just started trying to properly document what I did.  I've put up  
a blog post about it:
http://blog.singletoned.net/2009/07/connecting-to-ms-sql-server-from-python-on-mac-os-x-leopard/

It'll be subject to change as I work out more, and what is there at  
the moment is from memory as I didn't properly document whilst I was  
fiddling, and I'm not quite brave to undo it all and try again.

If you've got any specific issues or problems do post them and I'll  
see if I can help.  (Any issues with the post itself, obviously email  
me directly, or post them on the blog).

I'll try and get the Linux one written up tomorrow.

Ed

--~--~-~--~~~---~--~~
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: More SA, pyodbc, *nux and MSSQL problems

2009-07-28 Thread Ed Singleton

On 26 Jul 2009, at 15:06, Michael Bayer wrote:


 i have freetds 0.82, pyodbc 2.1.4.   except for binary it mostly works
 fine (with sqla 0.6).

Is that on Mac, Linux or both?

Did you do any particular configuration of character encodings?

Ed

--~--~-~--~~~---~--~~
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] ticket_change table

2009-07-28 Thread Lukasz Szybalski

Hello,

I want to implement a change log table something similar to
ticket_change table in trac.

ticket_change table structure:

Primary key (ticket, time, field)
Index (ticket, time)

ticket  integer  (fk to my table ticket)
time inetger
author
field
oldvalue
newvalue


How can I plugin my sqlalchemy connection / setup so that when it
tries to save changes to some table (in this case ticket) it saves the
old and new value for that field.

Where during the sqlalchemy can I plug it in?


A different example:

address = Addressbook()
address.FirstName = kw['FirstName']
address.LastName = kw['LastName']
DBSession.add(address)
DBSession.commit() ---somewhere here for each field would get changed
to my address_change table

address_id
time 234234
author: lucas
field: FirstName
oldvalue: ' '
newvalue: 'Lucas'

address_id
time 234234
author: lucas
field: LastName
oldvalue: ' '
newvalue: 'Mylastname'


Ideas on how this can be done?

Thanks,
Lucas


-- 
Using rsync. How to setup rsyncd.
http://lucasmanual.com/mywiki/rsync
OpenLdap - From start to finish.
http://lucasmanual.com/mywiki/OpenLdap

--~--~-~--~~~---~--~~
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] Manually setting the polymorphic type

2009-07-28 Thread NoDamage

Is it possible to manually set the type column of a base class when
using single table inheritance? The reason I want to do this is
because I am importing data from an external source which does not
differentiate between the subclass types.

For example:

a_table = Table('a', metadata,
  Column('id', Integer, primary_key=True),
  Column('type', String(20)),
  Column('name', String(20))
  )

class A(object): pass
class B(A): pass

a_mapper = mapper(A, a_table, polymorphic_on=a_table.c.type,
polymorphic_identity='a', with_polymorphic='*')
b_mapper = mapper(B, inherits=a_mapper, polymorphic_identity='b')

Here, A is the base class and B is the subclass. I want to be able to
do this:

a = A()
a.type = 'b'

session.add(a)
result = session.query(A).all()

I expect the result to contain an instance of B because I have
explicitly set the type to 'b'. But right now, it looks like because I
have instantiated an instance of A, the type is overwritten as 'a'. Is
there any nice way to do this?

--~--~-~--~~~---~--~~
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: Manually setting the polymorphic type

2009-07-28 Thread Michael Bayer


On Jul 28, 2009, at 8:14 PM, NoDamage wrote:


 Is it possible to manually set the type column of a base class when
 using single table inheritance? The reason I want to do this is
 because I am importing data from an external source which does not
 differentiate between the subclass types.

 For example:

 a_table = Table('a', metadata,
  Column('id', Integer, primary_key=True),
  Column('type', String(20)),
  Column('name', String(20))
  )

 class A(object): pass
 class B(A): pass

 a_mapper = mapper(A, a_table, polymorphic_on=a_table.c.type,
 polymorphic_identity='a', with_polymorphic='*')
 b_mapper = mapper(B, inherits=a_mapper, polymorphic_identity='b')

 Here, A is the base class and B is the subclass. I want to be able to
 do this:

 a = A()
 a.type = 'b'

 session.add(a)
 result = session.query(A).all()

 I expect the result to contain an instance of B because I have
 explicitly set the type to 'b'. But right now, it looks like because I
 have instantiated an instance of A, the type is overwritten as 'a'. Is
 there any nice way to do this?

you could just say:

a.__class__ = B

seems a little weird but it is probably the most pythonic way to go.

at the moment the flush() process overwrites the type column  
regardless of what's in it.  Theres no hard reason it has to be that  
way, but im hesitant to change it right now within 0.5 since its been  
that way for a long time and could break people's applications.


--~--~-~--~~~---~--~~
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: ticket_change table

2009-07-28 Thread Michael Bayer


On Jul 28, 2009, at 7:56 PM, Lukasz Szybalski wrote:


 Hello,

 I want to implement a change log table something similar to
 ticket_change table in trac.

 ticket_change table structure:

 Primary key (ticket, time, field)
 Index (ticket, time)

 ticket  integer  (fk to my table ticket)
 time inetger
 author
 field
 oldvalue
 newvalue


 How can I plugin my sqlalchemy connection / setup so that when it
 tries to save changes to some table (in this case ticket) it saves the
 old and new value for that field.

 Where during the sqlalchemy can I plug it in?

MapperExtension.before_insert() is best, assuming the data you're  
manipulating is within a single object (i.e. not any related objects).


--~--~-~--~~~---~--~~
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: More SA, pyodbc, *nux and MSSQL problems

2009-07-28 Thread Michael Trier
Hi

On Tue, Jul 28, 2009 at 3:14 PM, Ed Singleton singleto...@gmail.com wrote:


 On 26 Jul 2009, at 15:06, Michael Bayer wrote:

 
  i have freetds 0.82, pyodbc 2.1.4.   except for binary it mostly works
  fine (with sqla 0.6).
 
 Is that on Mac, Linux or both?

 Did you do any particular configuration of character encodings?


I've worked a lot recently in both of these environments. With Mac and Linux
I've experienced the same behavior; that is that you can't pass unicode
statements and you can't pass unicode parameters directly, like you can when
working just with pyodbc on Windows.  With Mac and Linux you need to ensure
that:

engine.dialect.supports_unicode = False
engine.dialect.supports_unicode_statements = False

Additional I've had to set convert_unicode to True and the encoding to
Latin1.

Finally one other import factor, pyodbc will not work properly as is on *nix
environments like Mac or Ubuntu, because it won't accept UCS2 like it will
directly on Windows.  To counter this you need to do something like:

class CustomString(MSString):
MSSQL VARCHAR type, for variable-length non-Unicode data with a
maximum
of 8,000 characters.

def bind_processor(self, dialect):
if self.convert_unicode or dialect.convert_unicode:
if self.assert_unicode is None:
assert_unicode = dialect.assert_unicode
else:
assert_unicode = self.assert_unicode
def process(value):
if isinstance(value, unicode):
return value.encode(dialect.encoding)
elif assert_unicode and not isinstance(value, (unicode,
NoneType)):
if assert_unicode == 'warn':
util.warn(Unicode type received non-unicode bind 
  param value %r % value)
return value
else:
raise exc.InvalidRequestError(Unicode type received
non-unicode bind param value %r % value)
else:
return value
return process
else:
return None
from sqlalchemy.databases.mssql import MSString, MSText
import sqlalchemy.util as util
from sqlalchemy import exc

class CustomText(MSText):
MSSQL TEXT type, for variable-length text up to 2^31 characters.

def bind_processor(self, dialect):
if self.convert_unicode or dialect.convert_unicode:
if self.assert_unicode is None:
assert_unicode = dialect.assert_unicode
else:
assert_unicode = self.assert_unicode
def process(value):
if isinstance(value, unicode):
return value.encode(dialect.encoding)
elif assert_unicode and not isinstance(value, (unicode,
NoneType)):
if assert_unicode == 'warn':
util.warn(Unicode type received non-unicode bind 
  param value %r % value)
return value
else:
raise exc.InvalidRequestError(Unicode type received
non-unicode bind param value %r % value)
else:
return value
return process
else:
return None

This ensures that unicode gets converted properly.  By default we ignore the
convert_unicode when using pyodbc, but that won't work with freetds in the
mix. We plan to correct this in 0.6 with the ability to pass additional
dbapi information.

Finally my stack is:

Mac: SA - iODBC - FreeTDS - pyodbc - MSSQL
Ubuntu: SA - unixODBC - FreeTDS - pyodbc - MSSQL

Of course you can remove the xODBC part of the equation if you want, but the
results are the same.

-- 
Michael Trier
http://michaeltrier.com/
http://thisweekindjango.com/

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