Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package com.example.konrad.sqlite_database.feature;
  2.  
  3. import android.database.sqlite.SQLiteDatabase;
  4. import android.database.sqlite.SQLiteOpenHelper;
  5. import android.content.Context;
  6. import android.util.Log;
  7.  
  8.  
  9. public class MyDatabase extends SQLiteOpenHelper {
  10.  
  11.  
  12. public static final int DATABASE_VERSION = 1;
  13. public static final String DATABASE_NAME = "mydatabase.db";
  14.  
  15. private static final String SQL_CREATE_ENTRIES = "CREATE TABLE " + MyDatabaseInfo.TABLE_NAME + " (" + MyDatabaseInfo._ID + " INTEGER PRIMARY KEY," + MyDatabaseInfo.COLUMN_NAME_USER_NAME + " TEXT," + MyDatabaseInfo.COLUMN_NAME_CASH + " INTEGER" + ")";
  16.  
  17. private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + MyDatabaseInfo.TABLE_NAME;
  18.  
  19. private final static String LOG_TAG = "RKLog";
  20.  
  21. public MyDatabase(Context context){
  22. super(context, DATABASE_NAME, null, DATABASE_VERSION);
  23. }
  24.  
  25. @Override
  26. public void onCreate(SQLiteDatabase db) {
  27. db.execSQL(SQL_CREATE_ENTRIES);
  28. }
  29.  
  30. @Override
  31. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  32. Log.w(LOG_TAG, "Upgrading database from version " + oldVersion + "to" + newVersion + ", which will destroy all old data");
  33. db.execSQL(SQL_DELETE_ENTRIES);
  34. onCreate(db);
  35. }
  36. @Override
  37. public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  38. onUpgrade(db, oldVersion, newVersion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement