So I have the following code, and it works:

for count in range(0,1000):
    L=[random.randint(0, 127),random.randint(0, 127),random.randint(0, 127)]
    random.randint(0, 127)
    name=''.join(map(chr,L))

    number=random.randint(0,1000)

    x.execute('insert into testTable set name=(%s), number=(%s)', (name, number))

Above, x is just the cursor I made (obviously). I just create a random string from ASCII values and a random number and write it to my database (this was a purely BS example so that I knew it worked)/

Then,

I have in another script:

x.execute('insert into rooms set \
        room_name=(%s),\
        room_sqft=(%s),\
        room_type=(%s),\
        room_purpose=(%s) ,\
        room_floor_number=(%s)',
        (name, sqft, roomType, room_use_ranking, floor))

And I get a syntax error: invalid syntax on the first line, right at the x. part of x.execute.

What is different between the two lines? In the problem code, all arguments but name are ints (name is a string) that are gotten from a int(raw_input(...)) type prompt that catches bad input errors.

Clearly this works, but what is going wrong in the second piece of code?

Thanks, nkk

link|improve this question
Is that a python syntax error message, or a mysql syntax error message? If it's python, it'll be how you're writing the execute function call. If it was mysql, then it'd be something related PURELY to the sql (though possibly badly building in python). – Marc B May 15 at 18:27
I do not know. How would I tell? This is a picture of the error as it comes up: link . I think it is python error, but I am not sure. Sorry...I am learning python and sql in tandem. – nkk May 15 at 18:45
So, I did some more debugging. I ran insert into rooms set room_name=5,room_sqft=4,room_type=4,room_purpose=4,room_floor_number=2 in mysql terminal and it worked perfectly. However, when I put it into an x.execute(..) (just as above), I get the same error. It is python, no mysql, that dislikes the syntax. – nkk May 15 at 20:06
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.