WEBVTT

00:00:00.350 --> 00:00:01.331
Welcome back!

00:00:01.511 --> 00:00:02.685
Here's what we'll learn.

00:00:02.865 --> 00:00:05.382
Insert an invoice row, change it, and delete it.

00:00:05.562 --> 00:00:09.061
Then use commit and rollback to decide which
changes remain.

00:00:09.241 --> 00:00:13.614
We use the same database in memory, with no
custom Python triggers yet.

00:00:15.017 --> 00:00:17.065
Let's add two teas and commit the row.

00:00:17.245 --> 00:00:21.362
We supply the stored total ourselves: two times
three fifty is seven.

00:00:21.542 --> 00:00:24.806
Insert adds the row; commit closes this
transaction.

00:00:24.986 --> 00:00:29.999
Because SQLite is in memory, commit keeps data
only while this connection exists.

00:00:30.179 --> 00:00:32.227
It does not create a database file.

00:00:33.617 --> 00:00:35.430
Let's change the quantity to three.

00:00:35.610 --> 00:00:40.154
Read the physical fields, copy the record and
update quantity and total together.

00:00:40.334 --> 00:00:44.238
Table update does not read or merge previous
values for us.

00:00:44.418 --> 00:00:48.877
Passing old record makes those previous values
available to the write cycle.

00:00:49.057 --> 00:00:50.827
We leave this change uncommitted.

00:00:52.217 --> 00:00:54.371
Let's update the selection to four teas.

00:00:54.551 --> 00:01:00.013
Query update reads the selected records, merges
our changes, and calls table update with

00:01:00.013 --> 00:01:01.378
their previous values.

00:01:01.558 --> 00:01:03.329
We pass only the changed fields.

00:01:03.509 --> 00:01:06.367
Its result is a list of updated primary keys.

00:01:06.547 --> 00:01:09.129
Our filter selects just row nine hundred and
one.

00:01:10.517 --> 00:01:13.205
Let's delete the row, then undo our pending
work.

00:01:13.385 --> 00:01:15.966
Query delete returns the removed records.

00:01:16.146 --> 00:01:18.386
The empty fetch confirms the row is gone.

00:01:18.566 --> 00:01:23.046
Rollback restores its last committed state:
quantity two and total seven.

00:01:23.226 --> 00:01:27.685
It undoes both updates and the deletion
together, not just the last statement.

00:01:29.017 --> 00:01:31.065
Let's clean up and commit the deletion.

00:01:31.245 --> 00:01:32.887
This time we commit the delete.

00:01:33.067 --> 00:01:35.201
The original thirty-six rows remain.

00:01:35.381 --> 00:01:40.437
The final commit closes the count query's read
transaction, ready for the next lesson.

00:01:41.817 --> 00:01:43.310
Thanks for following along!

00:01:43.490 --> 00:01:49.250
We inserted, updated and deleted a row, and
separated committed changes from pending work.

00:01:49.430 --> 00:01:51.798
We supplied every stored total ourselves.

00:01:51.978 --> 00:01:56.757
In the next lesson, Python triggers will
calculate and validate those totals for us.
