DEV Community

Peter + AI
Peter + AI

Posted on

Understanding Uniface 10.4's store Statement: A Complete Guide πŸš€

This blog post was created with AI assistance to help developers understand Uniface better.

The store statement in Uniface 10.4 is one of the most crucial commands for database operations. It handles validation and storage of all modified occurrences in your application. Let's dive deep into how it works! πŸ’Ύ

What is the store Statement? πŸ€”

The store statement initiates validation and storage of all occurrences marked as modified. Think of it as a "save" button that not only saves your data but also validates it first to ensure everything is correct.

An occurrence in Uniface is essentially a record or row of data that represents one instance of an entity (like one customer record in a customer table).

Basic Syntax πŸ“

The basic syntax is simple:

store
Enter fullscreen mode Exit fullscreen mode

But you can also use qualifiers for more specific operations:

store/complete
store/truncate
store/e "ENTITY_NAME"
Enter fullscreen mode Exit fullscreen mode

Key Qualifiers Explained πŸ”§

  • /e - Stores a specific entity and all its child entities
  • /complete - Builds incomplete hitlists before storing (useful for large datasets)
  • /truncate - Clears all hitlists after storing (this is the default behavior)

A hitlist is Uniface's term for a collection of retrieved database records that match your query criteria.

Return Values and Error Handling 🚨

The store statement returns different values in $status:

  • 1 - No data was stored (no modifications were made)
  • 0 - Data successfully stored βœ…
  • Negative values - Various errors occurred

Common error codes include:

  • -1 - Constraint violation (data rules were broken)
  • -6 - I/O error (like disk space issues)
  • -7 - Duplicate key (trying to create a record that already exists)
  • -10 - Record was modified by someone else

Practical Example πŸ’‘

Here's a real-world example of using store in a detail trigger:

trigger detail
 retrieve
 setocc "DEPT", 4
 store/e/complete "DEPT"
 commit
 macro "^LAST_OCC"
end; detail
Enter fullscreen mode Exit fullscreen mode

This code:

  1. Retrieves data from the database
  2. Sets the current occurrence to the 4th department record
  3. Stores the department entity with all child entities
  4. Commits the transaction to make changes permanent
  5. Navigates to the last occurrence

Important Behavior Notes ⚠️

Validation Process

Before storing, Uniface automatically validates your data by:

  • Checking data types and syntax
  • Running validation triggers
  • Verifying business rules

Locking Mechanism

After a successful store, Uniface locks the database records to prevent conflicts. These locks remain until you execute a commit or rollback.

Modification Status

The system tracks which records have been modified. After a successful store, all modification flags are reset, indicating the data is now synchronized with the database.

Best Practices 🌟

  • Always check $status after a store operation
  • Use commit or rollback to release locks
  • Consider using /complete only when necessary due to performance impact
  • Handle error cases gracefully with appropriate user messages

Performance Considerations 🏎️

The /complete qualifier can impact performance when working with large datasets because it builds complete hitlists before storing. Use it only when you need to ensure all data is available for post-store operations.

Conclusion 🎯

The store statement is essential for any Uniface application that modifies database data. Understanding its behavior, return values, and qualifiers helps you build robust applications that handle data correctly and provide good user experiences.

Remember: always validate your assumptions by testing with different data scenarios and handling error cases appropriately! πŸ§ͺ

Top comments (0)