--SourceTemplates_CopyBuiltin2Editable.sql
/* 2017-04-17 Tom Holden ve3meo
Copies the builtin Source Templates to User Editable copies. 
Same name prefixed by *. Can be applied to new database or to
one with custom source templates. For convenience on inspection 
and correlation, the copies are assigned the same TemplateID 
as the original offset by a multiple of 10000.
*/
BEGIN
;
INSERT OR REPLACE INTO SourceTemplateTable
SELECT
  ( 
   SELECT
     CASE
       WHEN MAX(TemplateID)/10000 
       THEN MAX(TemplateID)/1000*1000+1000
     ELSE 10000
     END
   FROM SourceTemplateTable
  ) + TemplateID AS TemplateID -- builtin TemplateID offset by n*10000
  , '*' || Name AS Name
  , Description
  , Favorite
  , Category
  , Footnote
  , ShortFootnote
  , Bibliography
  , FieldDefs
FROM SourceTemplateTable
WHERE TemplateID < 10000
;
COMMIT
;