Support Topics Documentation Slack YouTube Blog

Getting Data From Table


(Saad Zahoor) #1

I have 10 users and each user has its personal information
So In my UserInformation Table i have some properties

userName , userAge , userNationality , userPassportNumber , userGender , userDateOfBirth and so on

when a user register i get all the information and send the infomation to UserInformation Table and also have a relation with it (Users -> UserInformation)

Problem is when i am getting data from the server

I use the below code

        Backendless.Data.of( UserInformation.class).find(new AsyncCallback<List<UserInformation>>(){
            @Override
            public void handleResponse( List<UserInformation> foundUserInfo)
            {

                if (foundUserInfo.isEmpty()){

                    Toast.makeText(UserInfo.this, "No Information Is Found", Toast.LENGTH_SHORT).show(); 

                }else {


                    realFullName.setText(foundUserInfo.get(0).getName());
                    realNationality.setText(foundUserInfo.get(0).getNationality());
                    realBirthDate.setText(foundUserInfo.get(0).getDateOfBirth());
                }
            }
            @Override
            public void handleFault( BackendlessFault fault )
            {

               
            }
        });

i know

   foundUserInfo.get(0).getDateOfBirth()

this code will return the first object from the list
what i want is to get the information of the logged in user not randomly
Currently i am getting data randomly

Suppose if i login from user wildstone i get the data of unknownUser
i want to fetch the data from the table for the user who is log in
Thanks


(Mark Piller) #2

Do you need to get just the logged in user? Right now you get a collection of users from the database and use the first one.

Regards,
Mark


(Olha Danylova) #3

In addition to Mark’s answer - you can use this API to get currently logged in user: https://backendless.com/docs/android/users_get_current_user.html

Regards,
Olha


(Saad Zahoor) #4

Thank you for your time
My problem solved by using

String ownerId = backendlessUser.getProperty("ownerId").toString();
                String whereClause = "ownerId = '"+ownerId+"' ;
                DataQueryBuilder queryBuilder = DataQueryBuilder.create();
                queryBuilder.setPageSize( 20 ).setOffset( 0 );
                queryBuilder.setWhereClause( whereClause );
Backendless.Data.of( Database.class ).find(queryBuilder1,
                                                new AsyncCallback<List<Database>>()  ...