JSON から解析したデータをデータベースに入力しています。INSERT
ステートメントを実行すると、エラーが発生します: sqlite3.OperationalError: no such column: None
。一部の JSON データは を返しますnull
。これにより、Python がNone
テーブルに挿入されますが、これで問題ないと思いますか? 誰が問題が何であるか知っていますか?
トレースバック:
Traceback (most recent call last):
File "productInfoScraper.py", line 71, in <module>
")")
Python での私のINSERT
ステートメント:
cursor.execute("INSERT INTO ProductInfo VALUES(" +
str(data["data"]["product_id"]) + ", " +
"'" + str(data["data"]["product_name"]) + "'" + ", " +
"'" + str(data["data"]["ingredients"]) + "'" + ", " +
"'" + str(data["data"]["serving_size"]) + "'" + ", " +
str(data["data"]["calories"]) + ", " +
str(data["data"]["total_fat_g"]) + ", " +
str(data["data"]["total_fat_percent"]) + ", " +
str(data["data"]["fat_saturated_g"]) + ", " +
str(data["data"]["fat_saturated_percent"]) + ", " +
str(data["data"]["fat_trans_g"]) + ", " +
str(data["data"]["fat_trans_percent"]) + ", " +
str(data["data"]["cholesterol_mg"]) + ", " +
str(data["data"]["sodium_mg"]) + ", " +
str(data["data"]["sodium_percent"]) + ", " +
str(data["data"]["carbo_g"]) + ", " +
str(data["data"]["carbo_percent"]) + ", " +
str(data["data"]["carbo_fibre_g"]) + ", " +
str(data["data"]["carbo_fibre_percent"]) + ", " +
str(data["data"]["carbo_sugars_g"]) + ", " +
str(data["data"]["protein_g"]) + ", " +
str(data["data"]["vitamin_a_percent"]) + ", " +
str(data["data"]["vitamin_c_percent"]) + ", " +
str(data["data"]["calcium_percent"]) + ", " +
str(data["data"]["iron_percent"]) + ", " +
"'" + str(data["data"]["micro_nutrients"]) + "'" + ", " +
"'" + str(data["data"]["tips"]) + "'" + ", " +
str(data["data"]["diet_id"]) + ", " +
"'" + str(data["data"]["diet_type"]) + "'" +
")")
私のCREATE TABLE
声明:
cursor.execute("CREATE TABLE ProductInfo(product_id INT, product_name TEXT,\
ingredients TEXT, serving_size TEXT, calories INT, total_fat_g INT,\
total_fat_percent INT, fat_saturated_g INT, fat_saturated_percent INT,\
fat_trans_g INT, fat_trans_percent INT, cholesterol_mg INT, sodium_mg\
INT, sodium_percent INT, carbo_g INT, carbo_percent INT, carbo_fibre_g\
INT, carbo_fibre_percent INT, carbo_sugars_g INT, protein_g INT,\
vitamin_a_percent INT, vitamin_c_percent INT, calcium_percent INT,\
iron_percent INT, micro_nutrients TEXT, tips TEXT, diet_id INT, diet_type\
TEXT)")