I'm having some trouble using Python string functions on VARCHAR columns in 
MySQL (reflected using automap_base() and base.prepare). I'm getting 

AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' 
object associated with users.middlename has an attribute 'replace'

when I try

    base_match = sess.query(md_users.id, abms_biog.id).\
        filter(match().non_conflict_middlename(md_users.middlename, 
abms_biog.middlename) == 1).

with my non_conflict_middlename function which just does some basic string 
matching:

    def non_conflict_middlename(self, a, b):
        a = a.replace('.','')
        b = b.replace('.','')

        if ((len(a.strip()) == 0 or len(b.strip()) == 0)
            or (a.replace('-','').replace(' ','') == 
b.replace('-','').replace(' ',''))
            or ((len(a) == 1 or len(b) == 1) and a[0] == b[0])
            or ((len(a) > 1 and len(b) > 1) and (a.find(b) + b.find(a) > 
-2))
            or (((' ' in a) and a[0]+a.split(' ',1)[1][0] == b) or ((' ' in 
b) and b[0]+b.split(' ',1)[1][0] == a))
            or ((('-' in a) and a[0]+a.split(' ',1)[1][0] == b) or (('-' in 
b) and b[0]+b.split(' ',1)[1][0] == a))):
                return 1
        else:
                return 0



Am I missing something here? Do I need to explicitly declare the tables and 
data types with declarative base or can I somehow treat columns as Python 
string objects while using reflected tables via automap? Thanks in advance 
for your time!









-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to