#!/usr/bin/env python3 """ Check nom_articole structure and look for CAF01, FILTRU01 """ import oracledb import os from dotenv import load_dotenv # Load environment load_dotenv('.env') # Oracle configuration user = os.environ['ORACLE_USER'] password = os.environ['ORACLE_PASSWORD'] dsn = os.environ['ORACLE_DSN'] # Initialize Oracle client try: instantclient_path = os.environ.get('INSTANTCLIENTPATH', '/opt/oracle/instantclient_23_9') oracledb.init_oracle_client(lib_dir=instantclient_path) except Exception as e: pass def check_table_structure(): """Check nom_articole table structure""" print("šŸ” Checking nom_articole table structure...") try: with oracledb.connect(user=user, password=password, dsn=dsn) as conn: with conn.cursor() as cur: # Get column info cur.execute(""" SELECT column_name, data_type, nullable, data_length FROM user_tab_columns WHERE table_name = 'NOM_ARTICOLE' ORDER BY column_id """) columns = cur.fetchall() print(f"\nColumns in nom_articole:") for col in columns: print(f" {col[0]}: {col[1]}({col[3]}) - {'NULL' if col[2] == 'Y' else 'NOT NULL'}") # Check codmat values print(f"\nCodmat value distribution:") cur.execute(""" SELECT COUNT(*) as total, COUNT(codmat) as non_null, COUNT(*) - COUNT(codmat) as null_count FROM nom_articole """) stats = cur.fetchone() print(f" Total records: {stats[0]}") print(f" Non-null codmat: {stats[1]}") print(f" Null codmat: {stats[2]}") # Look for our test CODMATs print(f"\nSearching for test CODMATs (CAF01, FILTRU01)...") test_codmats = ['CAF01', 'FILTRU01'] for codmat in test_codmats: cur.execute("SELECT id_articol, codmat, denumire FROM nom_articole WHERE codmat = :1", [codmat]) results = cur.fetchall() if results: for result in results: print(f" āœ… Found {codmat}: ID={result[0]}, name='{result[2]}'") else: print(f" āŒ Not found: {codmat}") # Look for similar patterns print(f"\nSearching for similar patterns...") cur.execute("SELECT codmat, denumire FROM nom_articole WHERE codmat LIKE 'CAF%' AND codmat IS NOT NULL") results = cur.fetchall() if results: print(f" CAF* patterns found: {len(results)}") for result in results[:5]: # Show first 5 print(f" {result[0]} - {result[1]}") else: print(f" No CAF* patterns found") cur.execute("SELECT codmat, denumire FROM nom_articole WHERE codmat LIKE '%FILTR%' AND codmat IS NOT NULL") results = cur.fetchall() if results: print(f" *FILTR* patterns found: {len(results)}") for result in results[:5]: # Show first 5 print(f" {result[0]} - {result[1]}") else: print(f" No *FILTR* patterns found") except Exception as e: print(f"āŒ Check failed: {e}") def create_test_articles(): """Create test articles CAF01 and FILTRU01 for testing""" print("\nšŸ”§ Creating test articles for package testing...") try: with oracledb.connect(user=user, password=password, dsn=dsn) as conn: with conn.cursor() as cur: # Check if they already exist cur.execute("SELECT codmat FROM nom_articole WHERE codmat IN ('CAF01', 'FILTRU01')") existing = [row[0] for row in cur.fetchall()] articles_to_create = [ ('CAF01', 'CAFEA TEST - Produs test pentru import web'), ('FILTRU01', 'FILTRU CAFEA TEST - Produs test pentru seturi') ] created_count = 0 for codmat, denumire in articles_to_create: if codmat not in existing: try: # Insert new article (using negative ID for test) cur.execute(""" INSERT INTO nom_articole ( id_articol, codmat, denumire, dep, id_subgrupa, cant_bax, sters, id_mod, inactiv, in_stoc, in_crm, dnf, pretachctva, taxa_reconditionare, greutate ) VALUES ( -999999 - :seq, -- Unique negative ID :codmat, :denumire, 0, -- dep 1, -- id_subgrupa 1, -- cant_bax 0, -- sters 0, -- id_mod 0, -- inactiv 1, -- in_stoc 0, -- in_crm 0, -- dnf 0, -- pretachctva 0, -- taxa_reconditionare 0 -- greutate ) """, {'seq': created_count, 'codmat': codmat, 'denumire': denumire}) created_count += 1 print(f" āœ… Created: {codmat}") except Exception as e: print(f" āŒ Failed to create {codmat}: {e}") else: print(f" āœ… Already exists: {codmat}") if created_count > 0: conn.commit() print(f"āœ… Successfully created {created_count} test articles") else: print(f"ā„¹ļø All test articles already exist") except Exception as e: print(f"āŒ Create test articles failed: {e}") def main(): print("šŸ” nom_articole Analysis for P1-004 Testing") print("=" * 50) check_table_structure() create_test_articles() if __name__ == "__main__": main()