lundi 9 mai 2016

IN clause in objective c

Hi i am using "IN" clause in objective c but this is not able to get data.

SELECT * FROM database WHERE colum1!=0 AND colum2!=0 AND colum3 IN ('Allah','is');

for this query code is i am using

NSArray* serch = [NSArray arrayWithObjects:@"Allah",@"is",nil];
    str1=[NSString stringWithFormat:@"SELECT * FROM database WHERE colum1!=0 AND colum2!=0 AND colum3 IN ('%@')",[serch componentsJoinedByString:@"','"]]

FMResultSet return nil;

Update sqlite not working on android

I have a login and reset password activity. When I enter the new updated password and try to login again, I cannot do so with the new password. Logging in with the old password works fine. Basically, the password field is not getting updated/overwritten.

There is no error in the logcat. Just that the password is not updated.

Please help as I am new to android development.

Code for update( DataRegister is the class with GET AND SET functions):

public int updatePassword(DataRegister dataregister) {

db = dbHelper.getWritableDatabase();
ContentValues updated = new ContentValues();
updated.put("PASSWORD", dataregister.getPASSWORD());

return db.update(DataRegister.TABLE, updated, "EMAIL=?" , new String[]   {dataregister.getEMAIL()});

}

Code for retrieval:

public String getPass(DataRegister dataRegister) {

db = dbHelper.getWritableDatabase();

Cursor cursor = db.query(DataRegister.TABLE, null, "EMAIL=?",
        new String[]{dataRegister.getEMAIL()}, null, null, null, null);
if (cursor != null && cursor.moveToFirst())

{
    pass = cursor.getString(cursor.getColumnIndex("PASSWORD"));
    cursor.close();
}
return pass;


// return contact


}

Code for Login:

  String email = editTextUserName.getText().toString();
        dataRegister.setEMAIL(email);

        String password = editTextPassword.getText().toString();
        dataRegister.setPASSWORD(password);

        String storedPassword = loginDataBaseAdapter.getSinlgeEntry(dataRegister);

        Toast.makeText(Login.this, storedPassword,Toast.LENGTH_LONG).show();
        Boolean a=loginDataBaseAdapter.isExist(dataRegister.getEMAIL());
       validation = getSharedPreferences("myShaPreferences", Context.MODE_PRIVATE);

        if (password.equals(storedPassword)) {

            Toast.makeText(Login.this,
                    "Congrats: Login Successful", Toast.LENGTH_LONG)
                    .show();
        }

        else {

                Toast.makeText(Login.this,
                        "User Name or Password does not match",
                        Toast.LENGTH_LONG).show();


            }



    }
});

Code for reset password:

public class ResetPassword extends AppCompatActivity {


 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_reset_password);

 email = (EditText) findViewById(R.id.em2);
 dataRegister=new DataRegister();

loginDataBaseAdapter = new DatabaseAdapter(this);
loginDataBaseAdapter = loginDataBaseAdapter.open();



pass = (EditText) findViewById(R.id.text12);
conpass = (EditText) findViewById(R.id.text13);

email1 = email.getText().toString();
dataRegister.setEMAIL(email1);
pass1 = pass.getText().toString();

conpass1 = conpass.getText().toString();
dataRegister.setPASSWORD(conpass1);

Button btnReset = (Button) findViewById(R.id.btnReset);
btnReset.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {


        if (pass1.equals(conpass1)) {

         loginDataBaseAdapter.updatePassword(email1,pass1);
            String newpass =loginDataBaseAdapter.getPass(dataRegister);

Table with many columns or many small tables?

I created a table where it has 30 columns.

CREATE TABLE "SETTINGS" (
  "column1" INTEGER PRIMARY KEY,
  ...
  ...
  "column30"
)

However, I can group them and create different table where they can have foreign keys to the primary table. Which is the best way to follow? Or the number of the columns is small so it's the same which way I will follow?

android sqlight how to search string in like if string contains ' symbol

following is my query that I am trying to search name contain special character e.g. ' symbol

 SELECT * from  distributor where name like'%jeni's%'

when I tried to add backslash if work in MySQL but wont work in sq light database I also tried following query

SELECT * from distributor where name like'%jeni\'s%' can someone help me to how can i search if string contains ' symbol

what is the use of onUpgrade() in sqlite?

Anybody please help me regarding the correct use of onUpgrade() in sqliteopenhelper class.Thanks in advance.

How to copy displyed text of recent page and share in android?

I created database which is displayed on sliding page one by one like e1 slide e2. Now i want to copy e1 and share it with friends.How to perform this task in android?

green dao update column on play store update has taken place

this is my Generator class

public class Generator {
    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(1, "app.abc.db.dao");
        createAbcDB(schema);

    }
    private static void createAbcDB(Schema schema) throws IOException, Exception {
        Entity abc = schema.addEntity("Abc");
        abc.addIdProperty();
        abc.addShortProperty("name");
    }
}

This is the code where i get abc dao from dao session. This works fine.

DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(SurveyActivity.this, "abc.db", null);
        SQLiteDatabase db = devOpenHelper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        DaoSession daoSession = daoMaster.newSession(IdentityScopeType.None);
        abcDao = daoSession.getAbcDao();

I added one more column

abc.addShortProperty("email");

to createAbcDB in generator to new version of app. Once users get updated they are getting sql exception saying no column found. Because i am calling on new login

dropAllTables(db, true);
onCreate(db); 

But problem is i have given one time login that user will always come to landing screen on upgrade from play store. So i don't know whether the user is upgraded app or not in order to drop and create all tables.

So my question is how to know my table has altered?