1
00:00:03,790 --> 00:00:08,800
G'day everyone. How did you get on?
Hopefully, you managed to make the

2
00:00:08,800 --> 00:00:14,640
database changes and retrieve the timing
record from the database, if there is one.

3
00:00:14,640 --> 00:00:18,160
For my solution,
I'll start by creating the current

4
00:00:18,160 --> 00:00:24,070
Timing Contract class. All these Contract
classes are very similar, and I'll use

5
00:00:24,070 --> 00:00:33,040
the TimingsContract class as a
template. Right click TimingsContract.kt

6
00:00:33,040 --> 00:00:41,580
and choose Copy. Then right click
the package name and choose Paste.

7
00:00:41,580 --> 00:00:46,980
The new name will be CurrentTimingContract.

8
00:00:53,620 --> 00:00:59,699
We'll need to change the table name and
I'll update the comment after it.

9
00:01:17,760 --> 00:01:23,540
Next, we need to fix the column names. I'm
going to shorten them in this contract,

10
00:01:23,540 --> 00:01:49,400
and you can decide for yourself, whether
the longer names make the code more readable.

11
00:01:49,400 --> 00:01:55,200
The rows in this view don't have their
own ID, so the ID constant can be deleted.

12
00:01:55,200 --> 00:02:01,020
We have just four columns. The final
change is to delete the two functions.

13
00:02:01,020 --> 00:02:07,700
As I said, the rows in this view don't have
their own ID and these two functions won't be used.

14
00:02:15,580 --> 00:02:18,680
These Contract classes are, generally, very similar,

15
00:02:18,680 --> 00:02:24,320
but do think about what you're doing when you copy
one. If a table, or a view in this case,

16
00:02:24,320 --> 00:02:28,790
doesn't have a unique ID for each row,
then there's no point including support

17
00:02:28,790 --> 00:02:33,860
in your database classes, to access the
rows by ID. Now that we've defined the

18
00:02:33,860 --> 00:02:42,060
field names, we can create the view. We do
that in AppDatabase.

19
00:02:42,060 --> 00:02:52,480
We have to change the database version first. This will
become version 3. I'll call the function

20
00:02:52,490 --> 00:02:58,400
to create the view, addCurrentTiming
View and put it after the addTimings

21
00:02:58,400 --> 00:03:03,709
Table function. I'm going to paste the
function in. It's quite tedious, replacing

22
00:03:03,709 --> 00:03:08,450
all the table and column names with the
appropriate constants, and it's very easy

23
00:03:08,450 --> 00:03:13,820
to make mistakes. You can find the
function in resources for this video

24
00:03:13,820 --> 00:03:20,180
in the file add current timing view dot txt.

25
00:03:25,320 --> 00:03:29,519
I suggest that you start with the
correct sequel, and I've added that as a

26
00:03:29,519 --> 00:03:34,890
comment in the code. That makes it easier
to replace the individual names with

27
00:03:34,890 --> 00:03:40,470
references to the contract constant
values. Alright, we need to call the

28
00:03:40,470 --> 00:03:43,909
function from onCreate,

29
00:03:52,930 --> 00:04:00,900
and also in onUpgrade, when upgrading
from versions one or two of the database.

30
00:04:26,810 --> 00:04:31,730
Note that we have to call the function
twice. The user may be upgrading from

31
00:04:31,730 --> 00:04:38,000
version one, or they may be upgrading
from version 2. Okay that's the App

32
00:04:38,000 --> 00:04:42,680
DatabaseClass changed. This video is
getting a bit long, so we'll add the

33
00:04:42,680 --> 00:04:48,010
remaining code in the next video. I'll
see you there.

