Projet de remplacement du "RPiPasserelle" d'Otec.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pyheatpump.sql 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. CREATE TABLE IF NOT EXISTS var_type (
  2. slabel CHAR(1) UNIQUE PRIMARY KEY,
  3. label VARCHAR(10) UNIQUE,
  4. type VARCHAR(10) NOT NULL,
  5. start_address INT NOT NULL DEFAULT 0,
  6. end_address INT NOT NULL DEFAULT 250
  7. );
  8. CREATE TABLE IF NOT EXISTS variable (
  9. type CHAR(1) NOT NULL,
  10. address INT NOT NULL,
  11. unit VARCHAR(5) NULL,
  12. last_update INT NULL,
  13. FOREIGN KEY (type) REFERENCES var_type(slabel)
  14. ON DELETE CASCADE,
  15. PRIMARY KEY(type, address)
  16. );
  17. CREATE TABLE IF NOT EXISTS var_value (
  18. type CHAR(1) NOT NULL,
  19. address INT NOT NULL,
  20. time INT DEFAULT (strftime('%s', datetime('now'))),
  21. value INT NOT NULL,
  22. FOREIGN KEY (type) REFERENCES variable(type)
  23. ON DELETE CASCADE,
  24. FOREIGN KEY (address) REFERENCES variable(address)
  25. ON DELETE CASCADE,
  26. PRIMARY KEY(type, address, time)
  27. );
  28. INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
  29. 'A', 'Analog', 'float', 1, 1251);
  30. INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
  31. 'I', 'Integer', 'int', 5002, 6253);
  32. INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
  33. 'D', 'Digital', 'bool', 1, 1001);
  34. CREATE TRIGGER variable_last_update AFTER INSERT ON var_value
  35. FOR EACH ROW
  36. BEGIN
  37. UPDATE variable
  38. SET last_update = NEW.time
  39. WHERE
  40. type = NEW.type
  41. AND
  42. address = NEW.address;
  43. END;