123456789101112131415161718192021222324252627282930313233343536373839 |
- CREATE TABLE IF NOT EXISTS var_type (
- slabel CHAR(1) UNIQUE PRIMARY KEY,
- label VARCHAR(10) UNIQUE,
- type VARCHAR(10) NOT NULL,
- start_address INT NOT NULL DEFAULT 0,
- end_address INT NOT NULL DEFAULT 250
- );
-
- CREATE TABLE IF NOT EXISTS variable (
- type CHAR(1) NOT NULL,
- address INT NOT NULL,
- unit VARCHAR(5) NULL,
- last_update DATETIME NULL,
-
-
- FOREIGN KEY (type) REFERENCES var_type(slabel)
- ON DELETE CASCADE,
- PRIMARY KEY(type, address)
- );
-
- CREATE TABLE IF NOT EXISTS var_value (
- type CHAR(1) NOT NULL,
- address INT NOT NULL,
- time DATETIME DEFAULT CURRENT_TIMESTAMP,
- value INT NOT NULL,
-
- FOREIGN KEY (type) REFERENCES variable(type)
- ON DELETE CASCADE,
- FOREIGN KEY (address) REFERENCES variable(address)
- ON DELETE CASCADE,
- PRIMARY KEY(type, address, time)
- );
-
- INSERT INTO var_type (slabel, label, type) VALUES (
- 'A', 'Analog', 'float');
- INSERT INTO var_type (slabel, label, type) VALUES (
- 'I', 'Integer', 'int');
- INSERT INTO var_type (slabel, label, type) VALUES (
- 'D', 'Digital', 'boolean');
|