1 00:00:00,000 --> 00:00:03,539 Hi there, and I'm glad to introduce you 2 00:00:03,540 --> 00:00:05,700 to this new section of the course. And 3 00:00:05,700 --> 00:00:07,380 in this section, you're going to learn 4 00:00:07,380 --> 00:00:10,440 how to interact with databases via 5 00:00:10,440 --> 00:00:13,590 Python. And what that means is that you 6 00:00:13,590 --> 00:00:16,260 will use specific Python libraries, and 7 00:00:16,260 --> 00:00:19,050 you're going to operate a database from 8 00:00:19,080 --> 00:00:22,950 Python, using Python. You're going to do 9 00:00:22,980 --> 00:00:25,440 operations such as inserting data into 10 00:00:25,440 --> 00:00:27,660 database tables, you would be able to 11 00:00:27,660 --> 00:00:31,080 update date, delete and query data all from 12 00:00:31,080 --> 00:00:33,330 the database. And then you are able to 13 00:00:33,330 --> 00:00:35,730 use those data in your Python program. 14 00:00:35,940 --> 00:00:38,640 Python is able to interact with many 15 00:00:38,640 --> 00:00:42,270 databases such as MySQL, PostgreSQL, 16 00:00:42,328 --> 00:00:46,828 Oracle, or SQLite, etc. In this 17 00:00:46,830 --> 00:00:48,270 section, you're going to learn how to 18 00:00:48,270 --> 00:00:51,570 interact with an SQLite database and 19 00:00:51,570 --> 00:00:55,918 the PostgreSQL database as well. SQLite and PostgreSQL 20 00:00:55,919 --> 00:01:00,300 are different in that, SQLite is not a client server 21 00:01:00,300 --> 00:01:03,390 database, instead, it is embedded into 22 00:01:03,390 --> 00:01:05,970 the end program. So what does that mean? 23 00:01:06,150 --> 00:01:07,807 Well, let's look at this program. 24 00:01:09,706 --> 00:01:11,400 If you followed the previous section, you know 25 00:01:11,400 --> 00:01:13,320 that we're going to build this program 26 00:01:13,320 --> 00:01:15,630 in the next section. When you click a 27 00:01:15,630 --> 00:01:17,670 button here, you see some data, and 28 00:01:17,670 --> 00:01:20,070 these data are stored in SQLite 29 00:01:20,100 --> 00:01:22,500 database. In contrast to other databases 30 00:01:22,500 --> 00:01:25,530 such as PostgreSQL, SQLite is based on 31 00:01:25,530 --> 00:01:28,440 file. So all these data here are stored 32 00:01:28,470 --> 00:01:31,740 in a .db file database file, so that 33 00:01:31,740 --> 00:01:33,510 means you can just give this 34 00:01:33,510 --> 00:01:35,850 program to someone else who don't have 35 00:01:35,880 --> 00:01:37,890 SQLite installed, and they can use 36 00:01:37,890 --> 00:01:40,200 this program. So they can add more data 37 00:01:40,200 --> 00:01:42,750 here, can update data, and delete them and 38 00:01:42,750 --> 00:01:45,330 so on. But if you have this program, you 39 00:01:45,330 --> 00:01:48,000 know, PostgreSQL database, the user, you 40 00:01:48,000 --> 00:01:49,620 give the program to they would need to 41 00:01:49,620 --> 00:01:51,540 have PostgreSQL installed in the 42 00:01:51,570 --> 00:01:54,510 computer to be able to operate the data. 43 00:01:54,720 --> 00:01:57,720 So consider SQLite a small database, 44 00:01:58,260 --> 00:02:00,240 and you can call it portable, but it's 45 00:02:00,240 --> 00:02:03,210 very popular, and PostgreSQL would be 46 00:02:03,240 --> 00:02:05,490 more appropriate to use in a web 47 00:02:05,490 --> 00:02:07,440 application. So let's say you have some 48 00:02:07,440 --> 00:02:09,780 forms, you're getting some data from, from 49 00:02:09,780 --> 00:02:12,150 the user on your website, and you store 50 00:02:12,150 --> 00:02:15,000 your data on a PostgreSQL database on 51 00:02:15,002 --> 00:02:17,402 your server. And Python is a program 52 00:02:17,490 --> 00:02:20,520 that gets these data from your forms on 53 00:02:20,520 --> 00:02:22,980 the client, on the browser and 54 00:02:23,010 --> 00:02:25,680 sends those data in your database. Now 55 00:02:25,710 --> 00:02:27,480 to be able to interact with this 56 00:02:27,510 --> 00:02:30,480 databases, you need to have two 57 00:02:30,480 --> 00:02:32,610 libraries. Now these libraries serve as 58 00:02:32,610 --> 00:02:36,000 interfaces to actually send SQL code to 59 00:02:36,000 --> 00:02:37,860 the database. And the library to 60 00:02:37,860 --> 00:02:41,520 interact with an SQLite database is 61 00:02:41,520 --> 00:02:44,760 called sqlite3, and the library 62 00:02:44,760 --> 00:02:47,460 to work with a PostgreSQL database is 63 00:02:47,692 --> 00:02:51,832 psycopg2. So in this section now, in 64 00:02:51,840 --> 00:02:53,730 the next lecture, I'll show how to work 65 00:02:53,730 --> 00:02:57,150 with sqlite3. Then we'll jump to 66 00:02:57,150 --> 00:03:00,267 psycopg2. So let's move on.