Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

open .db-file from python script returns empty file

I want to open a .db-file from python to inspect it. I can open it from a terminal,

    % sqlite3 scrapy_quotes.db
    sqlite> .tables
    author     quote      quote_tag  tag      
    sqlite> select * from quote limit 3
    ...

but from a python-script it only shows an empty file,

    from sqlalchemy import create_engine, inspect
    engine = create_engine('sqlite:///scrapy_quotes.db')
    insp = inspect(engine)
    print(insp.get_table_names())
    []

while this script does work for another .db-file.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    from sqlalchemy import create_engine, inspect
    engine = create_engine('sqlite:///chinook.db')
    insp = inspect(engine)
    print(insp.get_table_names())
    ['albums', 'artists', 'customers', 'employees', 'genres',                 
    'invoice_items', 'invoices', 'media_types', 
    'playlist_track', 'playlists', 'sqlite_sequence', 
    'sqlite_stat1', 'tracks']

What is going on?

>Solution :

I cannot reproduce your error, are you sure the paths are right ?

import sqlite3

con = sqlite3.connect("/tmp/test.db")
con.execute("CREATE TABLE test (id INT)")
con.commit()
con.close()
from sqlalchemy import create_engine, inspect

engine = create_engine("sqlite:////tmp/test.db")
inspect(engine).get_table_names()  # gives ['test']
% sqlite3 /tmp/test.db
SQLite version 3.32.3 2020-06-18 14:16:19
Enter ".help" for usage hints.
sqlite> .tables
test
sqlite> CREATE TABLE reverse (id INT);
from sqlalchemy import create_engine, inspect

engine = create_engine("sqlite:////tmp/test.db")
inspect(engine).get_table_names()  # gives ['reverse', 'test']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading