Spaces:
Paused
Paused
| 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)}") | |