DEV Community

Peter + AI
Peter + AI

Posted on

Mastering Uniface entitycopy: Your Complete Guide to Data Migration πŸ“Š

🎯 What is entitycopy?

The entitycopy function is a powerful batch processing instruction in Uniface 10.4 that enables you to copy one or more entity occurrences from a source database or XML file to another destination. Think of it as your Swiss Army knife for data migration tasks! πŸ› οΈ

πŸ“ Basic Syntax

entitycopy Source, Target {, Options}
Enter fullscreen mode Exit fullscreen mode

πŸ” Quick Example

entitycopy "def:myent.mymodel", "xml:ABC.xml", "append=T"
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Parameters Overview

Parameter Type Description
Source String Source of data to be copied (database path, XML file, or TRX file)
Target String Destination database path or XML file
Options String Associative list containing operation options

πŸŽ›οΈ Essential Options You Need to Know

πŸ“„ File Operations

  • append=True|False - Append data to existing XML files
  • keepopen=True|False - Keep files open for performance optimization
  • sort=True|False - Copy output in primary key order

πŸ—ΊοΈ Data Mapping

  • map=MapFile - Use custom mapping files
  • map=# - Use target repository definitions
  • map=#Entity - Map specific entities

πŸ” Filtering & Selection

  • where=SelectClause - Copy selected occurrences based on conditions
  • supersede=True|False - Overwrite existing occurrences

⚑ Performance Tuning

  • printinterval=Number - Control message frequency
  • commitinterval=Number - Set database commit frequency

πŸ’‘ Practical Examples

πŸ”„ Database to XML Export

; Export entity data to XML file
entitycopy "def:myent.mymodel", "xml:myexportfile.xml"

; Export to compressed archive
entitycopy "def:myent.mymodel", "xml:myzip.zip:myexportfile.xml"
Enter fullscreen mode Exit fullscreen mode

πŸ“₯ XML to Database Import

; Import XML data to database
entitycopy "xml:myexportfile.xml", "def:myent.mymodel"
Enter fullscreen mode Exit fullscreen mode

🎯 Advanced Filtering with WHERE

; Copy organizations A-C in Detroit
entitycopy "def:ORG.ORGSMODEL", "xml:ABCOrgs.xml", 
"printinterval=50 ;where=ORGNAME >=A&<=D!;CITY=Detroit"

; Copy products with OR condition
entitycopy "def:PRODUCT.PRODUCTS", "xml:myexportfile.xml", 
"printinterval=50 ;where=CODE >=A &<=D !;CATEGORY|=footwear"
Enter fullscreen mode Exit fullscreen mode

🚨 Error Handling & Return Values

The function returns valuable information through $procReturnContext:

  • β‰₯0: Success - Number of processed records
  • <0: Error occurred - Check $procerror for details
  • 8066: Copy failed - Input file/table open error

πŸ“Š Return Context Information

  • InputRecords - Records to be copied
  • OutputRecords - Records successfully written
  • SkippedRecords - Records not written
  • WriteErrorsContinues - Non-fatal write errors

⚠️ Important Considerations

⚑ Performance Tip: Use keepopen=True when appending multiple datasets to improve performance, but remember to explicitly flush and close the file afterward!

πŸ”’ Security Note: The copy process doesn't consider referential integrity constraints. As a developer, you must ensure correct data copying to maintain referential integrity.

β›” Critical Warning: Never use entitycopy for Repository definitions export/import - this can cause corruption! Use the dedicated export/import functionality instead.

πŸŽ‰ Conclusion

The entitycopy function is an incredibly powerful tool for data migration in Uniface 10.4. Whether you're moving data between databases, creating backups, or performing bulk operations, mastering this function will significantly enhance your development workflow. 🎯

Remember to always test your copy operations in a development environment first, and pay attention to error handling and return values for robust applications! πŸ›‘οΈ


This guide was created with AI assistance and is based on the official Uniface Documentation 10.4. Happy coding! πŸš€

Top comments (0)