1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

在执行sql="SELECT * FROM `civet_user`.t_uc_libra_loan_limit WHERE user_id='f2745de3-94ee-42ae-8728-e5b0073dd9cf'"

报错:

1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server 

找了很久才发现其实这是python中执行sql带有单双引号的转义问题.sql既有双引号又有单引号就会出现这样的问题

解决办法如下

def transferContent(self, content):
    if content is None:
        return None
    else:
        string = ""
        for c in content:
            if c == '"':
                string += ''
            elif c == "'":
                string += "\'"
            elif c == "\\":
                string += "\\\\"
            else:
                string += c
        return string

猜你喜欢

转载自blog.csdn.net/qq_31551211/article/details/80111371