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:

  1. i still need use fixed amount in select statement itself;
  2. 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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -