Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持JSON字段 #99

Open
mudong1991 opened this issue Apr 15, 2022 · 1 comment
Open

支持JSON字段 #99

mudong1991 opened this issue Apr 15, 2022 · 1 comment

Comments

@mudong1991
Copy link

mudong1991 commented Apr 15, 2022

bilog2sql_util.py  --> fix_object

def fix_object(value, trans_json_str=True):
    """Fixes python objects so that they can be properly inserted into SQL queries"""
    if isinstance(value, set):
        value = ','.join(value)
    if PY3PLUS and isinstance(value, bytes):
        return value.decode('utf-8')
    elif not PY3PLUS and isinstance(value, unicode):
        return value.encode('utf-8')
    elif isinstance(value, dict):
        new_dict = dict([(k, fix_object(v, trans_json_str=False)) for k, v in value.items()])
        if trans_json_str:
            r_data = json.dumps(new_dict, encoding='utf-8', ensure_ascii=False)
        else:
            r_data = new_dict
        return r_data
    elif isinstance(value, list):
        new_list = []
        for v_item in value:
            new_list.append(fix_object(v_item, trans_json_str=False))
        if trans_json_str:
            r_data = json.dumps(new_list, encoding='utf-8', ensure_ascii=False)
        else:
            r_data = new_list
        return r_data
    else:
        return value
@AZHELLRGX
Copy link

hello, can you give out full code of this script? thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants