python - How to use a parameter to select one or more columns in a SELECT statement -
i'm trying create function able select particular columns sqlite 3 table. idea this:
con = sqlite3.connect("my_db.db") cursor = con.cursor() def my_func(parameter_list): con.execute("select parameter_list a_table") return cursor.fetchall()
where parameter_list
contains names of columns user wants selected.
i've tried using ?
placeholders, but:
- i still need use fixed amount in
select
statement itself; - for reason output names of columns, not contents. want let user determine number of columns , columns he'd fetch.
you need comma-separated string columns, right? can done his:
"select {} a_table".format(','.join(parameter_list))
Comments
Post a Comment