Uncategorized

mysql – Error when python check for existing row before add the new row



I wrote some code for checking the table for existing row and then if the id does not exist, the code inserts new row. Here is the code

x.execute("SELECT id FROM headlines WHERE id="+ pid)
numrows = int (x.rowcount)
if numrows<1:
    sql=""'insert into headlinesUS (id,feed_url,item_title,item_date,fetch_date) 
                       values ("%s","%s","%s","%s","%s");'''
    x.execute(sql, (pid,url,title,date,fetch))
    connection.commit()
    print("\n- " + title)

But when i run it i receive this error:

numrows = int (x.rowcount)
                         ^
IndentationError: unindent does not match any outer indentation level



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *