Earlier I asked a question about why my getColumnIndex returned a -1 result on my column I was sure existed (Android SQlite returning -1 with getColumnIndex when column obviously exists). The question was clearly answered but I discovered in the process that it turned out that my database was setup incorrectly. what I thought were columns are simply values in the "name" column. Being that I setup my database from several examples I found, perhaps I am unclear on how SQLite databases are actually setup. I'm used to Access databases, so I think I might making assumptions that I shouldn't be.
Below is the table creation method I used, but really what I'm trying to determine is how to setup the database table like to have columns as in:
Id | name | date | altitude | etc. <----Columns
1 | "name1" | "date1" | 5 | etc. <----row
2 | "name2" | "date2" | 3 | etc. <----row
etc.
Thank you for the help!
Table Creation Method:
//Database creation sql statement
private static final String SQL_CREATE_SPECIAL_DAYS =
"CREATE TABLE " + dbFields.TABLE_NAME_SPECIAL_DAYS + " (" +
dbFields.COLUMN_SPECIAL_DAYS_ID + INTEGER_PRIMARY_KEY + COMMA_SEP +
dbFields.COLUMN_SPECIAL_DAYS_DATE + TEXT_TYPE + COMMA_SEP +
dbFields.COLUMN_SPECIAL_DAYS_NAME + TEXT_TYPE + COMMA_SEP +
dbFields.COLUMN_SPECIAL_DAYS_ALTITUDE + INTEGER_TYPE + COMMA_SEP +
dbFields.COLUMN_SPECIAL_DAYS_USED + INTEGER_TYPE + COMMA_SEP +
dbFields.COLUMN_SPECIAL_DAYS_WARNING + INTEGER_TYPE + COMMA_SEP +
dbFields.COLUMN_SPECIAL_DAYS_ACTION + INTEGER_TYPE +
// Any other options for the CREATE command
" )";
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(SQL_CREATE_SPECIAL_DAYS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(MySQLiteHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + dbFields.TABLE_NAME_SPECIAL_DAYS);
onCreate(db);
}
Aucun commentaire:
Enregistrer un commentaire