I have created a table which has a default NULL field of type int. I need to insert data using a parameter query, but I am unable to pass NULL via variable into int field.
import sys
import os
import datetime
import logging
import rds_config
import pymysql
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5, sql_mode="")
def mk_int (value):
if value in (None, "",''):
return 'NULL'
else:
return int(value)
blankStrOfInt = ''
insertSQL = "INSERT INTO `patientinsight`.`Employee`(`id`,`LastName`,`FirstName`, `DepartmentCode`) VALUES (6, 'Doe', 'John', %s)"
conn.cursor().execute(insertSQL,mk_int(blankStrOfInt))
conn.commit()
I have tried the following as return from mk_int
- return NULL
- return 'NULL'
- return None
- return ''
But of the above allows inserting NULL into the field.
- When I return 'NULL' from mk_int .. it gives a warning of type mismatch and inserts 0 instead of NULL.