first_project
This commit is contained in:
53
check_plant_data_again.py
Normal file
53
check_plant_data_again.py
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
import mysql.connector
|
||||
|
||||
def get_connection_details():
|
||||
details = {}
|
||||
with open('setting.txt', 'r') as f:
|
||||
for line in f:
|
||||
key, value = line.strip().split(':', 1)
|
||||
details[key.strip()] = value.strip()
|
||||
return details
|
||||
|
||||
def check_plant_data_again():
|
||||
conn = None
|
||||
try:
|
||||
config = get_connection_details()
|
||||
conn = mysql.connector.connect(
|
||||
host=config.get('Host'),
|
||||
port=config.get('Port'),
|
||||
user=config.get('Username'),
|
||||
password=config.get('Password'),
|
||||
database=config.get('Database'),
|
||||
charset='utf8mb4' # Ensure consistent charset with DB table
|
||||
)
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("SELECT id, plant, department, name, extension FROM extension_data LIMIT 20")
|
||||
rows = cursor.fetchall()
|
||||
|
||||
if not rows:
|
||||
print("extension_data table is empty. No data to check.")
|
||||
return
|
||||
|
||||
print("First 20 rows of extension_data (checking 'plant' column):")
|
||||
all_plants_empty = True
|
||||
for row in rows:
|
||||
plant_value = row.get('plant')
|
||||
print(f"ID: {row.get('id')}, Plant: '{plant_value}', Department: {row.get('department')}, Name: {row.get('name')}, Extension: {row.get('extension')}")
|
||||
if plant_value is not None and plant_value != '':
|
||||
all_plants_empty = False
|
||||
|
||||
if all_plants_empty:
|
||||
print("WARNING: All 'plant' values in the first 20 rows are empty or NULL.")
|
||||
else:
|
||||
print("'plant' column seems to contain data (not all empty/NULL).")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
finally:
|
||||
if conn and conn.is_connected():
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_plant_data_again()
|
Reference in New Issue
Block a user