0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonでINSERT文を発行するとno such columnが表示される

Last updated at Posted at 2019-11-27

PythonでINSERT文を発行するとno such columnというエラーが表示されて、「??」となった時のお話です。

printを使ってコンソール画面にSQLを表示してみたら…

INSERT INTO license (license_nm) values (基本情報技術者試験)

どうやらシングルクォーテーションがないため、エラーが起きていたみたいです…。

■問題となったコード

データの挿入

sql = "INSERT INTO license (license_nm) values "
sql += "("
sql += in_shikaku
sql += ")"


■修正版のコード

データの挿入

sql = "INSERT INTO license (license_nm) values "
sql += "("
sql += "'" + in_shikaku + "'"
sql += ")"


初歩的なミスでした…。

いちいち、"'"で囲むのも嫌なのでDB発行処理をどうにかしなければ・・・。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?