MySQL错误:游标返回无类型对象

时间:2019-07-23 19:33:52

标签: mysql python-3.x

我正在使用3个游标,因为我要从3个不同的表中获取数据,并在python中使用MySQL库。 在这里,我的第一个游标运行良好,但是其他两个游标始终返回None类型对象,而不管数据库中是否存在值。

我已经在stackoverflow上经历了多个线程,包括:  1.使用mysql.connector  2.使用sqlite3  3.使用MySQL 在此处附加链接: Python MySQL Connector executing second sql statement within cursor loop?

https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.execute

python mysqldb multiple cursors for one connection

https://pynative.com/python-mysql-execute-parameterized-query-using-prepared-statement/

https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html

MySQL parameterized queries

How to use variables in SQL statement in Python?

附加示例代码: '''python

conn = MySQLdb.connect(host,database,user,password)
conn1 = MySQLdb.connect(host,database,user,password)
conn2 = MySQLdb.connect(host,database,user,password)
#all 3 are successfully connected
if conn:
    cursor = conn.cursor()
    cursor.execute("SELECT * from 2015batch where uid='f20150758'")
    row=cursor.fetchone()
    while(row is not None):
        i=0
        for i in range(len(row)):
            if not row[i]:
                lst=list(row)
                lst[i]="NIL"
                row=tuple(lst)
    cursor1 = conn1.cursor()
        cursor1.execute("SELECT * from 2015_med where uid='row[0]'")
        row1 = cursor1.fetchone()
        print(row1)
        i=0
        j=0
        for i in range(4):
            if(type(row1)==type(None)):
                row1=("NIL","NIL","NIL","NIL","NIL")
            else :
                if not row1[i]:
                    lst=list(row1)
                    lst[i]="NIL"
                    row1=tuple(lst)

'''

由此,我希望结果row1不会为空,尤其是在mysql databse中该条目清晰可见的情况下:

显示第0-0行(共1行,查询耗时0.0019秒。)

SELECT * FROM 2015_med,其中uid ='f20150758'

但是row1是一个None类型的对象,在打印时会得到它

0 个答案:

没有答案