私は単純なsqliteデータベースと相互作用するPythonプログラムに取り組んでいます。ユーザー入力に応じて、データベースをインタラクティブに「フィルタリング」し、検索に一致する行(アイテム)を返すことができる検索ツールを構築しようとしています。例えば...
私のPythonプログラム(ifステートメント、cgi.FieldStorage()などを介して)は、ユーザー入力を受け入れてからデータベースをハントできるはずです。プログラムの一般的なコードは次のとおりです。
import cgitb; cgitb.enable()
import cgi
import sys
import sqlite3 as lite
import sys
con = lite.connect('bikes.db')
form = cgi.FieldStorage()
terrain_get = form.getlist("terrain")
terrains = ",".join(terrain_get)
handlebar_get = form.getlist("handlebar")
handlebars = ",".join(handlebar_get)
kickstand = form['kickstand'].value
ご覧のとおり、その部分はユーザーの入力を受け取る部分です。正常に動作します(私は思います)。次に、助けが必要な場所:
if 'dirtrocky' not in terrains:
FILTER the database to not return items that have "dirtrocky' in their terrain field
そして、プログラムの後半で、フィルターを拡張できるようにしたいと思います。
if 'drop' not in handlebars:
FILTER the database to, much like in previous one, not return items that have 'drop' in their 'handlebar' field
私の質問は、データベースをどのようにフィルタリングできますか?私の最終結果は、理想的には、上記を「フィルターで除去」した後に残った行のIDのタプルになるはずです。
ありがとう!