stvds_metadata_table.sql 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --#############################################################################
  2. -- This SQL script generates the space time vector dataset metadata table,
  3. -- view and trigger
  4. --
  5. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  6. --#############################################################################
  7. --PRAGMA foreign_keys = ON;
  8. CREATE TABLE stvds_metadata (
  9. id VARCHAR NOT NULL, -- Name of the space-time vector dataset, this is the primary foreign key
  10. vector_register VARCHAR, -- The id of the table in which the vector maps are registered for this dataset
  11. number_of_maps INTEGER, -- The number of registered vector maps
  12. title VARCHAR, -- Title of the space-time vector dataset
  13. description VARCHAR, -- Detailed description of the space-time vector dataset
  14. PRIMARY KEY (id),
  15. FOREIGN KEY (id) REFERENCES stvds_base (id) ON DELETE CASCADE
  16. );
  17. -- Create the views to access all columns for absolute or relative time
  18. CREATE VIEW stvds_view_abs_time AS SELECT
  19. A1.id, A1.name, A1.mapset, A1.temporal_type,
  20. A1.semantic_type,
  21. A1.creation_time,
  22. -- Uncommented due to performance issues
  23. -- A1.modification_time, A1.revision,
  24. A1.creator,
  25. A2.start_time, A2.end_time, A2.timezone,
  26. A2.granularity,
  27. A3.north, A3.south, A3.east, A3.west, A3.proj,
  28. A4.vector_register,
  29. A4.number_of_maps,
  30. A4.title, A4.description
  31. FROM stvds_base A1, stvds_absolute_time A2,
  32. stvds_spatial_extent A3, stvds_metadata A4 WHERE A1.id = A2.id AND
  33. A1.id = A3.id AND A1.id = A4.id;
  34. CREATE VIEW stvds_view_rel_time AS SELECT
  35. A1.id, A1.name, A1.mapset, A1.temporal_type,
  36. A1.semantic_type,
  37. A1.creation_time,
  38. -- Uncommented due to performance issues
  39. -- A1.modification_time, A1.revision,
  40. A1.creator,
  41. A2.start_time, A2.end_time, A2.granularity,
  42. A3.north, A3.south, A3.east, A3.west, A3.proj,
  43. A4.vector_register,
  44. A4.number_of_maps,
  45. A4.title, A4.description
  46. FROM stvds_base A1, stvds_relative_time A2,
  47. stvds_spatial_extent A3, stvds_metadata A4 WHERE A1.id = A2.id AND
  48. A1.id = A3.id AND A1.id = A4.id;
  49. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  50. -- Uncommented due to performance issues
  51. --CREATE TRIGGER update_stvds_metadata AFTER UPDATE ON stvds_metadata
  52. -- BEGIN
  53. -- UPDATE stvds_base SET modification_time = datetime("NOW") WHERE id = old.id;
  54. -- UPDATE stvds_base SET revision = (revision + 1) WHERE id = old.id;
  55. -- END;