Python Forum
How to handle None with mysql.connector
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle None with mysql.connector
#3
Thanks for the reply.
The problem is that mysql.connector doesn't convert None or empty string to NULL so here is how i did it:
data = None or "NULL"
conn = cnx.cursor()
conn.execute("insert into contract(red) values({}) ".format(str(data)))
cnx.commit()
this way even if red column is integer it will insert the data correctly. It would be great if there is an easier way to do it.
Reply


Messages In This Thread
How to handle None with mysql.connector - by verb - Nov-16-2018, 07:54 AM
RE: How to handle None with mysql.connector - by verb - Nov-16-2018, 09:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question No disconnect method for snowflake.connector ? Calab 0 111 Jun-11-2024, 09:42 PM
Last Post: Calab
  Mysql and mysql.connector error lostintime 2 830 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,743 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,923 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,911 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  Program stuck at mysql.connector.connect zazas321 1 2,150 Jul-29-2021, 10:49 AM
Last Post: zazas321
  MYSQL.CONNECTOR ERROR DB1 8 4,033 Jul-23-2021, 03:31 AM
Last Post: DB1
  mysql.connector Nobima 1 1,972 Apr-10-2020, 12:00 PM
Last Post: Larz60+
  Trouble retrieving dictionary from mysql.connector cursor swechsler 2 3,171 Sep-17-2019, 05:21 PM
Last Post: swechsler
  Using VBA to Call a Python script causes error in pyodbc connector pcarra 1 2,931 Jun-11-2019, 04:14 PM
Last Post: pcarra

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020