Trouble passing string of values into mySQL connector for Python

205 views Asked by At

I am trying to complete a HW assignment where I have to pass values from a dictionary into a mySQL table with Python using the mySQL connector. To accomplish this, I turned the dictionary values into a string that I could pass into my INSERT query.

Here is the 'values string I pass into the command (just substitute values to see if the code works):

1, 1, 1, 1, 1, 111-111-1111, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

For some reason every time I attempt to run this code I get these errors:

mysql.connector.errors.Datmysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, 1, 1, 1, 1, 111-111-1111, 1, 1, 1, 1, 1, 1, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 1,' at line 1

aError: 1136 (21S01): Column count doesn't match value count at row 1

import mysql.connector
db = mysql.connector.connect(user ='root', host = 'localhost', password ='Fiddlere2012!', db='py')
cursor = db.cursor() 
values = ', '.join((tuple(mds.values())))
print(values)    
insertMDS = ('INSERT INTO MDS' 
            '(manufacturer, location, contact, address, email, phone, modelNumber, moduleTotalLenxWid, moduleWeight, indCellArea, cellTech, cellManufacturer, cellManuLocation, totalCells, cellSeries, seriesStrings, bypassDiodes, bypassDiodeRating, bypassDiodeMaxTemp, seriesFuseRating, interconnectMatSupModNo, interconnectDims, superstrateType, superstrateMan, substrateType, substrateMan, frameType, frameAdhesive, encapsulantType, encapsulantMan, juncBoxType, juncBoxMan, juncBoxPottingMat, juncBoxAdhesive, juncBoxUse, cableConnectorType, maxSysVoltage, voc, isc, vmp, imp, pmp, ff)' 
            'VALUES ((%s))' % (values))

cursor.execute(insertMDS)

Please help me figure out what I am doing wrong if you can.. thank you!

0

There are 0 answers