YouTube

Got a YouTube account?

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

English subtitles

← Talking about our JOIN

Get Embed Code
5 Languages

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

  1. When we first defined our tables,
  2. we defined the relationship between
    them in terms of constraints.
  3. I'm going to show how we implemented
    that relationship into our
  4. query using a JOIN.
  5. This JOIN allows us to
    query the Weather table for
  6. values from a specific location setting.
  7. In Sunshine's case,
    the user sets this in Preferences.
  8. You'll notice that there's
    an SQLiteQueryBuilder class variable at
  9. the top of WeatherProvider.
  10. As you might guess,
    this class helps construct queries and
  11. is actually used as the basis for
  12. the query functions you've already
    used in the SQLite database class.
  13. We initialize the SQLiteQueryBuilder
    in the static constructor of the class,
  14. describing the join between both tables.
  15. SetTables fills out the content in
    the from part of the SQL query.
  16. Note, since both tables have
    a field with an underscore ID,
  17. we must explicitly use the table
    name in order to disambiguate
  18. which ID we are talking
    about in the join.
  19. Then we define the selection.
  20. The selection is defined using
    the question mark replacement syntax.
  21. The selection parameters
    will replace these values.
  22. As you can see,
    our selection has two parameters,
  23. a location setting and a date.
  24. Then we have a function to get
    the weather by location setting using
  25. the same query builder.
  26. Note that we fetch the parameters from
    the URI and built a string array so
  27. that they can be
    substituted into our query.
  28. We do that for both of the queries
    that we're creating this way.
  29. Finally, we added the functions into the
    query routine of the content provider,
  30. for both WEATHER_WITH_LOCATION_AND_DATE
    and WEATHER_WITH_LOCATION