In Part 2 of this project, we use this representation for defining an extension of Datalog akin to TSQL2
date(Year, Month, Day)
This (i) will be stored using complex terms, (ii) corresponds to SQL2 DATE, and (iii) satisfies the constraints of the same.
SQL2 TIME and TIMESTAMP will not be supported.
month_cast($Date1, Date2)
year_cast($Date1, Date2)
day_cast($Date1, Date2)
When Date1 has granularity of days then Date2 is identical to Date1. Morevover:
month_cast(date(1987,0,0), X)
yields
X= date(1987,1,0)
day_cast(date(1987,8,0), X)
yields
X= date(1987,8,1)
day_cast(date(1987,0,0), X)
yields
X= date(1987,1,1)
same_date(Date1, Date2)
before($DATE1, $DATE2)
When the dates being compared have different granularities, an implicit conversion to the coarser granularity is performed.
months(Months) and days(Days)
Thus we have two types of intervals, as in SQL2 (but we do not allow things such as YEAR TO MONTH)
months_btwn($Date1, $Date2, Interval)
days_btwn ($Date1, $Date2, Interval)
time_add ($DATE1, $Interval, NewDate)
date(0,0,0) which denotes an
invalid date.
cd(CD#, Deposit_Date, Duration, Interest_to_Maturity)
Duration is a time interval expressed in days)
You must implement the following query which computes the actual interest paid at a given date.
pay($CD, $Withd_date, Interest_paid)
Duration days have elapsed,
Duration days have elapsed, but
before maturity, then pay 0.01 % interest for each day
between deposit and withdrawl,
Interest_to_Maturity
,
Thus short sample of the database might be as follows:
prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1996,12,31)).
prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,01)).
prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,02)).
prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,02)).
prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,03)).
prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,06)).
prescript('Sally', 'Beren', 'Prozac', 100mg, 360, date(1997,01,03)).
prescript('Sally', 'Beren', 'Prozac', 100mg, 360, date(1997,01,04)).
prescript('Sally', 'Beren', 'Prozac', 100mg, 360, date(1997,01,0)).
Define a LDL++ schema for this fact base, and then express the following queries: