- [Instructor] Now so far we've been looking
just at selecting existing data from a database,
next up we're going to look at
inserting new data into a database,
and to do that we're going to be
working with from the sqlite3 module,
a cursor object, and that's the class
that we will use to interact with the database
to insert new data, update existing data
and delete data from the database as well.
So the first thing that we need to do
in order to obtain the cursor object
is get it from our connection object,
so we'll first obtain the cursor,
and then the cursor object has an execute method
to which you can pass structured query language statements
that insert data into the database,
update data in the database
or remove data from the database as well.
So as you can see here, we're in this case,
going to insert into the authors table
a new first name and last name,
and the values we're going to use for that
are Sue and Red respectively.
Notice we're not saying anything about
the ID number because that is going to be
an auto incremented value,
so up to this point we have five authors
in the database but now if we go and select
the ID, first and last name for every author
from the authors table we can see
that we now have six IDs and that
our new author Sue Red was auto incremented to number six
because up until this point we've only
dealt with five authors so far.
Now by the way, if we were to delete
a record from this table that does not
modify any of the existing author IDs
and the next insert will still be the ID seven
no matter what at that point.
Now one quick note about strings
that contain single quotes,
so as you've seen up above SQL delimits
strings with single quotes,
so if you have a name like O'Malley
with a quote in it, you have to use two quotes
in that position to act as an escape sequence
in the context of a SQL query of any kind.