How to update in parse database custom table using android - android

I know about how to insert in custom table in parse.com database but i don't know about it how to update. i confuse in the how to get all object value from the table. so you have any idea about it.
Thanks in Advances.

You could try to retrieve the object you want to update and then save it edited like this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.whereEqualTo("firstName", "Dan");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
ParseObject person = list.get(0);
person.put("firstName", "Johan");
person.saveInBackground();
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
For more examples you could read the chapter for updating objects in Parse.com documentation here https://www.parse.com/docs/android/guide#objects-updating-objects

Related

Add data to parse table doesnt work (android)

Hi im trying to add data to specific object in some table in parse.com this is the code :
ParseQuery<ParseObject> query = ParseQuery.getQuery("Buildings");
query.whereEqualTo("objectId", building);
query.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if(object == null) {
Log.e("object","not found");
}
else {
Log.e("object","found "+ object.getObjectId().toString());
object.put("test", "test");
object.saveInBackground();
}
}
});
i debug the code and it was fine and he really find the object and it really add a column to the table with the name test but i dont see any value inside i just see all the time (undefined)

Retrieve ParseUsers list in Java (Android)

I have a table (ParseObject) called "Friends" with a "to" and "from" column which use pointers to objectId's of User's. This table tracks who's friends with who, how do I create a query that will return all my friends as user objects - not just the ID stored in that table?
Thanks!
The ParseUser class often confuses me as it is clearly different from a ParseObject and can't be used with the same methods (like ParseQuery.or)
Currently, I'm trying:
ParseQuery<ParseObject> friendsFrom = ParseQuery.getQuery("Friends");
friendsFrom.whereEqualTo("from", ParseUser.getCurrentUser());
ParseQuery<ParseObject> friendsTo = ParseQuery.getQuery("Friends");
friendsTo.whereEqualTo("to", ParseUser.getCurrentUser());
// where they've been accepted
friendsFrom.whereEqualTo("accepted", true);
friendsTo.whereEqualTo("accepted", true);
// combine the queries - parse does this a 'special' way
List<ParseQuery<ParseObject>> friends = new ArrayList<ParseQuery<ParseObject>>();
friends.add(friendsFrom);
friends.add(friendsTo);
ParseQuery<ParseObject> combinedQuery = ParseQuery.or(friends);
combinedQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> friends, ParseException e) {
if (friends != null) {
Log.d(getClass().getSimpleName(), "Found " + friends.size() + " friends");
contacts.clear();
for (ParseObject friend : friends) {
//show user, or whatever you'd like to do..
}
}
});
But a ParseObject cannot be cast to a ParseUser so I can't do anything here..
Update
According to Robert's advice I've tried the following, but it's still not providing me with the UserObjects I need - and for some reason, my Log aren't being written during these "findInBackground" callbacks by Parse..
ParseQuery < ParseObject > friendshipAndUserQuery = ParseQuery.getQuery("friends");
friendshipAndUserQuery.whereEqualTo("from", ParseUser.getCurrentUser().getObjectId());
friendshipAndUserQuery.include("to");
friendshipAndUserQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
for (ParseObject friendship : objects) {
UserObject friend = (UserObject) friendship.getParseObject("to");
contacts.add(friend);
}
}
});

A different way to retrieve an Object in Parse with Android Studios

Currently I am making an Android application with Android Studios and I am using Parse to handle the data. I want to be able send (put) data such as town names and info about that town (town_names would be a column and info would be another, there for each town_names would have its own info). I can do that with ease and it uploads to the Parse database. However, the part I can not seem to figure out is how to retrieve the data points I desire. I have code to retrieve data based off of an objectId shown below however that is not exactly what I want.
ParseQuery<ParseObject> query = ParseQuery.getQuery("userMessage");
query.getInBackground("KgsLojXPcq", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
retrievedText = object.getString("info");
} else {
retrievedText = "No information.";
}
}
});
"userMessage" is the ParseObject I have created and "info" is the column I want to get text from. Instead of searching for an objectId ("KgsLojXPcq") is there a way to search for town_names? So then I could for example search the database for "New York" and "retrievedText" would be set to the info for New York.
ParseQuery
.getQuery("userMessage")
.whereEqualTo("town_names", "New York")
.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
retrievedText = object.getString("info");
} else {
retrievedText = "No information.";
}
}
});

Fetch ParseObject data based on relations query

I've question about way in which I should create query to get expected data.
I've MyObject (ParseObject) which has pointer to ParseUser (column named createdByPtr). In ParseUser I have custom column userGroupPtr.
Now I want to get all MyObject rows which are created by all users (createdByPtr) belongs to user group (userGroupPtr) to which belongs current logged user (ParseUser.CurrentUser()).
At this moment I have some kind of draft like this:
ParseQuery<MyObject> query = ParseQuery.getQuery(MyObject.class);
query.include("createdByPtr");
query.whereEqualTo("createdByPtr.userGroupPtr", ParseUser.getCurrentUser().get("userGroupPtr"));
query.orderByDescending("updatedAt");
query.findInBackground(new FindCallback<MyObject>() {
#Override
public void done(List<MyObject> results, ParseException e) {
....
}
});
I don't have idea how should I transform line:
query.whereEqualTo("createdByPtr.userGroupPtr", ParseUser.getCurrentUser().get("userGroupPtr"));
in to working constrain.
Any suggestions?
Try like this. I have tested and it works perfectly. see Relational Queries
ParseQuery<ParseUser> innerQuery = ParseUser.getQuery();
innerQuery.whereEqualTo("userGroupPtr","userGroupPtr"); //value of userGroupPtr
ParseQuery<ParseObject> query = ParseQuery.getQuery(MyObject.class);
query.whereMatchesQuery("createdByPtr", innerQuery);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objectList, ParseException e) {
if(e == null){
}else{
Log.e("Object", e.getMessage());
}
}
});

how to get all column values of a single row in android parse.com

I want to get all the data(i.e. column values) of the first row, which includes the 'objectId', 'ClientName','Session','myDate','createdAT', 'updatedAt' and 'ACL'.
How can I achieve this, thanks for the help.
You just query the table for the first object:
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.whereEqualTo("playerEmail", "dstemkoski#example.com");
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("score", "The getFirst request failed.");
} else {
Log.d("score", "Retrieved the object.");
}
}
});
After this query, object will be the first object in the table, and you can access its values with the parse getter methods. I suggest you read the parse docs: https://parse.com/docs/android_guide#queries

Categories

Resources