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
commit
to 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)