Page 89 - 3-3
P. 89

@Override










                          public void onUpgrade(SQLiteDatabase de, 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 (curosr.moveToNext()) {
                               array.add(new           SaveLog(cursor.getInt(0),          cursor.getString(1),
              cursor.getString(2), cursor.getString(3), Timestamp.valueOf(cursor.getString(4))));


                          }
                        return array;
                      }




                    public void resetLog() {
                       SQLiteDatabase db = getWritableDatabase();
                       db.execSQL("UPDATE SQLITE_SEQUENCE SET seq = 0 WHERE name = 'log'");
                       db.execSQL("DELETE FROM log");
                       db.close();
                    }
                 }


                 SaveLog.java
                 package com.example.puppy;


                 import java.sql.Timestamp;


                /**


                                                           - 89 -
   84   85   86   87   88   89   90   91   92   93   94