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
But you can also use qualifiers for more specific operations:
store/complete store/truncate store/e "ENTITY_NAME"
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
This code:
- Retrieves data from the database
- Sets the current occurrence to the 4th department record
- Stores the department entity with all child entities
- Commits the transaction to make changes permanent
- 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 astore
operation - Use
commit
orrollback
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)