You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
1.3 KiB

  1. package at.ac.perg.htl.bhif16.coffeeapp;
  2. import android.content.Context;
  3. import android.database.sqlite.SQLiteDatabase;
  4. import android.database.sqlite.SQLiteOpenHelper;
  5. import android.util.Log;
  6. import static android.content.Context.MODE_PRIVATE;
  7. public class UserDB extends SQLiteOpenHelper {
  8. private static final String DATABASE_NAME = "USERS.db";
  9. private static final int DATABASE_VERSION = 1;
  10. // Database creation sql statement
  11. private static final String create_table = "CREATE TABLE IF NOT EXISTS students(id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT, drink INTEGER);";
  12. public UserDB(Context context) {
  13. super(context, DATABASE_NAME, null, DATABASE_VERSION);
  14. }
  15. // Method is called during creation of the database
  16. @Override
  17. public void onCreate(SQLiteDatabase database) {
  18. database.execSQL(create_table);
  19. }
  20. // Method is called during an upgrade of the database,
  21. @Override
  22. public void onUpgrade(SQLiteDatabase database,int oldVersion,int newVersion){
  23. Log.w(UserDB.class.getName(),"Upgrading database from version " + oldVersion + " to "
  24. + newVersion + ", which will destroy all old data");
  25. database.execSQL("DROP TABLE IF EXISTS FridgeItem");
  26. onCreate(database);
  27. }
  28. }