vector_metadata_table.sql 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --#############################################################################
  2. -- This SQL script generates the vector table to store
  3. -- metadata for SQL queries and temporal GIS support.
  4. --
  5. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  6. --#############################################################################
  7. --PRAGMA foreign_keys = ON;
  8. -- The metadata table
  9. CREATE TABLE vector_metadata (
  10. id VARCHAR NOT NULL, -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name@mapset) and is used as primary foreign key
  11. stvds_register VARCHAR, -- The name of the table storing all space-time vector datasets in which this map is registered
  12. PRIMARY KEY (id),
  13. FOREIGN KEY (id) REFERENCES vector_base (id) ON DELETE CASCADE
  14. );
  15. -- Create the views to access all columns for the absolute and relative time
  16. CREATE VIEW vector_view_abs_time AS SELECT
  17. A1.id, A1.mapset,
  18. A1.name, A1.layer, A1.temporal_type,
  19. A1.creation_time,
  20. -- Uncommented due to performance issues
  21. -- A1.modification_time, A1.revision,
  22. A1.creator,
  23. A2.start_time, A2.end_time, A2.timezone,
  24. A3.north, A3.south, A3.east, A3.west, A3.proj,
  25. A4.stvds_register
  26. FROM vector_base A1, vector_absolute_time A2,
  27. vector_spatial_extent A3, vector_metadata A4
  28. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  29. CREATE VIEW vector_view_rel_time AS SELECT
  30. A1.id, A1.mapset,
  31. A1.name, A1.layer, A1.temporal_type,
  32. A1.creation_time,
  33. -- Uncommented due to performance issues
  34. -- A1.modification_time, A1.revision,
  35. A1.creator,
  36. A2.start_time, A2.end_time,
  37. A3.north, A3.south, A3.east, A3.west, A3.proj,
  38. A4.stvds_register
  39. FROM vector_base A1, vector_relative_time A2,
  40. vector_spatial_extent A3, vector_metadata A4
  41. WHERE A1.id = A2.id AND A1.id = A3.id AND A1.id = A4.id;
  42. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  43. -- Uncommented due to performance issues
  44. --CREATE TRIGGER update_vector_metadata AFTER UPDATE ON vector_metadata
  45. -- BEGIN
  46. -- UPDATE vector_base SET modification_time = datetime("NOW") WHERE id = old.id;
  47. -- UPDATE vector_base SET revision = (revision + 1) WHERE id = old.id;
  48. -- END;