import mariadb # Database connection credentials db_config = { "user": "trasabilitate", "password": "Initial01!", "host": "localhost", "database": "trasabilitate" } # Connect to the database try: conn = mariadb.connect(**db_config) cursor = conn.cursor() print("Connected to the database successfully!") # Create the scan1_orders table create_table_query = """ CREATE TABLE IF NOT EXISTS scan1_orders ( Id INT AUTO_INCREMENT PRIMARY KEY, -- Auto-incremented ID with 6 digits operator_code VARCHAR(4) NOT NULL, -- Operator code with 4 characters CP_full_code VARCHAR(15) NOT NULL UNIQUE, -- Full CP code with up to 15 characters OC1_code VARCHAR(4) NOT NULL, -- OC1 code with 4 characters OC2_code VARCHAR(4) NOT NULL, -- OC2 code with 4 characters CP_base_code VARCHAR(10) GENERATED ALWAYS AS (LEFT(CP_full_code, 10)) STORED, -- Auto-generated base code (first 10 characters of CP_full_code) quality_code INT(3) NOT NULL, -- Quality code with 3 digits date DATE NOT NULL, -- Date in format dd-mm-yyyy time TIME NOT NULL, -- Time in format hh:mm:ss approved_quantity INT DEFAULT 0, -- Auto-incremented quantity for quality_code = 000 rejected_quantity INT DEFAULT 0 -- Auto-incremented quantity for quality_code != 000 ); """ cursor.execute(create_table_query) print("Table 'scan1_orders' created successfully!") # Commit changes and close the connection conn.commit() cursor.close() conn.close() except mariadb.Error as e: print(f"Error connecting to the database: {e}")