diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-03-24 11:28:35 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-03-24 11:28:35 +0100 |
commit | 7567984ca753c5a01fd8c5310e5aac5ef39a6fbc (patch) | |
tree | 4f1ebf0fe530331ca1a70e4217fc1a8e8dbd576f | |
parent | e4db9a7af3741cd18acf864c080fd3c59fc2f96c (diff) |
implement udfTotalDistance
-rw-r--r-- | dbinit/functions.sql | 16 | ||||
-rw-r--r-- | dbinit/makefile | 4 |
2 files changed, 19 insertions, 1 deletions
diff --git a/dbinit/functions.sql b/dbinit/functions.sql new file mode 100644 index 0000000..4343210 --- /dev/null +++ b/dbinit/functions.sql @@ -0,0 +1,16 @@ +drop function if exists udfTotalDistance; + +delimiter $$ +create function udfTotalDistance(raceID int) +returns int +begin + return ( + select `circuit`.`length` * `circuit`.`laps` + from `circuit` + inner join `racedatecircuit` on `racedatecircuit`.`circuitID` = `circuit`.`ID` + inner join `racedate` on `racedate`.`ID` = `racedatecircuit`.`raceDateID` + inner join `race` on `race`.`raceDateID` = `racedate`.`ID` + where `race`.`ID` = raceID); +end$$ + +delimiter ; diff --git a/dbinit/makefile b/dbinit/makefile index d412570..9e5d5d4 100644 --- a/dbinit/makefile +++ b/dbinit/makefile @@ -4,6 +4,8 @@ HOST = localhost .PHONY: clean permissions init data procedures full +all: full + # delete old tables and create new tables init: base.sql $(SQL) < $< @@ -23,7 +25,7 @@ full: full.sql base.sql: reset.sql init.sql cat $^ > $@ -full.sql: reset.sql init.sql demo.sql views.sql procedures.sql +full.sql: reset.sql init.sql demo.sql views.sql functions.sql procedures.sql cat $^ > $@ data.sql: |