Page 615 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 615
공중망을 이용한 애완동물 사료 공급기
/**
* Created by JBTS-24 on 2016-11-16.
*/
public class DataBase extends SQLiteOpenHelper {
public DataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int
version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE log " +
"([num]INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
"[type] VARCHAR(5) NOT NULL, " +
"[amount] VARCHAR(10) NOT NULL, " +
"[water] VARCHAR(5) NOT NULL, " +
"[time] DATATIME DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'LOCALTIME'))
NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void insert(String type, String amount, String water) {
SQLiteDatabase db = getWritableDatabase();
db.execSQL("INSERT INTO log (type, amount, water) VALUES " +
"('" + type + "' , '" + amount + "', '" + water + "');");
}
public ArrayList<SaveLog> getLog() {
ArrayList<SaveLog> array = new ArrayList<SaveLog>();
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM log order by num desc", null);
while (cursor.moveToNext()) {
array.add(new SaveLog(cursor.getInt(0), cursor.getString(1), cursor.getString(2),
cursor.getString(3), Timestamp.valueOf(cursor.getString(4))));
인천전자마이스터고등학교 - 608 -