python處理sql查詢結果為空


問題:
python 程序需要不停訪問數據庫,獲取數據進行處理, 但查詢結果為空時,如何處理?
 
關鍵點:
while 循環 、 continue 退出 循環 、 if not
 
解決偽代碼:

def main():
    while True:
        print(datetime.now(),'INFO : begin ******************************' )
        query_sql = 'select xxx'
        result = exec_query_sql(query_sql)
        if not result : # 即result是空的時候
            print(datetime.now(),'Waring : no query result, sleep 60s' )
            time.sleep(60)
            continue  # 退出本次while循環,執行下一次
        for res_tuple in result:
            # do something
main()

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM