Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Give that App a Backend - Intro to Relational Databases

Get Embed Code
4 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. So, here's one approach to fixing up
    this code that you might have taken.
  2. This code here actually has a bad
    bug that we'll be looking into next.
  3. So, please don't go copying this
    into all your production apps.
  4. So, whenever we want to read or write
    to database, we first connect to it.
  5. Then establish a cursor.
  6. Then we do an execute.
  7. In the case of GetAllPosts,
    we execute a SELECT statement.
  8. And then we fetch all the results and
  9. reformat them into the dictionary
    that our code expects.
  10. And of course, we close
    the connection and return the posts.
  11. In the case of AddPost, we still
    connect to the database just the same.
  12. We execute an INSERT query,
  13. substituting in the post
    content into the query string.
  14. Commit the change and close.
  15. Now, this seems to work, but
    I did just say this has a bad bug, and
  16. we're going to see that right up ahead.