Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMalcolm Mutambanengwe
4,205 PointsSQLite tables
Harry James your name is synonymous with being a database fundi. What am I doing wrong?
ContentValues values = new ContentValues();
values.put("name", "Rover");
values.put("type", "cat");
values.put("breed", "grumpy");
String clause = String.format("%s=%s", "name", "Rover");
database.update("PETS_TABLE", values , "where _id = 1", null);
4 Answers
Harry James
14,780 PointsThanks Malcolm and sorry for getting back to you a bit late!
In Android, the third argument of database.update() is the whereClause. You've already got this clause, so change the third argument to clause (The variable).
You don't need to specify the "where" as this is filled in automatically by Android. To the database, this will look like UPDATE WHERE name=rover (%s=%s) with values.
I think this will make it pass but let me know if not :)
Malcolm Mutambanengwe
4,205 PointsHi Harry
Challenge Task 2 of 2
Once again, assume you have a variable named 'database'. Update the database using the 'values' and 'clause' variables and "PETS_TABLE" as the table name. Use the documentation for help on how to call the appropriate method to update this data.
ContentValues values = new ContentValues(); values.put("name", "Rover"); values.put("type", "cat"); values.put("breed", "grumpy");
String clause = String.format("%s=%s", "name", "Rover");
/* Add your code here!
- Assume you already have a variable named 'database'. */
Malcolm Mutambanengwe
4,205 Pointsthis is what I typed
database.update("PETS_TABLE", values , "where _id = 1", null);
Malcolm Mutambanengwe
4,205 PointsHi Harry.
LIke so
database.update("PETS_TABLE", values , clause, null);
Got it. Thank you thank you.
That does the clause even mean?
Harry James
14,780 PointsYep that's it!
The clause is really just the command you're telling the database.
To explain this better, when we do database.update(), it will run the command in the database "UPDATE WHERE <your clause goes here>". So the clause is the condition that must be true for the values to be updated.
Hope that helps but if you don't quite get it, let me know and I'll try to rephrase it :)
Malcolm Mutambanengwe
4,205 PointsAh nice. Thanks man. May the force be with you ;)
Harry James
14,780 PointsNo problemo - any time :)
Harry James
14,780 PointsHarry James
14,780 PointsHey Malcolm - Do you mind letting me know what the challenge task you're on is (I have my subscription paused right now so can't check the challenge myself!) by pasting the question here and I'll take a look :)