Working with database controls in Uniface can be tricky, especially when you need to manipulate data that's already been fetched from the database. The release
command is a powerful tool that helps developers manage database controls effectively. With the assistance of AI, I'll walk you through everything you need to know about this essential Uniface feature. π€
This article is based on the official Uniface Documentation 10.4.
π What is the release
Command?
The release
command in Uniface removes database controls from fetched data, essentially treating the data as if it was just entered by the user. This is particularly useful when you want to:
- βοΈ Modify primary key fields
- π Convert existing records into new insertable records
- π Prepare data for insertion rather than updates
π οΈ Syntax and Usage
Basic Syntax
release{/mod}
release/e{/mod} {Entity}
π‘ Key Qualifiers
/e - Releases controls for the current or specified entity
/mod - Marks each released occurrence as modified, ensuring insertion during the next store operation
π― Example Usage
release/e ORDERS.SALES
β οΈ Important Considerations
π Database Locks
Remember that locked database occurrences remain locked until a commit
or rollback
is performed - the release
command doesn't unlock them!
πͺ Current Occurrence Behavior
Since Version 6, the last fetched occurrence becomes the current occurrence after a release. It's recommended to use setocc
to establish the desired current occurrence.
β‘ The /mod Qualifier Gotcha
When using /mod
, if you don't change the primary key before storing, you'll encounter a 'duplicate key' error. Plan accordingly! π¨
π Return Values
The release
command provides several status indicators:
$status Value | Meaning |
---|---|
0 | β Data successfully released |
-3 | β Exceptional I/O error |
-16 | π Network error: unknown |
π Practical Example
Here's a real-world example from a clear trigger that demonstrates the power of release
:
trigger clear
if ($formdb = 1)
release
message "Control released; data available as default"
return (0)
else
clear
return (0)
endif
end; clear
This example checks if form data came from the database. If so, it releases the controls, allowing the data to be modified and inserted as new records. Perfect for creating templates or duplicating existing records! πβ‘οΈπ
π― Best Practices
- πͺ Always use
setocc
afterrelease
to set the current occurrence explicitly - π When using
/mod
, ensure you modify primary keys to avoid duplicate key errors - π Remember that database locks persist after release - handle them appropriately
- β
Always check
$status
and$procerror
for error handling
π Conclusion
The release
command is an essential tool for any Uniface developer working with database operations. Understanding its behavior, especially with the /mod
qualifier and occurrence management, will help you build more robust applications. Whether you're creating data entry forms, implementing record duplication features, or managing complex database interactions, mastering release
will make your development workflow much smoother! π
Happy coding! π¨βπ»π©βπ»
Top comments (0)