As a developer working with Uniface, understanding database transaction management is crucial for building robust applications. Today, let's dive deep into one of the most important statements in Uniface: the commit statement! 💾
This article is based on the official Uniface 10.4 documentation and was created with the assistance of AI to help fellow developers understand this essential concept.
🎯 What is the commit Statement?
The commit statement in Uniface is your go-to tool for permanently saving database changes. It commits a transaction to a DBMS or specific path, ensuring your data modifications are safely stored.
Basic Syntax:
commit {"PathString"}
Quick Example:
commit "DEF"
📋 Parameters Breakdown
The PathString parameter is where the magic happens! Here's how it works:
🔍 Path with Dollar Sign ($)
When your PathString starts with a dollar sign, Uniface treats it as a path name:
commit "$DEF"
This commits modifications to all entities accessed through that specific path, based on assignments.
🗃️ DBMS Name (No Dollar Sign)
Without a dollar sign, the argument represents a DBMS defined in your modeled entities:
commit "DEF"
This commits all entities assigned to that DBMS, determined by the modeled entity definition.
🌐 Global Commit (No Parameters)
Omit the parameter for a complete commit:
commit
This commits all pending updates across all databases and unlocks all locked occurrences! 🔓
📊 Return Values & Error Handling
The commit statement returns values in $status to help you handle different scenarios:
✅ Success Values
- 0: Data successfully committed! 🎉
⚠️ Error Values
- -3: Exceptional I/O error (hardware/software issues)
- -9: Maximum DBMS logons reached
- -16: Network error
Additional error constants in $procerror include:
- -2 through -12: Database I/O errors (
UIOSERR_*) - -16 through -30: Network I/O errors (
UNETERR_*) - -1107: Invalid path name (
UPROCERR_PATH)
💡 Best Practices & Tips
🏗️ Component Level Strategy
Always place your commit (or rollback) statements at the highest component level to avoid currency problems:
If Component B is activated by Component A, place the commit statement in Component A, not Component B!
🧠 Memory Management Exception
If your component's Component Behavior property is set to "Keep component definition and data in memory", use commit at that component's level instead.
🔨 Practical Example
Here's a real-world example showing proper error handling with commit:
trigger store
call CENSTORE
return ($status)
end; store
function CENSTORE
store
if ($status < 0)
message "Store error!"
rollback
else
message "Store complete."
commit
if ($status < 0)
message "Commit error, rollback performed."
rollback
endif
endif
end; CENSTORE
🎭 DEF vs $DEF: A Tale of Two Commits
Understanding the difference between commit "DEF" and commit "$DEF" is crucial:
Setup Scenario:
$DEF = $ORA
FRODO.MYMODEL = $SYB
Different Behaviors:
-
commit "DEF"→ Commits all entities in MYMODEL (default DBMS) -
commit "$DEF"→ Commits all entities except FRODO (path-based)
🎯 Key Takeaways
- ✨ Use
committo permanently save your database changes - 🔄 Always handle return values for robust error management
- 📍 Place commits at the appropriate component level
- 💰 Understand the difference between path-based and DBMS-based commits
- 🛡️ Some DBMS don't support locking - commits are ignored in these cases
Understanding the commit statement is essential for any serious Uniface developer. It's the foundation of reliable data persistence and transaction management! 🚀
Happy coding, and may your transactions always commit successfully! 💪
Top comments (0)