vector8188
vector8188

Reputation: 1393

insert into table MySQL and Python

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)')

Upvotes: 0

Views: 820

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174624

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"))

Upvotes: 2

Related Questions