-- WebTags-DeleteDuplicates-RM8.sql
/*
2012-12-10 Tom Holden ve3meo
rev 2023-02-23 RM8 version

Repeated use of WebTags-Consolidate.sql will result in duplicate WebTags
as may some other operations. This query eliminates the duplicates
by copying the unique WebTags to a temporary table, deleting all records 
from URLTable, and copying the records from the temporary table back
into URLTable.

For RM8, this has the effect of updating UTCModDate to today. I don't
think that is a problem.
*/

DROP TABLE IF EXISTS tmpURLTable
;

CREATE TEMP TABLE IF NOT EXISTS tmpURLTable AS

SELECT DISTINCT
  NULL AS LinkID,
  OwnerType,
  OwnerID,
  LinkType,
  Name,
  URL,
  Note
--  ,Null AS UTCModDate --RM8
  FROM URLTable
;

DELETE FROM URLTable
;

INSERT INTO URLTable
SELECT *
       ,julianday('now') - 2415018.5 AS UTCModDate -- RM8 
  FROM tmpURLTable
;

DROP TABLE IF EXISTS tmpURLTable
;