DEV Community

Peter + AI
Peter + AI

Posted on

πŸ”— Understanding Referential Integrity in Uniface 10.4 Components

πŸ“ Note: This blog post was created with AI assistance to make Uniface documentation more accessible.

🎯 What Is This About?

When building applications in Uniface, you need to understand how referential integrity works. This is a fancy term for making sure that relationships between your data tables stay valid. Think of it like this: if you delete a customer, what happens to their orders? Referential integrity helps manage these relationships.

πŸ—οΈ Component Data Structure Basics

In Uniface, how you define your component's data structure directly affects how the system checks these relationships. When you compile a component, Uniface might show you a warning message like this:

-1074 RelatedEntity missing for integrity control on del/upd of AnEntity

Don't panic! 😊 This warning appears when Uniface notices you might delete records without having the related entities in your component structure.

πŸ’‘ The Simple Solution

The easiest way to handle referential integrity in Uniface is to insert related many-entities as children of the one-entity in your component data structure.

Example:

Imagine you have these entities:

  • 🏒 CUSTOMER (one entity)
  • πŸ“¦ ORDERS (many entity - one customer can have many orders)

In your component structure, you should place ORDERS as a child under CUSTOMER. This way, when someone tries to delete a customer, Uniface automatically checks if there are any related orders and prevents data corruption.

⚑ When Does Uniface Skip Checks?

Uniface is smart enough to recognize when you've included an entity just for integrity checking. It will skip unnecessary operations if ALL of these conditions are true:

  • βœ… The entity is inserted without its fields
  • βœ… The entity's triggers haven't been modified
  • βœ… Your component code doesn't reference any fields from this entity

When these conditions are met, the read trigger won't fire after retrieving the outer entity, which improves performance. πŸš€

πŸ“‹ Best Practices and Guidelines

1. Think Before Adding Many-Entities

Consider the performance impact! Retrieving many related records can slow things down. If your component doesn't allow deletes, you might not need these integrity checks at all.

2. Database Triggers

If your database management system (DBMS) supports referential integrity with its own triggers, Uniface will detect this and let the database handle it. However, it's safer to include the entities in your component structure anyway - this protects you if you ever move to a different database system. πŸ›‘οΈ

3. Hitlist Problem

Be careful with forms that display multiple occurrences of a many-entity. Uniface needs to build the entire hitlist first, which can be slow. In these cases, using field lists might be more efficient.

4. Disable Scroll Bars

For occurrences of many-entities used only for integrity checking, disable scroll bars to prevent confusion.

πŸŽ“ Real-World Scenario

Let's say you're building an order management system:

  • Your ORDER_FORM component displays customer information
  • Users can delete customer records through this form
  • Each customer might have multiple orders and invoices

To maintain data integrity, you should include both ORDERS and INVOICES entities in your component structure as children of CUSTOMER. This ensures that:

  • 🚫 Users can't accidentally delete customers who have orders
  • πŸ’Ύ Your data stays consistent across all tables
  • βœ”οΈ The system automatically enforces business rules

🎯 Key Takeaways

  • Always include related entities in your component structure to enforce referential integrity
  • Understand the warning message -1074 and when you can safely ignore it
  • Let your DBMS handle integrity checks when possible, but keep backup definitions
  • Balance integrity checking with performance considerations
  • Use field lists for better performance with many-entity occurrences

πŸš€ Conclusion

Referential integrity in Uniface might seem complex at first, but following these guidelines helps you build robust applications. The key is understanding the relationship between your component data structure and how Uniface checks data relationships. By properly defining your component entities, you create applications that protect data integrity while maintaining good performance.

Happy coding! πŸ’»βœ¨

Top comments (0)