title: Python: MQTT broker messages bulk insert into mysql database
body: <p>I have subscribed to multiple topics using paho mqtt client. On receiving the messages from broker, I want to store the messages into mysql database. I want to gather the messages altogether before inserting into DB.I have set the threshold say 1000 messages. Only when the threshold is reached the messages has to be inserted into DB altogether at once. I am checking the row_count after cursor.execute(). But it shows the count as 1. So the bulk insert is not happening. here is my sample code snippet</p>
  
  <pre><code>//main.py
  
  #mysql database class
  db = MySQLDBClass()
  
  #mqtt client class where subscription,connection to broker,some callbacks   
  mqttclient = MyMQTTClient() 
  mqttclient.on_message = db.onMessage
  mqttclient.loop_forever()
  
  //MySQLDBClass.py
  
   def __init__(self):
  
          self.insertcounter = 0
          self.insertStatement = ''
          self.bulkpayload = ''
          self.maxInsert = 1000
  
      def onMessage(self, client, userdata, msg):
  
          if  msg.topic.startswith("topic1/"):
              self.bulkpayload += "(" + msg.payload.decode("utf-8") + "," + datetime + "),"
          elif msg.topic.startswith("topic2/"):
              self.insertStatement += "INSERT INTO mydatabase.table1 VALUES (" + msg.payload.decode("utf-8") + "," + datetime + ");"
          elif msg.topic.startswith("topic3/")   
              self.insertStatement += "INSERT INTO mydatabase.table2 VALUES (" +msg.payload.decode("utf-8") + "," + datetime + ");"
          elif msg.topic.startswith("messages"):
              self.insertStatement += "INSERT INTO mydatabase.table3 VALUES ('" + msg.topic + "',"  + msg.payload.decode("utf-8") + "," + datetime + ");"
          else:
              return  # do not store in DB
  
          self.insertcounter += 1 
  
          if ( self.insertcounter &gt; self.maxInsert ): 
              if ( self.bulkpayload != '' ):
                  self.insertStatement += "INSERT INTO mydatabase.table4 VALUES" + self.bulkpayload + ";"    
                  self.bulkpayload = ''
  
              cursor.execute(self.insertStatement)
              cursor.commit()
              print (cursor.rowcount) #prints always count as one , expecting bulk count 
              self.insertcounter  = 0
              self.insertStatement = ''
  </code></pre>