Initial commit

This commit is contained in:
user
2026-07-12 13:47:34 +04:00
commit 51e2e789d0
37 changed files with 2005 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
DROP TABLE IF EXISTS Tables;
DROP TABLE IF EXISTS Bookings;
DROP TRIGGER IF EXISTS CHK_Bookings_Insert;
+33
View File
@@ -0,0 +1,33 @@
CREATE TABLE IF NOT EXISTS Tables (
-- column-def:
id INTEGER -- column-constraint:
CONSTRAINT PK_Tables PRIMARY KEY AUTOINCREMENT,
--
name INTEGER NOT NULL UNIQUE,
--
max_people INTEGER NOT NULL,
--
room TEXT NOT NULL,
-- table-constraint:
CONSTRAINT CHK_max_people CHECK (
max_people > 0
AND max_people < 11
)
);
CREATE TABLE IF NOT EXISTS Bookings (
-- column-def:
id INTEGER -- column-constraint:
CONSTRAINT PK_Bookings PRIMARY KEY AUTOINCREMENT,
--
id_tables INTEGER,
--
reservation TEXT NOT NULL,
--
time_reserve TEXT NOT NULL,
--
who_booked TEXT NOT NULL,
-- table-constraint:
CONSTRAINT FK_Bookings_Tables FOREIGN KEY (id_tables) REFERENCES Tables (id),
CONSTRAINT CHK_min_max_time_reserve CHECK (time_reserve BETWEEN "00:30" AND "12:00")
);
+21
View File
@@ -0,0 +1,21 @@
CREATE TRIGGER IF NOT EXISTS CHK_Bookings_Insert BEFORE INSERT ON Bookings BEGIN
SELECT
RAISE (
FAIL,
"Reservation of table is not possible due to the existing reservation"
)
FROM
(
SELECT
datetime (NEW.reservation) AS new_res_dt,
datetime (reservation) AS res_dt,
datetime (reservation, time_reserve) AS reserved_until
FROM
Bookings
)
WHERE
new_res_dt >= res_dt
OR new_res_dt < reserved_until;
--
END;
+7
View File
@@ -0,0 +1,7 @@
INSERT INTO
Tables (name, max_people, room)
VALUES
(1, 5, "Red room"),
(4, 4, "Red room"),
(2, 7, "Green room"),
(3, 10, "Game hall");
+144
View File
@@ -0,0 +1,144 @@
-- reservation format "YYYY-MM-DDTHH:MM"
-- time_reserve "HH:MM"
-- fail check time_reserve
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T00:00", "00:00", "");
-- fail check time_reserve
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T00:00", "00:29", "");
-- fail check time_reserve
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T00:00", "12:01", "");
-- success check time_reserve
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T00:00", "00:30", "");
-- success until 02:30
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T01:00", "01:30", "");
-- fail check begin
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T00:30", "01:00", "");
-- fail check middle
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T00:30", "01:30", "");
-- fail check end
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T00:30", "02:00", "");
-- fail check begin
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T01:00", "00:30", "");
-- fail check middle
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T01:30", "00:30", "");
-- fail check end
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T02:00", "00:30", "");
-- success
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T02:30", "00:30", "");
-- success
INSERT INTO
Bookings (
id_tables,
reservation,
time_reserve,
who_booked
)
VALUES
(1, "2000-01-01T03:00", "00:30", "");
+10
View File
@@ -0,0 +1,10 @@
SELECT -- Incorrect table reservations
Left.reservation,
datetime (Left.reservation, Left.time_reserve) AS reserved_until,
Right.reservation
from
Bookings AS Left
LEFT JOIN Bookings AS Right ON Left.id != Right.id
AND Left.id_tables = Right.id_tables
WHERE
datetime (Right.reservation) BETWEEN datetime (Left.reservation) AND datetime (Left.reservation, Left.time_reserve)