简体   繁体   中英

Raising exception during SQLite database connection in Python

Here is my code snippet:-

import sqlite3
database = "sample.db"
def dbConnection(database):
    try:
        connection = sqlite3.connect(database)
        db_cursor = connection.cursor()
        db_cursor.execute("show tables;")
        rows = db_cursor.fetchall()
        for row in rows:
            print row
        connection.close()
    except sqlite3.Error, e:
        print "Error in connection",e
dbConnection("enb.db")

It is raising this exception:-

Error in connection near "show": syntax error

I can't see anything wrong with the syntax as I just want to view the tables in the database. What could be the problem here?Thanks

"SHOW TABLES" is not supported by SQLite. It is valid for other databases such as MySQL.

SQLite sql reference

How to 'show tables' in SQLite

SQLite doesn't support "show" functions. You can use SELECT name FROM sqlite_master where type='table' . I found it from this thread, Android sqlite show tables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM