Loading...
Loading...
In DB2 database programming with COBOL, SQLCODE -803 indicates a duplicate key violation — you attempted to INSERT a row that would violate a unique constraint or primary key on a table. Handling this gracefully is critical in enterprise batch processing systems where records may be re-processed or feeds may contain duplicates.
You are tasked with simulating the logic of a COBOL DB2 error handler. Given a list of database INSERT operations (each represented as a record ID), your program must simulate what happens when duplicates are encountered and return the final state of the database table along with an operation log.
Given a list of integer record IDs representing attempted INSERT operations into a unique-key database table, simulate the DB2 insert behavior:
Return two things:
A single list of integers operations representing record IDs to be inserted, in order.
Return a tuple/pair: (sorted list of unique inserted IDs, count of duplicate errors).
Input: operations = [101, 202, 303, 101, 404, 202]
Output: ([101, 202, 303, 404], 2)
Explanation:
Input: operations = [1, 2, 3, 4, 5]
Output: ([1, 2, 3, 4, 5], 0)
Explanation: All inserts are unique, no -803 errors occur.
Input: operations = [7, 7, 7, 7]
Output: ([7], 3)
Explanation: First insert succeeds, the next three all trigger SQLCODE -803.
1 <= operations.length <= 10^5 1 <= operations[i] <= 10^9 All values are positive integers