Python cursor.fetchone()弹出一条记录?

2024-10-02 18:14:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图找到一种方法,如果我的光标返回行或不。 我确信我的数据库里有一条记录。但做了之后 if tcursor.fetchone():它不返回任何行。如果我复制行,我的代码正在执行。为什么

sql = 'select Id, Delivery,FileName from [dbo].[SEDeliveryTemp] where 

    UpdateFlag=0 and TankSystemId =' \
                      + str(TankSystemId) + ' and Date ='+"'" + str(date)+"'"

                    tcursor.execute(sql)
                    if tcursor.fetchone():
                        for (Id, Delivery, FileName) in tcursor:
                            print 'A' <---not printing if single row data presents
        .....

Tags: and方法代码id数据库sqlif记录