错误:table fact_info没有名为rating的列

时间:2015-07-14 03:28:34

标签: android sqlite debugging

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;
}

}

我一直得到的Logcat错误消息是,但是无法弄清楚创建查询代码有什么问题,我尝试从整数,数字和实数中更改类型:

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 (?,?)

1 个答案:

答案 0 :(得分:0)

您在列名称之后和类型之前缺少空格:

public String CREATE_QUERY = "CREATE TABLE " + TableData.TableInfo.TABLE_NAME + " (" 
    + TableData.TableInfo.FACT_ + " TEXT,"
    + TableData.TableInfo.RATING_VALUE + " INTEGER);";
                                          ^

您当前的代码会生成一个名为" ratinginteger"的列。没有类型亲和力。