DEV Community

Peter + AI
Peter + AI

Posted on

πŸ”— Mastering Uniface reconnect: Merging Disconnected Data with Live Components

Working with disconnected data sets is a common challenge in enterprise applications. Today, let's dive deep into Uniface's reconnect command - a powerful tool for merging XML, JSON, or Struct data back with live component occurrences and database connections. πŸš€

This article is based on the official Uniface Documentation 10.4 and was created with AI assistance to help developers understand this essential command better.

πŸ“‹ What is reconnect?

The reconnect command resolves modification state information stored in occurrence metadata after loading data using xmlload, webload, or structToComponent statements.

πŸ”§ Syntax

reconnect {/readcheck} {EntityName}
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Parameters & Qualifiers

  • /readcheck (optional): Ignores user modifications on read-only fields and restores values from database
  • EntityName (optional): String specifying the component entity name

🎯 How It Works

The reconnect process follows a specific procedure based on occurrence modification states:

$occstatus $occmod $storetype $occdel Description
"" 1 1 0 πŸ†• Treated as new occurrence
"new" 1 1 0 πŸ†• New occurrence
"est" 0 0 0 βœ… Existing unmodified occurrence
"mod" 1 0 0 ✏️ Existing modified occurrence
"del" X X 1 πŸ—‘οΈ Marked as deleted occurrence

πŸ”’ Read-Only Field Handling

Fields become read-only when:

  • Field syntax definition specifies NED (no edit allowed) 🚫
  • Field syntax changed to NED at runtime via fieldsyntax or $fieldsyntax

Using the /readcheck qualifier will ignore user modifications to read-only fields and restore original database values. πŸ”„

πŸ“Š Return Values

  • 0: βœ… Successful reconnection
  • >0: ❌ Number of errors encountered (negative error trigger returns)

⚑ Performance Benefits

The reconnect statement intelligently merges only disconnected occurrences with modification states other than "est". This approach:

  • πŸš€ Improves performance significantly
  • πŸ›‘οΈ Avoids unnecessary CRC errors on unmodified occurrences
  • 🎯 Uses ID property for efficient merging

πŸ’‘ Practical Example

; Basic reconnect example
xmlload "/data/customer_updates.xml", "CUSTOMERS"
reconnect

; Reconnect with read-check for specific entity
xmlload "/data/orders.xml", "ORDERS"  
reconnect /readcheck ORDERS

; Check the result
if ($status = 0)
    message "Data successfully reconnected! βœ…"
else
    message "Reconnect failed with %%$status%% errors ❌"
endif
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ Conclusion

The reconnect command is essential for modern Uniface applications handling disconnected data scenarios. Understanding its behavior with different occurrence states and proper use of qualifiers like /readcheck ensures reliable data synchronization and optimal performance.

Remember: reconnect works with all component types and automatically handles validation flags, modification states, and database locking when using cautious locking mode! πŸ”


Have you used reconnect in your Uniface projects? Share your experiences in the comments below! πŸ’¬

Top comments (0)