Patch for BIT data types

1 view
Skip to first unread message

Waleed Abdulla

unread,
Dec 4, 2009, 2:36:26 AM12/4/09
to appr...@googlegroups.com
I came across another bug that took a couple of hours to track. It's caused by MySql's BIT datatype, which is usually trouble anyway. Here is a possible fix in station.py. I wouldn't say it's the best way to fix it, but it worked for me. Note that I fixed the mysql-to-gae direction only. I haven't tested the gae-to-mysql direction yet.


**** red indicates code that I added ****

def normalize_type(self, field_name, field_type):
    if field_name.endswith("_ref"):
        return TYPE_REFERENCE
    elif field_type.startswith("tinyint(1)") or field_type.startswith("bit"):
        return TYPE_BOOL
    elif field_type.startswith("varchar"):
        return TYPE_STR
    elif field_type.startswith("int") or field_type.startswith("tinyint"):
        return TYPE_INT 
    else:
        return field_type


------------------

def mysql_to_rocket(self, field_type, mysql_value):
    .....
    .....
    .....

    elif field_type == TYPE_BLOB:
        rocket_value = base64.b64encode(mysql_value)
    elif field_type == TYPE_BOOL and ord(mysql_value) < 2:  # field is of type BIT
        rocket_value = str(ord(mysql_value)).encode('utf-8')
    else:
        rocket_value = (u'%s' % mysql_value).replace('|', '&#124;').encode('utf-8')

Reply all
Reply to author
Forward
0 new messages