私はこれにかなりイライラしています。データベース内にいくつかの文字列値を入れようとしましたが、値を取得するフィールドは 4 つだけです。違う
次のコード:
データを挿入する場所:
DatabaseHandler db = new DatabaseHandler(this);
db.deleteStats(5);
db.deleteStats(6);
db.addStats(new Stats( "O Teste 01",
"teste 1.gpx",
"00:10:00",
"100.00",
"10.0",
"10.0",
"20.0",
"20",
"1",
"10",
"100",
"1",
"2012-07-15 12:00:00"));
Stats.java
public class Stats {
private Integer mId;
private String mName;
private String mFilename;
private String mTotalTime;
private String mTotalDistance;
private String mAvgSpeed;
private String mMinSpeed;
private String mMaxSpeed;
private String mAcumAltitude;
private String mMaxAltitude;
private String mMinAltitude;
private String mCalories;
private String mMod;
private String mDate;
// Construtor vazio
public Stats(){
}
// Construtor
public Stats( Integer mId, String mName, String mFilename, String mTotalTime, String mTotalDistance, String mAvgSpeed,
String mMinSpeed, String mMaxSpeed, String mAcumAltitude, String mMinAltitude, String mMaxAltitude,
String mCalories, String mMod, String mDate)
{
this.mId = mId;
this.mName = mName;
this.mFilename = mFilename;
this.mTotalTime = mTotalTime;
this.mTotalDistance = mTotalDistance;
this.mAvgSpeed = mAvgSpeed;
this.mMinSpeed = mMinSpeed;
this.mMaxSpeed = mMaxSpeed;
this.mAcumAltitude = mAcumAltitude;
this.mMinAltitude = mMinAltitude;
this.mMaxAltitude = mMaxAltitude;
this.mCalories = mCalories;
this.mMod = mMod;
this.mDate = mDate;
}
// Construtor
public Stats( String mName, String mFilename, String mTotalTime,
String mTotalDistance, String mAvgSpeed, String mMinSpeed, String mMaxSpeed,
String mAcumAltitude, String mMinAltitude, String mMaxAltitude,
String mCalories, String mMod,
String mDate)
{
this.mName = mName;
this.mFilename = mFilename;
this.mTotalTime = mTotalTime;
this.mTotalDistance = mTotalDistance;
this.mAvgSpeed = mAvgSpeed;
this.mMinSpeed = mMinSpeed;
this.mMaxSpeed = mMaxSpeed;
this.mAcumAltitude = mAcumAltitude;
this.mMinAltitude = mMinAltitude;
this.mMaxAltitude = mMaxAltitude;
this.mCalories = mCalories;
this.mMod = mMod;
this.mDate = mDate;
}
public Stats(String string, String string2, String string3, String string4) {
// TODO Auto-generated constructor stub
this.mName = string;
this.mFilename = string2;
this.mTotalTime = string3;
this.mDate = string4;
}
public Integer getmId() {
return mId;
}
public void setmId(Integer mId) {
this.mId = mId;
}
public String getmName() {
return mName;
}
public void setmName(String mName) {
this.mName = mName;
}
public String getmFilename() {
return mFilename;
}
public void setmFilename(String mFilename) {
this.mFilename = mFilename;
}
public String getmTotalTime() {
return mTotalTime;
}
public void setmTotalTime(String mTotalTime) {
this.mTotalTime = mTotalTime;
}
public String getmTotalDistance() {
return mTotalDistance;
}
public void setmTotalDistance(String mTotalDistance) {
this.mTotalDistance = mTotalDistance;
}
public String getmAvgSpeed() {
return mAvgSpeed;
}
public void setmAvgSpeed(String mAvgSpeed) {
this.mAvgSpeed = mAvgSpeed;
}
public String getmMinSpeed() {
return mMinSpeed;
}
public void setmMinSpeed(String mMinSpeed) {
this.mMinSpeed = mMinSpeed;
}
public String getmMaxSpeed() {
return mMaxSpeed;
}
public void setmMaxSpeed(String mMaxSpeed) {
this.mMaxSpeed = mMaxSpeed;
}
public String getmAcumAltitude() {
return mAcumAltitude;
}
public void setmAcumAltitude(String mAcumAltitude) {
this.mAcumAltitude = mAcumAltitude;
}
public String getmMaxAltitude() {
return mMaxAltitude;
}
public void setmMaxAltitude(String mMaxAltitude) {
this.mMaxAltitude = mMaxAltitude;
}
public String getmMinAltitude() {
return mMinAltitude;
}
public void setmMinAltitude(String mMinAltitude) {
this.mMinAltitude = mMinAltitude;
}
public String getmCalories() {
return mCalories;
}
public void setmCalories(String mCalories) {
this.mCalories = mCalories;
}
public String getmMod() {
return mMod;
}
public void setmMod(String mMod) {
this.mMod = mMod;
}
public String getmDate() {
return mDate;
}
public void setmDate(String mDate) {
this.mDate = mDate;
}
データを sqlite に挿入する関数:
public void addStats(Stats st)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DatabaseHandler.COLUMN_NAME, st.getmName());
values.put(DatabaseHandler.COLUMN_FILENAME, st.getmFilename());
values.put(DatabaseHandler.COLUMN_TOTAL_TIME, st.getmTotalTime());
values.put(DatabaseHandler.COLUMN_TOTAL_DISTANCE, st.getmTotalDistance());
values.put(DatabaseHandler.COLUMN_AVG_SPEED, st.getmAvgSpeed());
values.put(DatabaseHandler.COLUMN_MIN_SPEED, st.getmMinSpeed());
values.put(DatabaseHandler.COLUMN_MAX_SPEED, st.getmMaxSpeed());
values.put(DatabaseHandler.COLUMN_ACUM_ALTITUDE, st.getmAcumAltitude());
values.put(DatabaseHandler.COLUMN_MIN_ALTITUDE, st.getmMinAltitude());
values.put(DatabaseHandler.COLUMN_MAX_ALTITUDE, st.getmMaxAltitude());
values.put(DatabaseHandler.COLUMN_CALORIES, st.getmCalories());
values.put(DatabaseHandler.COLUMN_MOD, st.getmMod());
values.put(DatabaseHandler.COLUMN_DATE, st.getmDate());
// Adiciona linha
db.insert(DatabaseHandler.TABLE_STATS, null, values);
db.close(); // fechando a conexão à base de dados
}
前もって感謝します!
これが残りのコードです...
public class DatabaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 4;
// Database Name
private static final String DATABASE_NAME = "magik_tracker_gpx";
// estatísticas table name
private static final String TABLE_STATS = "stats";
// estatísticas Table Columns names
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_FILENAME = "filename";
public static final String COLUMN_TOTAL_TIME = "total_time";
public static final String COLUMN_TOTAL_DISTANCE = "total_distance";
public static final String COLUMN_AVG_SPEED = "avg_speed";
public static final String COLUMN_MIN_SPEED = "min_speed";
public static final String COLUMN_MAX_SPEED = "max_speed";
public static final String COLUMN_ACUM_ALTITUDE = "acum_altitude";
public static final String COLUMN_MIN_ALTITUDE = "min_altitude";
public static final String COLUMN_MAX_ALTITUDE = "max_altitude";
public static final String COLUMN_CALORIES = "calories";
public static final String COLUMN_MOD = "mod";
public static final String COLUMN_DATE = "date";
private static final String DATABASE_CREATE = "create table "
+ TABLE_STATS + " ( "
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_NAME + " text,"
+ COLUMN_FILENAME + " text, "
+ COLUMN_TOTAL_TIME + " text, "
+ COLUMN_TOTAL_DISTANCE + " text, "
+ COLUMN_AVG_SPEED + " text, "
+ COLUMN_MIN_SPEED + " text, "
+ COLUMN_MAX_SPEED + " text, "
+ COLUMN_ACUM_ALTITUDE + " text, "
+ COLUMN_MIN_ALTITUDE + " text, "
+ COLUMN_MAX_ALTITUDE + " text, "
+ COLUMN_CALORIES + " text ,"
+ COLUMN_MOD + " text, "
+ COLUMN_DATE + " text "
+ ");";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_STATS);
// Create tables again
onCreate(db);
}