I am trying my app locally, with the aim of updating later on the deployed version of it.
I am using st.connection for connecting to a local sqlite3 database, and then trying to extract all tables name from the database. However, the only thing that I am getting is the list ['name']. Below you have the corresponding code:
command = "SELECT name FROM sqlite_master WHERE type='table';"
tables_sql = list(conn.query(command))
print(tables_sql)
My databases is supposed to contain 2 tables: almond and peach.
I don’t use SQLAlchemy and st.connection, so you can have the plain vanilla code from me as under:
import sqlite3
import pandas as pd
application_path = "D:/Users..." # your application path
dbf_name = "nocrf.db" # your db name
dbcnn = sqlite3.connect(application_path + dbf_name)
dbcmd = "SELECT tbl_name FROM sqlite_master WHERE type='table' "
tables = pd.read_sql_query(dbcmd, dbcnn)
tables = tables['tbl_name'].tolist()
tables.sort() # if you need to...
st.info(f"tables: {tables}")
dbcnn.close()
Thanks for your reply. I was using sqlite3 before and it was working fine. However, I moved to SQLAlchemy and st.connection because I want to use them for connecting to the local DB from the deployed version of my application. I don’t know if this can be done with sqlite3.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.