I am using sqlite3 and I am trying to dynamically return specific columns from database using SELECT query, problem is I keep getting the column names back instead of the actual rows. Here is an example code
import sqlite3
conn = sqlite3.connect('db_name.db')
c = conn.cursor()
query = 'SELECT ?, ? FROM devices'
columns = ('name','network-id')
c.execute(query, columns)
print(c.fetchall())
This is the result I get:
[('name', 'network_id'), ('name', 'network_id'), ('name', 'network_id'), ('name', 'network_id'), ('name', 'network_id'), ('name', 'network_id'), ('name', 'network_id'), ('name', 'network_id'), ('name', 'network_id')]
It is very annoying, I am only trying to get back specific columns from my results, but I get the column names instead. Any help will be much appreciated