File size: 919 Bytes
7b1cbee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()