I am working on android app. I am using sqlite and saving data in it. So i have table, "main_table" and columns are "_id", "question" and "answer".
I am searching for question in database by this function.
private Cursor getQuestionFromDB(String question){
        String whereClause = "question = ?";
        String[] whereArgs = new String[]{question.toLowerCase()};
        return dbRead.query("main_table",
                new String[]{"question", "answer"},
                whereClause,  whereArgs,  null,  null,  null, null);
    }
so I have one question/answer saved in database.
--------------------------------------------------
| _id |         question                | answer |
--------------------------------------------------
|  1  | Should I eat my dinner on time? |  Yes   |
--------------------------------------------------
so when I search with for this question using input I get answer "yes". I have function that will also save question in database if it doesn't exist in it and for answer it will randomly select yes or no.
So if the question exist in database it will return the answer from db else it will save new question/answer in db and return that random answer. So when I search for question "Should I eat my dinner on time to avoid health issues?" it gives me back answer "yes" and I checked by showing question in toast and so it returns this and the question I am seeing in toast is from the function. So instead of adding in database, it is matching old question with new question as the old question is totally included in new question. Can anyone tell me how can I separate both with whole sentence?
All I want in db is
--------------------------------------------------
| _id |         question                | answer |
--------------------------------------------------
|  1  | Should I eat my dinner on time? |  Yes   |
--------------------------------------------------
|  2  | Should I eat my dinner on time  | random | 
|     | to avoid health issues?         | yes/no |
--------------------------------------------------
Aucun commentaire:
Enregistrer un commentaire