javaandroiddatabaseormsugarorm

check whether data available in orm database


Is it possible to add the data in to the sugarorm db by this method? I want to validate if the user is already in db, if yes then display "user available" else I want to insert the value in the database.Can some one help me with this validation?

private void postDataToSQLite() {

        User.find(User.class, "email = ? and password = ?", email, password);

Solution

  • You Need to change the if condition. You are currently checking the user already exits or not. But issue is you trying compare two string using "==" this. But if you need to compare two string you have to use "equals"

    Current Code

       if (user.getEmail() != textInputEditTextEmail.getText().toString().trim() || user.getPassword() != textInputEditTextPassword.getText().toString().trim()) {
    

    New Code

    if (!user.getEmail().equals(textInputEditTextEmail.getText().toString().trim()) || !user.getPassword().equals(textInputEditTextPassword.getText().toString().trim()) ) {