Added a SQLite section to query_next_available_episode.md
parent
9c2a66f9f3
commit
9df590f855
@ -1,4 +1,4 @@
|
||||
# Documentation of the `query query_next_available_episode`
|
||||
# Documentation of the query `query_next_available_episode`
|
||||
|
||||
## Purpose
|
||||
|
||||
@ -153,6 +153,33 @@ Using the full query against the database on 2023-10-12 we get the following res
|
||||
+---------+------------+------------+
|
||||
```
|
||||
|
||||
## Differences in the SQLite version
|
||||
|
||||
1. Many of the functions used take string arguments, and since the query is
|
||||
stored in a single-quoted string, these have to be escaped with a backslash.
|
||||
|
||||
2. The SQLite function to get the current date is `date('now')`
|
||||
|
||||
3. The SQLite function to get the day of the week from a date is
|
||||
`strftime('%w',last_date)` and the values are 0 for Sunday and 6 for Saturday.
|
||||
|
||||
4. When adding days to a date in SQLite the function is `date(date,'+3 days')`
|
||||
and this is why such strings are returned from the `CASE` statement.
|
||||
|
||||
5. To compute the difference in days between two dates in SQLite it is
|
||||
necessary to convert dates to Julian dates and subtract the values. This can
|
||||
give a negative result, so we use `abs()` to prevent it. The result is
|
||||
fractional because of the way Julian dates are implemented in SQLite, so
|
||||
`printf('%i,?)` is used to get the integer part. Therefore, the following
|
||||
expression is needed:
|
||||
```
|
||||
printf('%i',
|
||||
abs(
|
||||
julianday(DATE (prev_date, date_offset)) -
|
||||
julianday('now') + 1)
|
||||
) AS delta_days
|
||||
```
|
||||
|
||||
<!--
|
||||
vim: syntax=pandoc:ts=8:sw=4:tw=0:et:ai:
|
||||
-->
|
||||
|
Loading…
Reference in New Issue
Block a user