#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    How to display content of a sqlite database?


    I'm writing a software in python and glade gui that stores data in a sqlite database. Ive managed to make the program insert data but I want to be able to display the content of the database in a list where the user can select different records. How do I do this?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    I'd use sqlite directly through a subprocess and parse the information myself. Python almost certainly has a library to simplify this.
    Code:
    $ sqlite3 ~/.config/chromium/Default/databases/Databases.db
    sqlite> .help
    (omitted)
    sqlite> .tables
    Databases  Quota      meta     
    sqlite> .schema Databases
    CREATE TABLE Databases (id INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT NOT NULL, name TEXT NOT NULL, description TEXT NOT NULL, estimated_size INTEGER NOT NULL);
    CREATE INDEX origin_index ON Databases (origin);
    CREATE UNIQUE INDEX unique_index ON Databases (origin, name);
    sqlite> select * from Databases;
    (omitted)
    sqlite> .dump Databases
    (omitted)
    Last edited by b49P23TIvg; December 13th, 2012 at 11:10 AM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    39
    Rep Power
    3
    Put python sqlite3 into your favourite search engine and you'll get several good tutorials for using SQLite inside of python.

    A very quick routine that prints out a SQL statement:

    Code:
    import sqlite3
    conn = sqlite3.connect("mydatabase.db")
    cursor = conn.cursor()
    sql = "SELECT * FROM sometable WHERE condition"
    for row in cursor.execute(sql):
        print row

IMN logo majestic logo threadwatch logo seochat tools logo