sql_trainer / sql_training.py
seriouspark's picture
sql_uploader and practier
7b1cbee
raw
history blame
919 Bytes
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()