louiecerv commited on
Commit
fe612fa
·
1 Parent(s): cb00ce6

saved changes

Browse files
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.title("SQLite3 Interactive Lesson")
4
+
5
+ st.header("Welcome to the SQLite3 Tutorial")
6
+ st.markdown("""
7
+ ### Objectives
8
+ - Learn the basics of SQLite3.
9
+ - Practice creating, modifying, and querying databases.
10
+ - Integrate SQLite3 with Python.
11
+
12
+ ### Instructions
13
+ Navigate through the pages in the sidebar to complete each interactive task:
14
+ 1. Create a Database and Tables.
15
+ 2. Insert Data.
16
+ 3. Query Data.
17
+ 4. Update Data.
18
+ 5. Delete Data.
19
+ """)
example.db ADDED
Binary file (12.3 kB). View file
 
pages/Task1_Create_Database_and_Tables.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sqlite3
3
+
4
+ st.title("Task 1: Create a Database and Tables")
5
+
6
+ db_name = st.text_input("Enter database name:", "example.db")
7
+ table_name = st.text_input("Enter table name:", "students")
8
+ columns = st.text_area("Define columns (e.g., id INTEGER PRIMARY KEY, name TEXT):")
9
+
10
+ if st.button("Create Database and Table"):
11
+ try:
12
+ conn = sqlite3.connect(db_name)
13
+ cursor = conn.cursor()
14
+ cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} ({columns})")
15
+ conn.commit()
16
+ st.success(f"Table '{table_name}' created in database '{db_name}'.")
17
+ except Exception as e:
18
+ st.error(f"Error: {e}")
19
+ finally:
20
+ conn.close()
pages/Task2_Inser_Data.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sqlite3
3
+
4
+ st.title("Task 2: Insert Data")
5
+
6
+ db_name = st.text_input("Enter database name:", "example.db")
7
+ table_name = st.text_input("Enter table name:", "students")
8
+ data = st.text_area("Enter data (e.g., 1, 'John Doe'):")
9
+
10
+ if st.button("Insert Data"):
11
+ try:
12
+ conn = sqlite3.connect(db_name)
13
+ cursor = conn.cursor()
14
+ cursor.execute(f"INSERT INTO {table_name} VALUES ({data})")
15
+ conn.commit()
16
+ st.success("Data inserted successfully!")
17
+ except Exception as e:
18
+ st.error(f"Error: {e}")
19
+ finally:
20
+ conn.close()
pages/Task3_Query_data.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sqlite3
3
+ import pandas as pd
4
+
5
+ st.title("Task 3: Query Data")
6
+
7
+ db_name = st.text_input("Enter database name:", "example.db")
8
+ query = st.text_area("Enter SQL query (e.g., SELECT * FROM students):")
9
+
10
+ if st.button("Execute Query"):
11
+ try:
12
+ conn = sqlite3.connect(db_name)
13
+ result = pd.read_sql_query(query, conn)
14
+ st.write(result)
15
+ except Exception as e:
16
+ st.error(f"Error: {e}")
17
+ finally:
18
+ conn.close()
pages/Task4_Update.Data.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sqlite3
3
+
4
+ st.title("Task 4: Update Data")
5
+
6
+ db_name = st.text_input("Enter database name:", "example.db")
7
+ update_query = st.text_area("Enter SQL update query (e.g., UPDATE students SET name='Jane Doe' WHERE id=1):")
8
+
9
+ if st.button("Update Data"):
10
+ try:
11
+ conn = sqlite3.connect(db_name)
12
+ cursor = conn.cursor()
13
+ cursor.execute(update_query)
14
+ conn.commit()
15
+ st.success("Data updated successfully!")
16
+ except Exception as e:
17
+ st.error(f"Error: {e}")
18
+ finally:
19
+ conn.close()
pages/Task5_Delete_Data.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sqlite3
3
+
4
+ st.title("Task 5: Delete Data")
5
+
6
+ db_name = st.text_input("Enter database name:", "example.db")
7
+ delete_query = st.text_area("Enter SQL delete query (e.g., DELETE FROM students WHERE id=1):")
8
+
9
+ if st.button("Delete Data"):
10
+ try:
11
+ conn = sqlite3.connect(db_name)
12
+ cursor = conn.cursor()
13
+ cursor.execute(delete_query)
14
+ conn.commit()
15
+ rows_affected = cursor.rowcount
16
+ if rows_affected == 0:
17
+ st.warning("No data deleted. Please check your query.")
18
+ else:
19
+ st.success("Data deleted successfully!")
20
+ except Exception as e:
21
+ st.error(f"Error: {e}")
22
+ finally:
23
+ conn.close()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit