jeudi 8 octobre 2015

SQLite Select statement when have multiples rows

I want select * from a table comparing 3 rows and the select return an id, i create this method:

//UserDAO class

private SQLiteDatabase mDatabase;
private DatabaseHelper mDbHelper;

// irelative code

public Long selectUserLogin(String nickname, String chapter, String password) {
    long id;
    String selectQuery = "SELECT  * FROM " +
            DatabaseHelper.TABLE_USERS + " WHERE " +
            DatabaseHelper.COLUMN_USERS_NICKNAME + " = " + nickname + " AND " +
            DatabaseHelper.COLUMN_USERS_CHAPTER + " = " + chapter + " AND " +
            DatabaseHelper.COLUMN_USERS_PASSWORD + " = " + password;

    Log.e(TAG, selectQuery);
    try {
        Cursor cursor = mDatabase.rawQuery(selectQuery, null);
        if (cursor != null)
            cursor.moveToFirst();

        id = cursor.getLong(cursor.getColumnIndex(DatabaseHelper.COLUMN_USERS_ID));

        return id;
    } catch (Exception e){
        e.printStackTrace();
    }
    return null;
}

Already created on my database nickname = q, chapter = Q and password = qqqqqq

These is where i called the method to test his functionality

userDAO.selectUserLogin("q", "Q", "qqqqqq");

I checked with another method that list all my users and i get all the users I've one time created.

Here is the results:

10-09 01:00:18.298 10978-10978/com.org.feedme.cisvmeeting.activities     D/LeaderFragment: User: [
D/LeaderFragment: [1] 1, h, h, G 
D/LeaderFragment: [2] 2, fkfkdk, fjfkdk, SAO 
D/LeaderFragment: [3] 3, Filipe fila, Fil36
D/LeaderFragment: [4] 4, q, Q, qqqqqq
D/LeaderFragment: [5] 5, glgl, vmlc, GOLGO]

When i tried to see my data folder on Android Device Monitor the folder was empty, so i'm little bit confused if i could not access the database or if i'm not inserting correctly.

Part of my logcat when i tried call the method selectUserLogin:

10-09 00:46:01.198 7745-7745/com.org.feedme.cisvmeeting.activities E/UserDAO: SELECT * FROM users WHERE nickname = q AND chapter = Q AND password = qqqqqq

10-09 00:46:01.208 7745-7745/com.org.feedme.cisvmeeting.activities E/SQLiteLog: (1) no such column: q

10-09 00:46:01.208 7745-7745/com.org.feedme.cisvmeeting.activities W/System.err: android.database.sqlite.SQLiteException: no such column: q (code 1): , while compiling: SELECT * FROM users WHERE nickname = q AND chapter = Q AND password = qqqqqq

Aucun commentaire:

Enregistrer un commentaire