Reputation: 32
Ok so I have no idea what the problem is. I get an error saying that the sender_id column does not exist. I have two tables, the user table is created just fine and all the column names are constants.
public String CREATE_USER_TABLE = "CREATE TABLE " + TableData.TableInfo.USER_TABLE +
" ( "+ TableData.TableInfo.USER_NAME +" TEXT PRIMARY KEY, "
+ TableData.TableInfo.USER_PASS +" TEXT, "
+ TableData.TableInfo.USER_FNAME + " TEXT, "
+ TableData.TableInfo.USER_LNAME + " TEXT);";
//Create Message table
public String CREATE_MSG_TABLE = "CREATE TABLE " + TableData.TableInfo.MSG_TABLE +
" ( " + TableData.TableInfo.MESSAGE_ID + " INTEGER PRIMARY KEY, "
+ TableData.TableInfo.RECEIVER_ID + " TEXT, "
+ TableData.TableInfo.SENDER_ID + " TEXT, "
+ TableData.TableInfo.MESSAGE + " TEXT, "
+ TableData.TableInfo.STATUS + " INTEGER);";
The User table is created just fine and I have no issues accessing information. But I get errors trying to access the message table.
public void onCreate(SQLiteDatabase sdb){
sdb.execSQL(CREATE_USER_TABLE);
Log.d("Database operations", "Table1 created");
sdb.execSQL(CREATE_MSG_TABLE);
Log.d("Database operations", "Table2 created");
}
And this is where I query the table to add a row.
public void putInformationMsgTable(DatabaseOperations dop,String senderID,String receiverID, String text, int status)
{
SQLiteDatabase SQ = dop.getWritableDatabase();
SQ.execSQL("INSERT INTO " + TableData.TableInfo.MSG_TABLE +
" (" + TableData.TableInfo.MESSAGE_ID +
", " + TableData.TableInfo.RECEIVER_ID +
", " + TableData.TableInfo.SENDER_ID +
", " + TableData.TableInfo.MESSAGE +
", " + TableData.TableInfo.STATUS + ")" +
" VALUES (" + null + ", "
+ receiverID + ", "
+ senderID + ", "
+ text + ", "
+ status + ")");
Log.d("Database operations", "One row inserted into message table");
}
I know there are a lot of threads out there on this topic but both my professor and I are stumped. My syntax seems correct and there is no reason that this shouldn't work. Any thoughts?!
EDIT: These are the constants I am working with **I also changed the value of the constant MESSAGE_ID to msg_id and the error now says "table msg_info has no column named msg_id (code 1)"
//User Table
public static final String USER_NAME = "user_name";
public static final String USER_PASS = "user_pass";
public static final String USER_FNAME = "user_fname";
public static final String USER_LNAME = "user_lname";
public static final String DATABASE_NAME = "user_info";
public static final String USER_TABLE = "user_info";
//Message Table
public static final String MESSAGE_ID = "rowid";
public static final String RECEIVER_ID = "receiver_id";
public static final String SENDER_ID = "sender_id";
public static final String MESSAGE = "message";
public static final String STATUS = "status";
public static final String MSG_TABLE = "msg_info";
Upvotes: 0
Views: 93