0

I run the following code and after researching the web, I stumbled upon a way to Insert records into MySQL using Python. I executed following code

i = 0

for j in range(starting_index,ending_index):
    for i in range(0,len(s)):
            c.append(nnp_array_index_coloumn.count(i))
            add1 = add1 + c[i-1]
            add2 = add1 + c[i]
            var_string_1 = ', '.join('?' * len(nnp_array[add1:add2]))
            cursor.execute("INSERT INTO tblauto_tagged ( propernoun_SRNO,tagger,train ,propernoun,propernoun_ID)VALUES (%d, %s,%s, %s, %s)" % (j, str(iput),str(corpora), var_string_1,"AUX" ))
            for item in nnp_array_index_coloumn:
                    if item not in uniques:
                            uniques.append(item)
                            add1=0;add2=0

Following Error was Generated

Traceback (most recent call last):
File "C:/Users/vchauhan/Desktop/test_for_write.py", line 111, in <module>
cursor.execute("INSERT INTO tblauto_tagged ( propernoun_SRNO,tagger,train ,propernoun,propernoun_ID)VALUES (%d, %s,%s, %s, %s)" % (j, str(iput),str(corpora), var_string_1,"AUX" ))
Error: ('07001', '[07001] [MySQL][ODBC 5.1 Driver][mysqld-5.1.61-community]SQLBindParameter not used for all parameters (506) (SQLExecDirectW)')

1 Answer 1

2

You don't never concatenate strings in .execute(). See the db api faq

Use this:

q = """
      INSERT INTO
        tblauto_tagged
        (
           propernoun_SRNO,
           tagger,
           train,
           propernoun,
           propernoun_ID
         ) VALUES (
           %d,
           %s,
           %s,
           %s,
           %s
          )
       """
cursor.execute(q,(j,str(iput),str(corpora),var_string_1,"AUX"))
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your suggestion and made appropriate changes in the code however I got following error Traceback (most recent call last): File "C:/Users/vchauhan/Desktop/test_for_write.py", line 128, in <module> cursor.execute(insert_string,(j,str(iput),str(corpora),var_string_1,"AUX")) ProgrammingError: ('The SQL contains 0 parameter markers, but 5 parameters were supplied', 'HY000')
replace %d and %s with ?
@ Burhan Khalid thank you for your valuable suggestion I did that but I got the following error don't know why. IntegrityError: ('23000', "[23000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.61-community]Duplicate entry '1' for key 'PRIMARY' (1062) (SQLExecDirectW)") Even though tblauto_tagged being a new table with no values whatsoever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.