title: How to check whether query have inserted data or not in Python
body: <p>I am using raw sql queries for inserting the data into DB. The insertion is working right, Now I want to perform some checks on this insert query e.g. If the query has inserted the data or not
  suppose I have insert query like</p>
  
  <pre><code>cursor.execute("some insert query" )
  </code></pre>
  
  <p>Now I want to know whether  <code>cursor.execute</code> has inserted the row then show me some text like <strong>success</strong> and if it fails to insert for some <strong>reason</strong> then show me text like <strong>error</strong> and also if the row is already inserted then show, <strong>row already exist</strong>.</p>
  
  <p>But I don't know how to perform these checks on <code>cursor.execute</code>.</p>
  
  <p><strong>edit</strong></p>
  
  <pre><code>for i in range(numrows):
                  row = cursor.fetchone()
                  if row[6]==1:
                          arr["user_id"]=row[0]
                          arr["email"]=row[1]
                          arr["style_quiz_score"]=row[2]
                          arr["style_quiz_answer"]=row[3]
                          arr["date_joined"]=row[4]
                          arr["is_active"]=row[5]
                          arr['firstname'] = row[7]
  
                          arr["username"]=re.sub(r'[^a-zA-Z0-9]', '_', arr["email"])
                  elif row[6]==2:
                          arr['lastname'] = row[7]
          cursor1.execute("insert into auth_user(id,username,first_name,last_name,email,password,is_staff,is_active,is_superuser,date_joined,last_login)  values(%s,%s,%s,%s,%s,'NULL',0,%s,0,%s,0)",[arr["user_id"],arr["username"],arr['firstname'],arr['lastname'],arr["email"],arr["is_active"],arr["date_joined"]])
  </code></pre>
  
  <p>when i am executing  <code>cursor1.execute</code> outside forloop than it insert the last entry , but if i execute it in inside forloop than it gives error and nothing will be inserted</p>