0

I can now insert a BLOb into a row using the following code snippets:-

TheData = open("/home/mjh/Documents/DemoData/sjp.bin", 'rb').read()

sql = "Insert into Results (idResults, idClient, TestDateTime, ResultBinary) 
    Values (10, 7, '2014-11-05 14:09:11', %s)"

cursor.execute(sql, (TheData,))

However I want to put multiple BLObs into the same row and expanded the code to:-

sql = "Insert into Results (idResults, idClient, TestDateTime, ResultBinary, SecondResult) 
    Values (10, 7, '2014-11-05 14:09:11', %s, %s)"

cursor.execute(sql, (TheData, SecondData,))

This generates the error:-

_mysql_exceptions.OperationalError: (1241, 'Operand should contain 1 column(s)')

This seems a logical change (to me) based on extending the insert to add other field types. Does this mean I have to do an insert (for the first BLOb) followed by an UPDATE (for the second BLOb)?

3 Answers 3

0

Have you tried using named parameters, viz:

sql = "Insert into Results (idResults, idClient, TestDateTime, ResultBinary, SecondResult) 
    Values (10, 7, '2014-11-05 14:09:11', %(one)s, %(two)s)"

cursor.execute(sql, { 'one': TheData, 'two': SecondData})

Reference

1
  • Works on my setup - so now have two options rather than the 'none' of two hours ago... Commented Nov 7, 2014 at 14:52
0

I have checked that it works for me. There is nothing wrong in passing multiple field values to the sql execute function. The mistake is you may pass the python List. You should convert it to string and pass to that execute function. Please view for the following link:

MySqlDb throws Operand should contain 1 column(s) on insert ignore statement

0

I found that changing the Execute line to:-

cursor.execute(sql, ([TheData, SecondData]))

worked. Will try the other approaches

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.