Resolving DUPLICATE for a column with UNIQUE
I would look at your model first.  Placing a unique key constraint on a non-unique column gets you into this kind of problem.  What happens when you get a legitimate value like test title-2 but you've already used that value to resolve a collision on test title.

If I had to resolve your problem, I would build a query for each unique key of the form:

SELECT  title
FROM    table1
WHERE   title STARTS WITH ?


The results will need to be parsed to see what the suffix should be.  It might be possible to do this in a stored procedure.  However, I would strongly argue that the data model needed to be fixed, not the code.