Is it possible to use a returned column value as a table name in an SQLite query?

前端 未结 1 1317
南旧
南旧 2020-12-11 10:41

I want to write a query that examines all the tables in an SQLite database for a piece of information in order to simplify my post-incident diagnostics (performance doesn\'t

1条回答
  •  鱼传尺愫
    2020-12-11 11:23

    SQLite is designed as an embedded database, i.e., to be used together with a 'real' programming language. To be able to use such dynamic constructs, you must go outside of SQLite itself:

    cursor.execute("SELECT name FROM sqlite_master")
    rows = cursor.fetchall()
    for row in rows:
        sql = "SELECT ... FROM {} WHERE ...".format(row[0])
        cursor.execute(sql)
    

    0 讨论(0)
提交回复
热议问题