-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManualQuery.py
More file actions
34 lines (30 loc) · 1.23 KB
/
ManualQuery.py
File metadata and controls
34 lines (30 loc) · 1.23 KB
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
32
33
34
import streamlit as st
from CarRenatlBackend import cursor, db
from Setup import DB_NAME
import pandas as pd
def ExecuteManualQuery(query):
cursor.execute(f'use {DB_NAME}')
str(query).replace(";", '')
if "select" in str(query).lower():
cursor.execute(query)
res = cursor.fetchall()
# st.write(cursor.description)
st.table(pd.DataFrame(res, columns=[col[0] for col in cursor.description]))
elif "insert" in str(query).lower():
cursor.execute(query)
res = cursor.fetchall()
db.commit()
st.success(f'inserted successfully with id {cursor.lastrowid}', icon="✅")
# st.table(pd.DataFrame(res, columns=[col[0] for col in cursor.description]))
elif "update" in str(query).lower():
cursor.execute(query)
res = cursor.fetchall()
st.success(f'updated successfully', icon="✅")
db.commit()
# st.table(pd.DataFrame(res, columns=[col[0] for col in cursor.description]))
elif "delete" in str(query).lower():
cursor.execute(query)
res = cursor.fetchall()
db.commit()
st.success(f'deleted successfully', icon="✅")
# st.table(pd.DataFrame(res, columns=[col[0] for col in cursor.description]))