mercredi 3 février 2016

Android SQL join two tables gives error "no such table: "

I am joining two tables in a Android Database adapter class. I have two tables: Conversations and UserConversations.

In my class ConversationsDatabaseUtil class I am creating a cursor to get Conversations that have matching rows in UserConversations:

public class ConversationsDatabaseUtil extends SQLiteOpenHelper {

public Cursor getCursor(long userId) {
        SQLiteDatabase db = this.getWritableDatabase();
        String query = "select c from "+TABLE_NAME + " c, UserConversation uc where " +
                " uc."+UserConversationsDatabaseUtil.columns.userId.name() + "=" + userId +
                " and uc."+UserConversationsDatabaseUtil.columns.conversationId.name() + "=c."+ columns.conversationId.name();
        Log.i(getClass().toString(), "query: " + query);
        Cursor cursor = db.rawQuery(query, null);

..

On execution of the rawQuery method I keep getting the following error:

I keep getting the following error:

Error Code : 1 (SQLITE_ERROR)
02-03 08:27:29.461 1385-1385/kecha.sonam.com.kechasonam E/AndroidRuntime: Caused By : SQL(query) error or missing database.
02-03 08:27:29.461 1385-1385/kecha.sonam.com.kechasonam E/AndroidRuntime:   (no such table: UserConversations (code 1): , while compiling: select c from Conversations c, UserConversations uc where  uc.userId=14 and uc.conversationId=c.conversationId)
02-03 08:27:29.461 1385-1385/kecha.sonam.com.kechasonam E/AndroidRuntime: #################################################################
02-03 08:27:29.461 1385-1385/kecha.sonam.com.kechasonam E/AndroidRuntime:  

Any insight appreciated.

thanks

Aucun commentaire:

Enregistrer un commentaire