Advertisement
Guest User

DbHelper.java

a guest
Jul 20th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package com.mysite.utilities;
  2.  
  3. import android.content.Context;
  4. import android.database.sqlite.SQLiteDatabase;
  5. import android.database.sqlite.SQLiteOpenHelper;
  6. import android.util.Log;
  7.  
  8. import com.mysite.models.Article;
  9. import com.mysite.models.Photo;
  10. import com.mysite.models.Section;
  11.  
  12. public class DbHelper extends SQLiteOpenHelper
  13. {
  14.    
  15.     private static final String DATABASE_NAME = "mysite.news.db";
  16.     private static final int DATABASE_VERSION = 29;
  17.    
  18.     public DbHelper(Context context)
  19.     {
  20.         super(context, DATABASE_NAME, null, DATABASE_VERSION);
  21.     }
  22.    
  23.     @Override
  24.     public void onCreate(SQLiteDatabase database)
  25.     {
  26.         database.execSQL(Article.TABLE_CREATE);
  27.         database.execSQL(Photo.TABLE_CREATE);
  28.         database.execSQL(Section.TABLE_CREATE);
  29.         database.execSQL(Section.POPULATE_TABLE);
  30.     }
  31.    
  32.     @Override
  33.     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
  34.     {
  35.         Log.w(DbHelper.class.getName(),
  36.                 "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
  37.         db.execSQL("DROP TABLE IF EXISTS " + Article.TABLE);
  38.         db.execSQL("DROP TABLE IF EXISTS " + Photo.TABLE);
  39.         db.execSQL("DROP TABLE IF EXISTS " + Section.TABLE);
  40.         onCreate(db);
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement