MySQLに文を挿入する際に、挿入できる文と挿入しようとするとエラーが起きる文があります。
Python
1import mysql.connector 2import re 3 4db=mysql.connector.connect(host="localhost", user="user", password="user_pass") 5 6cursor=db.cursor() 7 8cursor.execute("USE tex_base") 9db.commit() 10 11# 挿入できる文 12ret = "海賊王になるのは誰だ。。。" 13# 挿入できない文 14ret = "They just didn't get it, but they do now! " 15 16#エスケープ 17ret = db._cmysql.escape_string(ret) 18 19date = "Sat Jul 21 15:28:48 +0000 2018" 20 21cursor.execute("SELECT str_to_date('%s', '%%a %%b %%d %%T %%f %%Y')" % date) 22rows = cursor.fetchall() 23 24cursor.execute("SELECT DAYNAME('%s')" % rows[0][0]) 25week = cursor.fetchall() 26 27cursor.execute("INSERT into tex(date, week, tex) values('%s', '%s' '%s')" % (rows[0][0], week[0][0], ret))
エラーの内容について
mysql.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 't get it, but they do now! ')' at line 1
他の文を挿入した際にも
mysql.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 's ')' at line 1
retのprint出力 b"They just didn\'t get it, but they do now! "
このような文が出たりします。
エスケープ処理もしてあります。
原因はどこにあるのでしょうか。
教えていただきたいです。
よろしくお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。