Здрасьте. Объясните пожалуйста вот этот help:
2.1 Determination Of Column Affinity
The affinity of a column is determined by the declared type of the column, according to the following rules in the order shown:
1. If the declared type contains the string "INT" then it is assigned INTEGER affinity.
2. If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
3. If the declared type for a column contains the string "BLOB" or if no type is specified then the column has affinity NONE.
4. If the declared type for a column contains any of the strings "REAL", "FLOA", or "DOUB" then the column has REAL affinity.
Otherwise, the affinity is NUMERIC.
Note that the order of the rules for determining column affinity is important. A column whose declared type is "CHARINT" will match both rules 1 and 2 but the first rule takes precedence and so the column affinity will be INTEGER.
Я так понял, что если я хочу в таблицу закинуть int, string, float и double, то при создании таблица я должен указать следующий текст:
String s = "20.07.2015"
int i = 5;
float f = 0.833f;
double d = 3.5;
Код: Выделить всё
class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "myDB", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d("onCreate", "DataBase");
db.execSQL("CREATE TABLE myTrips ("
+ "id integer primary key autoincrement,"
+ "date text,"
+ "days integer,"
+ "specificWeight real,"
+ "factor real," + ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
Код: Выделить всё
public void onSaveClick(View v){
Log.d("Save", "Click");
cv = new ContentValues();
db = dbhelper.getWritableDatabase();
cv.put("date", s);
cv.put("days", i);
cv.put("specificWeight", f);
cv.put("factor", d);
rowID = db.insert("myTrips", null, cv);
Log.d("ME", "row inserted, ID = " + rowID);
Toast.makeText(TripsRecords.this, "Сохранено", Toast.LENGTH_SHORT).show();
}
public void onReadClick(View v){
Log.d("Read", "Click");
Cursor c = db.query("myTrips", null, null, null, null, null, null);
if(c.moveToFirst()){
int idColIndex = c.getColumnIndex("id");
int dateColIndex = c.getColumnIndex("date");
int daysColIndex = c.getColumnIndex("days");
int specificWeightColIndex = c.getColumnIndex("specificWeight");
int factorColIndex = c.getColumnIndex("factor");
do {
Log.d("ME",
"ID = " + c.getInt(idColIndex) +
", date = " + c.getString(dateColIndex) +
", days = " + c.getString(daysColIndex) +
", specificWeight = " + c.getString(specificWeightColIndex) +
", factor = " + c.getString(factorColIndex));
}while(c.moveToNext());
}else{
Log.d("ME", "Нет записей");
}
c.close();
dbhelper.close();
}
Правильно ли создана таблица?