Home » Topic » How to Search all Tables and Columns in SQLite Database?

How to Search all Tables and Columns in SQLite Database?

Andrew Jackson ~ Modified: August 17th, 2015 ~ ~ 1 Minute Reading

Home Forums How to Search all Tables and Columns in SQLite Database?

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #481 Score: 0
    Lincoln Burrows
    Moderator
    16 pts

    try this “SELECT name FROM sqlite_master WHERE type=’table'” to search all tables and columns in SQLite database.
    For Example:
    import sqlite3
    import os
    filename = …
    with sqlite3.connect(filename) as conn:
    conn.row_factory = sqlite3.Row
    cursor = conn.cursor()
    cursor.execute(“SELECT name FROM sqlite_master WHERE type=’table'”)
    for tablerow in cursor.fetchall():
    table = tablerow[0]
    cursor.execute(“SELECT * FROM {t}”.format(t = table))
    for row in cursor:
    for field in row.keys():
    print(table, field, row[field])

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.