'Equal' rows compare unequal

77 views
Skip to first unread message

Frank Millman

unread,
Jun 17, 2010, 10:20:04 AM6/17/10
to pyodbc
Hi all

I want to SELECT a few columns, and save the 'fetchall()' result in a
variable, then later on SELECT the same columns and compare the result
with the saved one to see if any columns have changed.

The compare always returns False, even if there are no changes.

I am guessing it is because pyodbc returns a list of Row objects
instead of a list of tuples, and I assume that two Row objects do not
compare equal, even if their contents are identical.

If I am right, is there a solution? What would work for me would be
either of -

a) make the Row objects compare equal if their contents are identical
b) have pyodbc return a normal tuple instead of a Row object, as an
option

I am using pyodbc 2.1.6 on python 2.6.2 and MS Sql Server 2005 on MS
Windows 2003 Server.

Thanks

Frank Millman

Alec Shaner

unread,
Jun 17, 2010, 12:23:13 PM6/17/10
to pyo...@googlegroups.com
Not sure if you require a solution within pyodbc itself, but can't you just do something like this?

[tuple(r) for r in r2] == [tuple(r) for r in r1]

where r1 and r2 are the results of cursor.fetchall() calls.


--
You received this message because you are subscribed to the Google Groups "pyodbc" group.
To post to this group, send email to pyo...@googlegroups.com.
To unsubscribe from this group, send email to pyodbc+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyodbc?hl=en.


Frank Millman

unread,
Jun 18, 2010, 2:05:18 AM6/18/10
to pyodbc


On Jun 17, 6:23 pm, Alec Shaner <asha...@chumpland.org> wrote:
> Not sure if you require a solution within pyodbc itself, but can't you just
> do something like this?
>
> [tuple(r) for r in r2] == [tuple(r) for r in r1]
>
> where r1 and r2 are the results of cursor.fetchall() calls.
>

Thanks, Alec. Yes I can do that, and if there is no alternative I
will.

I have existing code that works with sqlite3 and with psycopg2, and
they can both handle my requirement with a simple compare. It would be
nice not to have to 'special case' pyodbc, but if I have to I will.

Frank
Reply all
Reply to author
Forward
0 new messages