简体   繁体   English

MySQL错误-错误1054:“ where子句”中的未知列

[英]MySQL ERROR - Error 1054: Unknown column in 'where clause'

I have a list of dictionaries that is being passed as an argument to the updateResource() after cleaning the data. 我有一个字典列表,这些字典在清除数据后作为参数传递给updateResource()。

#method to clean the dictionary data
def getResource(self):
    try:
        for i in range(len(data)):
            sys_name = data[i]["system_name"]
            team = data[i]["fdc_inv_sa_team"]
            sys_name = re.sub('.1DC.com|.1dc.com|.1dc.COM |.1DC.COM\\b', '', str(sys_name))
            sys_name = str(sys_name.strip('"[]"'))
            team = str(team).replace('\\n', '')
            team = str(str(team).strip("[]"))
            data[i]["system_name"] = sys_name
            data[i]["fdc_inv_sa_team"] = team
            return data
    except Exception, e:
        logger.error("Error : ", str(e))

Here is the method that takes list of dictionaries as an argument and updates the database after doing a few checks. 这是将字典列表作为参数并在进行几次检查后更新数据库的方法。

#method to update the database with the dictionary key-value pair.
def updateResource(self, data):
    for i in range(len(data)):
        self.arg1 = data[i]["system_name"]
        self.arg2 = data[i]["fdc_inv_sa_team"]
        try:
            query1_row = self.cursor.execute(self.select_query %self.arg1)
            if query1_row:
                print "Success"
            else:
                self.cursor.execute(self.insert_query, (self.arg1, self.arg2, "Resource Not Present In Echo_Resource Table", \
                                                    str(datetime.now())))
                self.cnx.commit()

        except MySQLdb.Error as e:
            logger.error("Error %d: %s" % (e.args[0],e.args[1]))
        except Exception, e:
            logger.error("Error : ", str(e))

Here are the example queries - 以下是示例查询-

select_query = "SELECT resource_id, resource_name, support_contact_id \
              FROM echo_resource \
             WHERE resource_name = (%s) \
               AND inactive = 0;"


update_query = "UPDATE echo_resource \
               SET support_contact_id = ( \
                   SELECT contact_id FROM contacts WHERE last_name = (%s)), \
                   update_date = (%s) \
             WHERE resource_name = (%s);"


contact_echo_resource_query = "SELECT 1 \
                  FROM echo_resource \
                 WHERE resource_name = (%s) \
                   AND support_contact_id = (SELECT contact_id \
                                               FROM contacts \
                                              WHERE last_name = (%s));"

contacts_query = "SELECT 1 \
                FROM contacts \
               WHERE last_name = (%s);"

insert_query = "INSERT INTO echo_resource_log VALUES(%s, %s, %s, %s);"

Structure of echo_resource table - echo_resource表的结构-

resource_id varchar(40) NO  PRI 
resource_name   varchar(255)    YES MUL 
description longtext    YES     
ip_address  varchar(40) YES     
resource_tag    varchar(40) YES     
support_contact_id  int(11) YES MUL 
last_found_date_time    datetime    YES     

Error message - 错误信息 -

[2017-07-17 18:14:31,794] {updateEchoResource.py:82} DEBUG - Arguments for the queries : n3bvap049, X2Linux_NSS
[2017-07-17 18:14:31,795] {updateEchoResource.py:121} ERROR - Error 1054: Unknown column 'n3bvap049' in 'where clause'

Well isn't it obvious, cause you are missing single quote '' around your column values and thus it's getting considered as column name too 好吧,这不是很明显,因为您在列值周围缺少单引号'' ,因此也被视为列名

WHERE resource_name = (%s) \
                      ^...here

So you will have to concatanate your value with your query (OR) better yet use parameterized query 因此,您必须更好地与查询(OR)结合使用价值,而使用参数化查询

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python和mySQLdb错误:OperationalError:(1054,“'where子句'中的未知列””) - Python and mySQLdb error: OperationalError: (1054, “Unknown column in 'where clause'”) OperationalError:(1054,“ where子句”中的“未知列””) - OperationalError: (1054, “Unknown column '' in 'where clause'”) mysql.connector.errors.ProgrammingError: 1054 (42S22): 'where 子句'中的未知列 'X' - mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column 'X' in 'where clause' 尝试使用多对多关系进行查询时,带有MySQL的Django:OperationalError(1054,“ where子句”中的“未知列”) - Django with MySQL: OperationalError (1054, “Unknown column '' in 'where clause'”) when trying to query over Many-To-Many relationship mysql.connector.errors.ProgrammingError:1054(42S22):“where 子句”中的未知列“PY_VAR0” - mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column 'PY_VAR0' in 'where clause' python-mysql游标中的错误消息:“字段列表”中的1054未知列“x” - Error message in python-mysql cursor: 1054 unknown column “x” in 'field list' MySQL 错误消息:“1054 (42S22):‘字段列表’中的未知列‘inf’” - MySQL error message: “1054 (42S22): Unknown column 'inf' in 'field list'” SQL错误1054,带有占位符的Python中的“'字段列表'中的未知列'xxxxx'” - SQL error 1054, “Unknown column 'xxxxx' in 'field list'” in Python with placeholders pymysql.err.OperationalError:1054。“‘where 子句’中的未知列‘X’ - pymysql.err.OperationalError: 1054. "Unknown column 'X' in 'where clause' python mysql where子句中的错误 - error in python mysql where clause
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM