public class DatabaseOperations extends SQLiteOpenHelper {
public static final int DATABASE_VERSION =1;
public String CREATE_QUERY = "CREATE TABLE "+ TableData.TableInfo.TABLE_NAME + " (" + TableData.TableInfo.FACT_+" TEXT,"+ TableData.TableInfo.RATING_VALUE+"INTEGER );";
public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DATABASE_NAME, null, DATABASE_VERSION);
Log.d("Database operations","Database created");
}
@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(CREATE_QUERY);
Log.d("Database operations","Table created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void putInformation(DatabaseOperations dop, String fact, int rating){
SQLiteDatabase SQ = dop.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.FACT_,fact);
cv.put(TableData.TableInfo.RATING_VALUE ,rating);
long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
Log.d("Database operations", "One row inserted");
}
public Cursor getInformation(DatabaseOperations dop){
Log.d("Database operations", "One row inserted");
SQLiteDatabase SQ = dop.getReadableDatabase();
Log.d("Database operations", "One row inserted");
String[] columns ={TableData.TableInfo.FACT_, TableData.TableInfo.RATING_VALUE};
Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME,columns,null,null,null,null,null);
return CR;
}
}
The Logcat error message that i keep getting is, but cant figure out what is wrong with the create query code, i have tried changing type from integer, numeric and real:
8305-8305/com.danial.funfacts E/SQLiteLog﹕ (1) table fact_info has no column named rating
android.database.sqlite.SQLiteException: table fact_info has no column named rating (code 1): , while compiling: INSERT INTO fact_info(rating,facts) VALUES (?,?)
Aucun commentaire:
Enregistrer un commentaire