Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import sqlite3 | |
from datetime import datetime | |
def app(): | |
st.title('SQL Training') | |
st.write('SQL ์ฐ์ต์ ํด๋ด ์๋ค.') | |
file_name = st.text_input('file name:', ) | |
# ์์ ํ์ผ ์ ๋ก๋ | |
user_query = st.text_area('Enter your SQL query:', height = 100) | |
if st.button('์ฟผ๋ฆฌ ์คํ'): | |
try: | |
# ์ฟผ๋ฆฌ ์คํ ๋ฐ ๊ฒฐ๊ณผ ์ถ๋ ฅ | |
conn = sqlite3.connect(file_name) | |
c = conn.cursor() | |
query_results = pd.read_sql_query(user_query, conn) | |
if not query_results.empty: | |
st.dataframe(query_results) | |
else: | |
st.write('์ฟผ๋ฆฌ๋ ์ฑ๊ณต์ ์ผ๋ก ์คํ๋์์ต๋๋ค. ๊ทธ๋ฌ๋ ๊ฒฐ๊ณผ๊ฐ ์๋ค์.') | |
except Exception as e: | |
st.error(f'์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}') | |
finally: | |
conn.close() | |