DEV Community

Peter + AI
Peter + AI

Posted on

πŸ”“ Mastering Uniface's Release Statement: Unlocking Database Controls Like a Pro

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}
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ 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
Enter fullscreen mode Exit fullscreen mode

⚠️ 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
Enter fullscreen mode Exit fullscreen mode

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

  1. πŸŽͺ Always use setocc after release to set the current occurrence explicitly
  2. πŸ”‘ When using /mod, ensure you modify primary keys to avoid duplicate key errors
  3. πŸ”’ Remember that database locks persist after release - handle them appropriately
  4. βœ… 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)