#!/usr/bin/env python3 """ Test PACK_JSON with direct Oracle calls """ 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 test_pack_json_simple(): """Test PACK_JSON with hardcoded JSON""" print("๐Ÿงช Testing PACK_JSON with simple JSON...") try: with oracledb.connect(user=user, password=password, dsn=dsn) as conn: with conn.cursor() as cur: # Test with simple hardcoded JSON print("Testing parse_array...") cur.execute(""" SELECT * FROM TABLE(PACK_JSON.parse_array('[{"sku":"TEST01","cantitate":2,"pret":10.5}]')) """) results = cur.fetchall() print(f"Parse array results: {len(results)} items") for result in results: json_item = result[0] print(f"JSON item: {json_item}") # Test get functions cur.execute(f"SELECT PACK_JSON.get_string('{json_item}', 'sku') FROM DUAL") sku = cur.fetchone()[0] print(f"SKU: {sku}") except Exception as e: print(f"โŒ PACK_JSON test failed: {e}") def test_pack_comenzi_direct(): """Test PACK_COMENZI.adauga_comanda directly to check for CASE issues""" print("\n๐Ÿงช Testing PACK_COMENZI.adauga_comanda directly...") try: with oracledb.connect(user=user, password=password, dsn=dsn) as conn: with conn.cursor() as cur: partner_id = -1 # Known test partner # Test direct call to adauga_comanda print("Testing PACK_COMENZI.adauga_comanda...") try: # Create a simple cursor to test the call cur.execute(""" DECLARE v_id_comanda NUMBER; BEGIN PACK_COMENZI.adauga_comanda( V_NR_COMANDA => 'TEST-DIRECT-001', V_DATA_COMANDA => SYSDATE, V_ID => :partner_id, V_DATA_LIVRARE => SYSDATE + 1, V_PROC_DISCOUNT => 0, V_INTERNA => 0, V_ID_UTIL => -3, V_ID_SECTIE => 1, V_ID_ADRESA_FACTURARE => NULL, V_ID_ADRESA_LIVRARE => NULL, V_ID_CODCLIENT => NULL, V_COMANDA_EXTERNA => 'TEST-DIRECT-001', V_ID_CTR => NULL, V_ID_COMANDA => v_id_comanda ); :result := v_id_comanda; END; """, {'partner_id': partner_id, 'result': cur.var(oracledb.NUMBER)}) result_var = cur.getvar('result') print(f"โœ… PACK_COMENZI.adauga_comanda succeeded: ID = {result_var}") except Exception as e: print(f"โŒ PACK_COMENZI.adauga_comanda failed: {e}") except Exception as e: print(f"โŒ Direct test failed: {e}") def main(): print("๐Ÿ” Direct PACK_JSON and PACK_COMENZI Tests") print("=" * 50) test_pack_json_simple() test_pack_comenzi_direct() if __name__ == "__main__": main()