Python MySQLdb Cursor返回空结果

时间:2013-06-21 07:40:25

标签: python mysql-python

这是我的代码段...

首先我调用了__execute_query函数来插入一些行,然后选择几行。 但是,如果执行select查询,则函数返回None或Empty rows ...但是手动sql查询返回几行..

def __execute_query(self, query, parameters = [], set_row_id = False):
    conn = MySQL.get_conn()
    cursor = conn.cursor()

    cursor.execute(query, parameters)

    result = None
    query_type = query[0:query.find(" ")]
    query_type = query_type.lower()

    if query_type in ('insert', 'update', 'delete'):
        result = cursor.rowcount > 0
        if result:
            conn.commit()

            if query_type == 'insert' and set_row_id == True:
                """
                    Update the object with the newly saved row ID and mark
                    the object as not new.
                """
                self.__new_row = False
                    self.__row_id = conn.insert_id()
                    if self.__row_id == 0 or self.__row_id == "0":
                        self.__row_id = cursor.lastrowid
    else:
        result = cursor.fetchall()

    cursor.close()
    return result

0 个答案:

没有答案