首页 > 解决方案 > Sqlite和python之间不返回值

问题描述

我正在尝试在我的数据库上实现选择,但每次将 datetime.now() 作为 arg 时,它都不会返回列表。

Sqlite3 命令:

if from_date is not None and to_date is not None:
                ping_select = """
                    select valor
                    from dispatcher_storage
                    where timestamp between ? and ? and chave = ?
                """
                self.data_base_conn.execute(ping_select, (from_date, to_date, key))
                sql_time_history = self.data_base_conn.fetchall()

            self.sqliteConnection.commit()

其他模块中的代码部分是:

ping_histogram = Dispatcher().fetch_all("provider_ping", date_past, datetime.now())

但是,当我None代替datetime.now()代码工作并获得值时,我没有看到问题。

标签: pythonsqlpython-3.xsqlite

解决方案


您必须验证格式是否datetime.now()与您的数据库格式匹配。您的数据库的格式是什么,因为 Sqlite 没有特定的日期时间格式。


推荐阅读