我已经尽可能多地搜索,但找不到任何帮助。我要创建一个明显超过 2 列的数据库。有没有人可以指出我的来源来帮助我。我还应该使用不同的数据库来提高性能。
我得到的错误信息是:
CursorWindow 对字段槽 0,2 的错误请求。numRows = 3。numColumns = 2
@Override
public void onCreate(SQLiteDatabase db) {
String sql = String
.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY, %s INTEGER NOT NULL, %s TEXT NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s REAL NOT NULL, %s REAL NOT NULL, %s REAL NOT NULL, %s REAL NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL);",
EXERCISES_TABLE, COL_ID, EXERCISE_ID, NAME,
TYPE_OF_TRAINING, WEIGHT_BEST, SETS_BEST, REPS_BEST,
SETS, REPS, WEIGHT_GOAL, SETS_GOAL, REPS_GOAL,
DISTANCE, TIME, BEST_TIME, BEST_DISTANCE, BEST_DATE,
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
SATURDAY);
db.execSQL(sql);
}
还有我试图检索数据的方式:
public List<Exercise> getExerciseList() {
List<Exercise> retEx = new ArrayList<Exercise>();
SQLiteDatabase db = getReadableDatabase();
String sql = String.format("SELECT %s, %s FROM %s ORDER BY %s",
EXERCISE_ID, SATURDAY, EXERCISES_TABLE, COL_ID);
Cursor cursor = db.rawQuery(sql, null);
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String name = cursor.getString(1);
int typeOfTraining = cursor.getInt(2);
int weightBest = cursor.getInt(3);
int setsBest = cursor.getInt(4);
int repsBest = cursor.getInt(5);
int sets = cursor.getInt(6);
int reps = cursor.getInt(7);
int weightGoal = cursor.getInt(8);
int setsGoal = cursor.getInt(9);
int repsGoal = cursor.getInt(10);
float distance = cursor.getFloat(11);
float time = cursor.getFloat(12);
float bestTime = cursor.getFloat(13);
float bestDistance = cursor.getFloat(14);
int bestDate = cursor.getInt(15);
int sunday = cursor.getInt(16);
int monday = cursor.getInt(17);
int tuesday = cursor.getInt(18);
int wednesday = cursor.getInt(19);
int thursday = cursor.getInt(20);
int friday = cursor.getInt(21);
int saturday = cursor.getInt(22);
retEx.add(new Exercise(name, weightBest, setsBest, repsBest, sets,
reps, weightGoal, setsGoal, repsGoal, distance, time,
bestTime, bestDistance, bestDate, typeOfTraining, id,
sunday, monday, tuesday, wednesday, thursday, friday,
saturday));
}
db.close();
return retEx;
}