快速检查空白,如果为空白,则将其设置为NULL:
if(!variable_to_insert) variable_to_insert = "NULL"
…然后确保插入的变量不在插入语句的引号中,例如:
insert = "INSERT INTO table (var) VALUES (%s)" % (variable_to_insert)...
不喜欢:
insert = "INSERT INTO table (var) VALUES ('%s')" % (variable_to_insert)...


