#100DaysOfCode in Python Transcripts
Chapter: Days 79-81: Basic Database Access with SQLite3
Lecture: Pulling data with SELECT
0:00 All right, now that we have our lovely table
0:02 with Mike, Bob, and myself in it,
0:04 and our very realistic addresses,
0:08 let's actually print some of that data out.
0:11 So we're going to do that within the Python shell.
0:13 Again, import sqlite3, getting tedious by now.
0:18 So, we will run our connection,
0:21 con equals sqlite3.connect.
0:31 'Kay, c = con.cursor to get our cursor.
0:37 Now to print the actual data within the database,
0:40 we need to put this into a for loop, okay?
0:44 Just bear with me, because we're going to
0:45 iterate over these three rows, okay?
0:50 So, the way we do that, is we go for row in c.execute.
0:57 We're going to select data.
1:00 Now what data were we going to select?
1:02 We're going to select everything from our details table,
1:07 all right, so for row in c.execute.
1:09 Select all from details.
1:12 What next?
1:14 Well, once it's got the row,
1:17 we want to print the row.
1:19 And that's it.
1:22 And there are our three lines.
1:24 You've got these, the formatting's a bit off,
1:26 it's actually taking that data,
1:30 or the literal, the tuple for that, for that row, you know?
1:33 So it doesn't look that great.
1:36 So to actually make that look a little bit better,
1:39 let's just bring that back up to save me some time.
1:42 We can actually choose which column to view,
1:46 so we can go print row...
1:54 Julian, Bob, Mike.
1:56 And once we have this sort of information,
1:59 you can start to pop a few strings together,
2:03 you know, start making sentences from these,
2:05 these sorts of database pulls.
2:08 So let's do one really quickly here.
2:13 And there we go.
2:14 So Julian lives at 123 Fake Street, blah blah blah,
2:16 and his phone number X, okay?
2:19 And that's the sort of manipulation we can do
2:21 by pulling the data out of the database.