1
00:00:00,710 --> 00:00:01,490
Welcome back.

2
00:00:01,730 --> 00:00:08,750
In the last year, we had this little book where we recreated or duplicated entries when we edited them,

3
00:00:08,750 --> 00:00:13,300
so we kept the old country, but we created a new entry with the updated values.

4
00:00:13,580 --> 00:00:15,290
So let's fix that problem.

5
00:00:16,010 --> 00:00:21,140
First of all, we have to go to our database handler because that's where we handle all of our database

6
00:00:21,140 --> 00:00:21,460
stuff.

7
00:00:21,770 --> 00:00:28,610
And here we had to create an update and then we had this fun and happy place function.

8
00:00:29,030 --> 00:00:33,590
And we're going to create a similar one, which I'm going to call update happy place.

9
00:00:33,860 --> 00:00:41,810
Now, we could, of course, go ahead and create functions which are depending on a country that you

10
00:00:41,810 --> 00:00:43,400
have here or a parameter.

11
00:00:43,640 --> 00:00:48,770
But I think in this case, it really makes sense to have two functions, one for adding, the other

12
00:00:48,770 --> 00:00:52,070
one for updating, even though they are so super similar to each other.

13
00:00:52,670 --> 00:00:53,030
All right.

14
00:00:53,040 --> 00:00:55,880
So first of all, we need a database that is rewritable.

15
00:00:55,880 --> 00:00:58,040
So that stays the same then.

16
00:00:59,630 --> 00:01:05,960
Everything else should also stay the same, except for this part where we insert something, so instead

17
00:01:05,960 --> 00:01:12,250
of inserting something to the database, what we want to do is, of course, to the update something.

18
00:01:12,350 --> 00:01:19,100
So let's create this variable called success and call DB Update.

19
00:01:19,250 --> 00:01:24,050
So database, which is this writable database update.

20
00:01:24,290 --> 00:01:26,390
And then we need to say what we want to update.

21
00:01:26,420 --> 00:01:33,740
So I want to update the table called Happy Place with the content values.

22
00:01:34,770 --> 00:01:39,320
Then we also need to add another value, which is our workflows.

23
00:01:39,320 --> 00:01:44,060
So we want to update it on a specific entry.

24
00:01:44,510 --> 00:01:45,230
So here.

25
00:01:46,770 --> 00:01:49,710
I'm going to say at the point where the kid.

26
00:01:51,640 --> 00:01:54,840
And here, key on the score, Edem.

27
00:01:56,290 --> 00:01:57,490
Is equal to.

28
00:02:00,090 --> 00:02:01,650
Our happy place.

29
00:02:03,580 --> 00:02:04,710
Thought I'd.

30
00:02:06,050 --> 00:02:11,680
And, of course, a plus missing, so I think it makes sense to put it in a new line here.

31
00:02:13,680 --> 00:02:15,120
So we have this update method.

32
00:02:15,970 --> 00:02:18,160
And there we pass in the.

33
00:02:19,080 --> 00:02:25,080
Table the content values, and then we say where we want to change that, and that will be changed,

34
00:02:25,080 --> 00:02:34,260
where the ID is, the happy place ID and we need to call the where arguments or person where arguments

35
00:02:34,260 --> 00:02:34,710
here as well.

36
00:02:34,710 --> 00:02:35,800
I'm going to pass and now.

37
00:02:36,360 --> 00:02:41,310
OK, so in this case we are updating something, but only at one point.

38
00:02:41,310 --> 00:02:48,210
And that is going to be where the ID is the same as the happy place ID that was passed when we call

39
00:02:48,220 --> 00:02:50,060
the update Happy Place.

40
00:02:50,310 --> 00:02:55,860
So we pass on an object of type happy place model, which contains, of course, all of the information

41
00:02:55,860 --> 00:02:58,650
such as the title, the image and so forth.

42
00:02:58,950 --> 00:03:02,820
And then we just go ahead and update all of that.

43
00:03:04,060 --> 00:03:07,550
And now I'm just going to return success.

44
00:03:07,930 --> 00:03:11,770
Now, the thing is, when updating, we're going to be update.

45
00:03:11,770 --> 00:03:13,510
You can see it returns an integer.

46
00:03:14,080 --> 00:03:19,230
But our update, happy place currently returns that long.

47
00:03:19,600 --> 00:03:26,260
So we need to change that because when adding something you can see here, when inserting insert returns

48
00:03:26,260 --> 00:03:33,790
a long and that's why it was totally fine to use a long here as the return type for our ad happy place

49
00:03:33,790 --> 00:03:34,140
method.

50
00:03:34,480 --> 00:03:39,670
But now when working with the update Happy Place Method, we're working with integers, so we need to

51
00:03:39,670 --> 00:03:47,050
return an integer because the success here, which is the result of DB update, is an integer.

52
00:03:48,730 --> 00:03:50,570
So when is that even relevant?

53
00:03:50,590 --> 00:03:53,110
So when do we call either of those methods?

54
00:03:53,530 --> 00:03:55,100
So either add or update.

55
00:03:55,690 --> 00:03:57,720
Well, it's this save button here.

56
00:03:57,730 --> 00:03:58,960
So once we.

57
00:04:00,070 --> 00:04:05,150
Press on this button here at the bottom, so it's inside of adding this happy place.

58
00:04:05,170 --> 00:04:09,190
So let's go to our happy place and we have this.

59
00:04:10,480 --> 00:04:16,029
Button function, so it's inside of our unclick, so here.

60
00:04:17,230 --> 00:04:25,300
When we pressed Button safe, we do all of this stuff and then we have a real happy place model, so

61
00:04:25,420 --> 00:04:28,370
we called Debbie Handler at Happy Place.

62
00:04:28,390 --> 00:04:34,840
So this is the spot where we should make changes, because now we don't only want to add happy places

63
00:04:34,840 --> 00:04:40,660
all the time, but we really just want to do that if we create a new entry.

64
00:04:40,660 --> 00:04:43,330
Otherwise we want to update a happy place.

65
00:04:43,870 --> 00:04:44,320
All right.

66
00:04:44,800 --> 00:04:54,910
So the changes start right here where the ID will either be zero or it will be the ID of happy place

67
00:04:55,150 --> 00:04:55,750
details.

68
00:04:56,260 --> 00:05:00,700
So here it's going to be if I'm happy.

69
00:05:02,920 --> 00:05:04,960
Plus, details is now.

70
00:05:07,560 --> 00:05:13,620
Then you zero else use em, happy place details, I'd.

71
00:05:15,700 --> 00:05:17,980
OK, so what is this happy place these days?

72
00:05:18,010 --> 00:05:25,990
Well, it's a happy place model object that we created here at the highest level and then we set that

73
00:05:25,990 --> 00:05:26,740
one at one point.

74
00:05:26,760 --> 00:05:33,610
So here, if we the intent has extra, that's where we get information about the happy place model that

75
00:05:33,610 --> 00:05:34,240
we need to change.

76
00:05:34,270 --> 00:05:39,550
So if that exists, then we want to update if it doesn't exist and we want to add a new entry.

77
00:05:39,940 --> 00:05:42,190
OK, so we need to go back to.

78
00:05:43,350 --> 00:05:44,580
That part here.

79
00:05:44,730 --> 00:05:46,650
All right, so this is the if statement.

80
00:05:47,760 --> 00:05:55,260
And now, finally, we need to check when calling dysfunction, so here we have the DB handler and now

81
00:05:55,530 --> 00:06:00,400
either we call ad happy place or update happy place.

82
00:06:01,230 --> 00:06:01,710
All right.

83
00:06:02,490 --> 00:06:09,150
So here, let's create another if statement if I'm happy.

84
00:06:09,150 --> 00:06:11,280
Place details is now.

85
00:06:12,290 --> 00:06:13,430
Then just go ahead.

86
00:06:14,340 --> 00:06:22,500
And to this quote here, so Rhonda at Happy Place and also check this one year.

87
00:06:23,580 --> 00:06:29,640
So if statement to as you did before, but otherwise if it's not now.

88
00:06:30,640 --> 00:06:37,330
Then go ahead and do the update, have your place so it's pretty much the same thing, only with difference

89
00:06:37,330 --> 00:06:41,080
that it's now called Update Happy Place.

90
00:06:41,740 --> 00:06:45,660
And of course, the function is also called update happy place.

91
00:06:46,480 --> 00:06:49,060
And now we just need to pass in the model.

92
00:06:49,870 --> 00:06:54,520
And of course, here, check if the result code.

93
00:06:55,760 --> 00:06:58,550
Is great, greater zero, which means there is no error.

94
00:06:59,030 --> 00:07:02,960
All right, so going back to our update, happy place.

95
00:07:02,960 --> 00:07:04,440
You can see it returns an integer.

96
00:07:04,820 --> 00:07:12,800
So if that integer that comes from the success or so from the attempts to update something, if that

97
00:07:12,800 --> 00:07:16,970
is greater than zero, it means that things worked out.

98
00:07:18,340 --> 00:07:20,800
And then we can go ahead and use it.

99
00:07:23,330 --> 00:07:25,100
And the rest can stay the same.

100
00:07:25,610 --> 00:07:29,220
OK, so this is pretty much it, what we need to check here.

101
00:07:29,750 --> 00:07:34,670
So let's now test it again and see if the bug is fixed.

102
00:07:36,460 --> 00:07:37,620
All right, so there we are.

103
00:07:37,760 --> 00:07:44,050
Let's change test without anything, let's call this one test number one.

104
00:07:46,170 --> 00:07:53,580
And press update, you could see now the first entry's test number one, and if I scroll, you see no

105
00:07:53,910 --> 00:07:58,710
changes were made or no additions were made, no new entry was created.

106
00:07:58,770 --> 00:08:01,370
Now, let's see if we create a new entry.

107
00:08:01,680 --> 00:08:09,810
So test new entry test, new entry description.

108
00:08:11,000 --> 00:08:12,390
Now, the location.

109
00:08:14,400 --> 00:08:15,270
Somewhere.

110
00:08:16,330 --> 00:08:17,440
Far away.

111
00:08:20,220 --> 00:08:20,940
An image here.

112
00:08:30,210 --> 00:08:38,610
And now we're safe and we can see this new entry, this new entry desk, so that worked perfectly.

113
00:08:39,950 --> 00:08:46,580
All right, so that's already a pretty good step, you could see you could go ahead and create a to

114
00:08:46,580 --> 00:08:48,980
do list now with all the knowledge that you have.

115
00:08:48,980 --> 00:08:54,080
So you could use pretty much everything that you've learned so far and create a beautiful to do list

116
00:08:54,080 --> 00:08:57,940
app, which would really do well, I think.

117
00:08:58,280 --> 00:09:04,970
But then, of course, we want to add a bunch of new features which include the location so we will

118
00:09:04,970 --> 00:09:08,660
see how to use Google Maps and everything else and the next few videos.

119
00:09:08,670 --> 00:09:09,860
So see you in the next one.

