Correctly fetch main location IDs

We updated the table structure , so that for main locations the main
location ID is NULL; Otherwise there were issue when removing rows with
self-references and foreign keys.
Handler dependencies not yet defined
Construct trash handler correctly
Use correct is null expression
Create uniw remote ID when duplicating type