dimanche 15 mars 2015

SQLAlchemy insert html into mysql throwing an error unable to decipher


Vote count:

0




I have tried multiple permutations of the following to accomplish the goal of inserting an html string into a database with type longtext.


My code looks like this:



def generic_sql_alch(sql):
db = get_engine()
connection = db.connect()
connection.execute("inert into questions values (':name')",name= ( sql))
connection.close()
db.dispose()


The error I am getting is the following:



File "C:\Python27\Lib\site-packages\mysql\connector\connection.py", line 722, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Python27\Lib\site-packages\mysql\connector\connection.py", line 640, in _handle_result
raise errors.get_exception(packet)
sqlalchemy.exc.ProgrammingError: (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 'inert into questions values (':name')' at line 1 "inert into questions values (':name')" {'name': '%0A%09%09%09%26lt%3Bp%26gt%3BA+list+contains+twenty+integers%2C+not+necessarily+distinct.+Does+the+list+contain+at+least+two+consecutive+integers%3F%0A%26lt%3Bbr%26gt%3B+%26amp%3Bnbsp%3B%0A%26lt%3Bbr%26gt%3B+%281%29+If+any+single+value+in+the+list+is+increased+by+1%2C+the+number+of+different+values+in+the+list+does+not+change.%0A%26lt%3Bbr%26gt%3B+%26amp%3Bnbsp%3B%0A%26lt%3Bbr%26gt%3B+%282%29+At+least+one+value+occurs+more+than+once+in+the+list.%0A%26lt%3Bbr%26gt%3B%26lt%3B%2Fp%26gt%3B%09%09%09%09+%09%09%09%0A%09%09%09%0A%09%26lt%3Bdiv+align%3D%22left%22+style%3D%22padding-right%3A15px%3B+margin-top%3A12px%3B%22%26gt%3B%0A%09%26lt%3Btable+border%3D%220%22+align%3D%22left%22+class%3D%22cat_old%22%26gt%3B%0A%09%09%0A%09%09%09%26lt%3Btbody%26gt%3B%26lt%3Btr%26gt%3B+%0A%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+width%3D%2216%22+valign%3D%22top%22%26gt%3B%26lt%3Bdiv+id%3D%22show1%22+style%3D%22display%3Anone%3B%22%26gt%3B%26lt%3Bimg+src%3D%22images%2Fdelete.gif%22+width%3D%2216%22+height%3D%2216%22+alt%3D%22%22+border%3D%220%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+valign%3D%22top%22+width%3D%2216%22+style%3D%22position%3Arelative%3Btop%3A%2B2%3Bpadding-left%3A4px%3B%22%26gt%3B%09%0A%09%09%09%09%09%09%09%26lt%3Bimg+id%3D%22checkbox_img_1%22+src%3D%22images%2FradAnswerOff.gif%22+width%3D%2213%22+height%3D%2213%22+alt%3D%22%22+border%3D%220%22%26gt%3B%0A%09%09%09%09%09%09%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09%26lt%3Btd+style%3D%22vertical-align%3Atop%3B%22+align%3D%22left%22+valign%3D%22top%22%26gt%3BStatement+%281%29+ALONE+is+sufficient%2C+but+statement+%282%29+alone+is+not+sufficient.%26lt%3B%2Ftd%26gt%3B%0A%09%09%09%26lt%3B%2Ftr%26gt%3B%0A%09%09%0A%09%09%09%26lt%3Btr%26gt%3B+%0A%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+width%3D%2216%22+valign%3D%22top%22%26gt%3B%26lt%3Bdiv+id%3D%22show2%22+style%3D%22display%3Anone%3B%22%26gt%3B%26lt%3Bimg+src%3D%22images%2Fdelete.gif%22+width%3D%2216%22+height%3D%2216%22+alt%3D%22%22+border%3D%220%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+valign%3D%22top%22+width%3D%2216%22+style%3D%22position%3Arelative%3Btop%3A%2B2%3Bpadding-left%3A4px%3B%22%26gt%3B%09%0A%09%09%09%09%09%09%09%26lt%3Bimg+id%3D%22checkbox_img_2%22+src%3D%22images%2FradAnswerOff.gif%22+width%3D%2213%22+height%3D%2213%22+alt%3D%22%22+border%3D%220%22%26gt%3B%0A%09%09%09%09%09%09%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09%26lt%3Btd+style%3D%22vertical-align%3Atop%3B%22+align%3D%22left%22+valign%3D%22top%22%26gt%3BStatement+%282%29+ALONE+is+sufficient%2C+but+statement+%281%29+alone+is+not+sufficient.%26lt%3B%2Ftd%26gt%3B%0A%09%09%09%26lt%3B%2Ftr%26gt%3B%0A%09%09%0A%09%09%09%26lt%3Btr%26gt%3B+%0A%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+width%3D%2216%22+valign%3D%22top%22%26gt%3B%26lt%3Bdiv+id%3D%22show3%22+style%3D%22display%3Anone%3B%22%26gt%3B%26lt%3Bimg+src%3D%22images%2Fcheckmark.gif%22+width%3D%2216%22+height%3D%2216%22+alt%3D%22%22+border%3D%220%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+valign%3D%22top%22+width%3D%2216%22+style%3D%22position%3Arelative%3Btop%3A%2B2%3Bpadding-left%3A4px%3B%22%26gt%3B%09%0A%09%09%09%09%09%09%09%26lt%3Bimg+id%3D%22checkbox_img_3%22+src%3D%22images%2FradAnswerOff.gif%22+width%3D%2213%22+height%3D%2213%22+alt%3D%22%22+border%3D%220%22%26gt%3B%0A%09%09%09%09%09%09%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09%26lt%3Btd+style%3D%22vertical-align%3Atop%3B%22+align%3D%22left%22+valign%3D%22top%22%26gt%3BBoth+statements+TOGETHER+are+sufficient%2C+but+NEITHER+one+ALONE+is+sufficient.%26lt%3B%2Ftd%26gt%3B%0A%09%09%09%26lt%3B%2Ftr%26gt%3B%0A%09%09%0A%09%09%09%26lt%3Btr%26gt%3B+%0A%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+width%3D%2216%22+valign%3D%22top%22%26gt%3B%26lt%3Bdiv+id%3D%22show4%22+style%3D%22display%3Anone%3B%22%26gt%3B%26lt%3Bimg+src%3D%22images%2Fdelete.gif%22+width%3D%2216%22+height%3D%2216%22+alt%3D%22%22+border%3D%220%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+valign%3D%22top%22+width%3D%2216%22+style%3D%22position%3Arelative%3Btop%3A%2B2%3Bpadding-left%3A4px%3B%22%26gt%3B%09%0A%09%09%09%09%09%09%09%26lt%3Bimg+id%3D%22checkbox_img_4%22+src%3D%22images%2FradAnswerOff.gif%22+width%3D%2213%22+height%3D%2213%22+alt%3D%22%22+border%3D%220%22%26gt%3B%0A%09%09%09%09%09%09%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09%26lt%3Btd+style%3D%22vertical-align%3Atop%3B%22+align%3D%22left%22+valign%3D%22top%22%26gt%3BEACH+statement+ALONE+is+sufficient.%26lt%3B%2Ftd%26gt%3B%0A%09%09%09%26lt%3B%2Ftr%26gt%3B%0A%09%09%0A%09%09%09%26lt%3Btr%26gt%3B+%0A%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+width%3D%2216%22+valign%3D%22top%22%26gt%3B%26lt%3Bdiv+id%3D%22show5%22+style%3D%22display%3Anone%3B%22%26gt%3B%26lt%3Bimg+src%3D%22images%2Fdelete.gif%22+width%3D%2216%22+height%3D%2216%22+alt%3D%22%22+border%3D%220%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%26lt%3Btd+valign%3D%22top%22+width%3D%2216%22+style%3D%22position%3Arelative%3Btop%3A%2B2%3Bpadding-left%3A4px%3B%22%26gt%3B%09%0A%09%09%09%09%09%09%09%26lt%3Bimg+id%3D%22checkbox_img_5%22+src%3D%22images%2FradAnswerOff.gif%22+width%3D%2213%22+height%3D%2213%22+alt%3D%22%22+border%3D%220%22%26gt%3B%0A%09%09%09%09%09%09%26lt%3B%2Ftd%26gt%3B%09%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09%26lt%3Btd+style%3D%22vertical-align%3Atop%3B%22+align%3D%22left%22+valign%3D%22top%22%26gt%3BStatements+%281%29+and+%282%29+TOGETHER+are+NOT+sufficient.%26lt%3B%2Ftd%26gt%3B%0A%09%09%09%26lt%3B%2Ftr%26gt%3B%0A%09%09%0A%09%26lt%3B%2Ftbody%26gt%3B%26lt%3B%2Ftable%26gt%3B%0A%09%26lt%3B%2Fdiv%26gt%3B%0A%09%09%09%09%09%09%09%09%09%09%0A%0A%0A%09%09%26lt%3Bdiv+style%3D%22CLEAR%3ABOTH%3B+height%3A1px%3B+width%3A1px%3B+visibility%3Ahidden%3B+font-size%3A+4px%3B+padding-left%3A15px%3B+padding-right%3A15px%3B+padding-top%3A15px%3B%22%26gt%3B%0A%09%09%09%0A%09%09%26lt%3B%2Fdiv%26gt%3B%0A%09%09%26lt%3Bdiv+class%3D%22explanation%22%26gt%3B%0A%09%09%09%09%09%09%09%09%0A%09%09%09%09%26lt%3Bdiv+id%3D%22divbtnShowExpl%22%26gt%3B%26lt%3Binput+type%3D%22Button%22+name%3D%22btnshow%22+value%3D%22View+Explanation%22+class%3D%22marback%22+onclick%3D%22showans%28%29%3B%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%0A%09%09%09%09%26lt%3Bdiv+id%3D%22divbtnHideExpl%22%26gt%3B%26lt%3Binput+type%3D%22Button%22+name%3D%22btnshow2%22+value%3D%22Hide+Explanation%22+class%3D%22marback%22+onclick%3D%22hideans%28%29%3B%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%0A%09%09%09+%0A%09%09%09%09%26lt%3Bdiv+id%3D%22reviewBox%22+style%3D%22display%3Anone%3B%22+class%3D%22hidden%22%26gt%3B%0A%09%09%09%09%09This+problem+is+annoying+because+of+the+number+of+terms+in+the+list%3B+it%26%238217%3Bs+hard+to+wrap+your+head+around+20+integers.+Check+the+statements+to+see+whether+you+can+think+through+the+problem+using+a+smaller+list%2C+or+whether+it+really+is+necessary+to+stick+with+a+list+of+20.+In+the+case+of+both+statements+1+and+2%2C+the+full+size+of+the+list+doesn%26%238217%3Bt+matter%3B+you+can+think+the+problem+through+using+an+easier+list+%28say%2C+10+or+even+5+numbers%29+that+still+represents+the+basic+principles+in+question.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0A%281%29+NOT+SUFFICIENT%3A+If+the+list+consists+of+the+numbers+2%2C+4%2C+6%2C+8%2C+10%2C+then+all+of+the+values+are+different.+If+any+value+is+increased+by+1%2C+the+list+will+still+consistent+of+five+different+values%2C+so+this+scenario+satisfies+the+statement.+This+list+does+%26lt%3Bem%26gt%3Bnot%26lt%3B%2Fem%26gt%3B+contain+two+consecutive+integers%2C+so+the+answer+to+the+question+is+no.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0AIf%2C+on+the+other+hand%2C+the+list+consists+of+four+%26%238220%3B1%26%238221%3Bs+and+a+%26%238220%3B2%26%238221%3B%2C+then+there+are+only+2+different+values+%281+and+2%29.+If+any+of+the+1%26%238217%3Bs+is+increased%2C+the+result+is+2%2C+which+is+already+in+the+list%2C+so+there+are+still+two+different+values.+If+the+2+is+increased%2C+then+the+list+will+contain+four+1%26%238217%3Bs+and+a+3%2C+and+so+the+list+will+still+contain+only+two+distinct+values.+In+this+case%2C+the+original+list+%26lt%3Bem%26gt%3Bdoes%26lt%3B%2Fem%26gt%3B+contain+two+consecutive+integers+%281+and+2%29%2C+so+the+answer+to+the+question+is+yes.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0ABecause+there+are+two+conflicting+answers+to+the+question+%28no+and+yes%29%2C+this+statement+is+not+sufficient.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0A%282%29+NOT+SUFFICIENT%3A+A+list+containing+four+1%26%238217%3Bs+and+a+2+contains+two+consecutive+integers+%281+and+2%29.+If+the+list+contains+four+1%26%238217%3Bs+and+a+3%2C+then+it+doesn%26%238217%3Bt+contain+any+consecutive+integers.+Because+there+are+two+conflicting+answers+to+the+question%2C+this+statement+is+not+sufficient.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0A%281%29+AND+%282%29+SUFFICIENT%3A+Statement+2+indicates+that+at+least+one+value+occurs+twice%3B+call+that+value+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0AStatement+1+indicates+that+increasing+any+value+in+the+list+by+1+will+not+change+the+number+of+distinct+values+in+the+list.+In+this+case%2C+then%2C+increasing+one+of+the+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+values+by+one%2C+to+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+%2B+1%2C+will+still+leave+you+with+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+in+the+list+%28since+there+are+at+least+two+%26lt%3Bem%26gt%3Ba+%26lt%3B%2Fem%26gt%3Bvalues%29+as+well+as+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+%2B+1.+The+value+of+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+%2B+1%2C+then%2C+must+already+have+been+in+the+original+list%3B+if+it+wasn%26%238217%3Bt%2C+then+you+would+have+just+added+a+new+value+without+getting+rid+of+an+old+value%2C+and+statement+1+forbids+this.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0AFor+example%2C+if+the+original+list+is+%7B1%2C+1%2C+2%2C+4%2C+6%7D%2C+then+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+%3D+1+and+there+are+four+distinct+values+in+the+list.+Changing+one+of+the+1%26%238217%3Bs+to+2+makes+the+list+%7B1%2C+2%2C+2%2C+4%2C+6%7D+and+there+are+still+four+distinct+values.+This+list+does+contain+two+consecutive+integers+%281+and+2%29.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0AIf+the+original+list+were+%7B1%2C+1%2C+3%2C+5%2C+7%7D%2C+then+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+%3D+1+and+there+are+four+distinct+values+in+the+list.+Changing+one+of+the+1%26%238217%3Bs+to+2+makes+the+list+%7B1%2C+2%2C+3%2C+5%2C+7%7D%2C+but+now+there+are+5+distinct+values+in+the+list%21+This+is+not+allowed%2C+according+to+statement+1.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0AAs+a+result%2C+whatever+%26lt%3Bem%26gt%3Ba%26lt%3B%2Fem%26gt%3B+is%2C+%26lt%3Bem%26gt%3Ba+%26lt%3B%2Fem%26gt%3B%2B+1+must+also+be+in+the+original+list.+The+original+list+must+contain+at+least+one+pair+of+consecutive+integers.%26lt%3Bbr%26gt%3B%0A%26amp%3Bnbsp%3B%26lt%3Bbr%26gt%3B%0A%26lt%3Bstrong%26gt%3BThe+correct+answer+is+%28C%29.%26lt%3B%2Fstrong%26gt%3B%26lt%3Bbr%26gt%3B%0A%0A%09%09%09%09%26lt%3B%2Fdiv%26gt%3B%0A%09%09%09%0A%09%09%09%26lt%3B%2Fdiv%26gt%3B%09%09%09%0A%09%09%0A%09%09'}


I am unsure why as I encoded the string, escaped it etc. Banging my head against the wall on this.


Thank you



asked 1 min ago







SQLAlchemy insert html into mysql throwing an error unable to decipher

Aucun commentaire:

Enregistrer un commentaire