File size: 1,070 Bytes
e4fe207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import random
import streamlit as st
import time
import pandas as pd

def generate_unique_4(cursor, col_id, tblname):
    while True:
        unique_id = random.randint(1000, 9999)
        cursor.execute(f"SELECT {col_id} FROM {tblname} WHERE {col_id} = {unique_id}")
        result = cursor.fetchone()
        if result is None:
            return unique_id

def display_table(cursor, table_name):
    try:
        cursor.execute(f"pragma table_info('{table_name}')")
        column_data = cursor.fetchall()
        column_names = [column[1] for column in column_data]

        cursor.execute(f"SELECT * FROM {table_name}")
        data = cursor.fetchall()
        
        if not data:
            st.warning(f"No data found in the {table_name} table.")
        else:
            df = pd.DataFrame(data, columns=column_names)
            st.header(f"{table_name} Table")
            st.dataframe(df.style.set_properties(**{'text-align': 'center'}))
    
    except Exception as e:
        st.error(f"An error occurred while fetching data from {table_name}: {str(e)}")