Python 2.7 sqlite3如何确定空字段

时间:2018-06-25 21:05:52

标签: sqlite

我正在使用Python脚本访问sqlite3,

input_data = None
connection = sqlite3.connect(db_path)
db = connection.cursor()
read_string = 'select viewer_id, email, device_group, created_date, path_found, analyzed from ' + db_table + ' where analyzed < ' + str(cfg_history_number_of_days) + ';'
db.execute(read_string)
input_data = db.fetchall()
connection.close()

,当“分析”字段中有数据时,此方法非常有用。当'analyze'为空时,脚本认为该字段的值比我的字符串值大得多,并且此测试失败。如何更改脚本,以便确定数据库中的字段是否为空?

1 个答案:

答案 0 :(得分:0)

任何与NULL的比较都会失败。要使NULL值看起来像是一个小字符串,请replace用一个小字符串:

Attempting to add a Windows Firewall rule with command: netsh.exe advfirewall firewall add rule name="Port 3306" protocol=TCP localport=3306 dir=in action=allow
Ok.


Successfully added the Windows Firewall rule.
Ended configuration step: Updating Windows Firewall rules

Beginning configuration step: Adjusting Windows service
Attempting to grant Network Service require filesystem permissions.
Granted permissions.
Adding new service
New service added
Ended configuration step: Adjusting Windows service

Beginning configuration step: Initializing Database
Attempting to run MySQL Server with --initialize-insecure option...
Starting process for MySQL Server 8.0.11...
Starting process with command: C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console --initialize-insecure=on...
2018-06-25T21:06:16.705865Z 0 [ERROR] [MY-011071] [Server] Unknown suffix '.' used for variable 'lower_case_table_names' (value '0.0')
2018-06-25T21:06:16.706023Z 0 [ERROR] [MY-011071] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Error while setting value '0.0' to 'lower_case_table_names'
2018-06-25T21:06:16.706780Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-06-25T21:06:16.707053Z 0 [Note] [MY-010120] [Server] Binlog end
Process for mysqld, with ID 6372, was run successfully and exited with code 1.
Failed to start process for MySQL Server 8.0.11.
Database initialization failed.
Ended configuration step: Initializing Database