title: Failed inserting record into table_sensor_log table - Syntax error - failed inserting record to table - 42000
body: <p>Im trying to take readings from my BME280 sensor and write them as a line in a Mysql Database using a python script. I'm sure the answer is pretty simple, however I've been banging my head against a wall for ages about this.</p>
  
  <p>Current error is: Failed inserting record into table_sensor_log table 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '09:29:03.708933,3fa924c8-73b1-4986-a9bc-f13fdc15163f,25.7461863119)' at line 2
  MySQL connection is closed</p>
  
  <p>I am getting a correct reading off my sensor.</p>
  
  <p>Pretty much tried everything I can think of - have reformulated the code multiple times.</p>
  
  <pre class="lang-py prettyprint-override"><code>
  import smbus2
  import bme280
  
  port = 1
  address = 0x76
  bus = smbus2.SMBus(port)
  
  calibration_params = bme280.load_calibration_params(bus, address)
  
  # the sample method will take a single reading and return a
  # compensated_reading object
  data = bme280.sample(bus, address, calibration_params)
  
  # the compensated_reading class has the following attributes
  timest = data.timestamp
  id = data.id
  temperature = data.temperature
  
  # there is a handy string representation too
  print(data)
  import mysql.connector
  from mysql.connector import Error
  try:
     connection = mysql.connector.connect(host='localhost',
                               database='sensor_log',
  # the compensated_reading class has the following attributes
  timest = data.timestamp
  id = data.id
  temperature = data.temperature
  
  # there is a handy string representation too
  print(data)
  import mysql.connector
  from mysql.connector import Error
  try:
     connection = mysql.connector.connect(host='localhost',
                               database='sensor_log',
                               user='superadmin',
                               password='Chillipo3')
     sql_insert_query = """ INSERT INTO `table_sensor_log`
                            (`timestamp`, `sensor_id`, `sensor_value`) VALUES (%s,%s,%s);""" % (timest,id,temperature,)
     cursor = connection.cursor()
     result  = cursor.execute(sql_insert_query)
     connection.commit()
     print ("Record inserted successfully into table_sensor_log table")
  except mysql.connector.Error as error :
      connection.rollback() #rollback if any exception occured
      print("Failed inserting record into table_sensor_log table {}".format(error))
  finally:
      #closing database connection.
  </code></pre>
  
  <p>The readings are coming out ok - I left them in to prove that my sensor has no issues.</p>
  
  <p>compensated_reading(id=3fa924c8-73b1-4986-a9bc-f13fdc15163f, timestamp=2019-07-27 09:29:03.708933, temp=25.746 °C, pressure=1009.16 hPa, humidity=55.00 % rH)
  Failed inserting record into table_sensor_log table 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '09:29:03.708933,3fa924c8-73b1-4986-a9bc-f13fdc15163f,25.7461863119)' at line 2
  MySQL connection is closed
  2019-07-27 09:29:03.708933</p>