Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.kman.AndroMail.data;
- import java.io.File;
- import android.content.Context;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Environment;
- /**
- * Does not derive from SQLiteOpenHelper
- */
- public class MailDbOpenHelper {
- private static final String DIRECTORY_NAME = "AndroMail";
- private static final String DATABASE_NAME = "Messages.sqldb";
- private static final int DATABASE_VERSION = 1;
- private static final String FOLDER_TABLE_CREATE =
- "CREATE TABLE " + MailConstants.FOLDER._TABLE_NAME + " ("
- + "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
- + "name TEXT, "
- + "type INTEGER, "
- + "is_sync INTEGER, "
- + "is_dead INTEGER, "
- + "msg_count_total INTEGER, "
- + "msg_count_unread INTEGER, "
- + "imap_uid_validity INTEGER, "
- + "imap_uid_next INTEGER, "
- + "imap_uid_unseen INTEGER, "
- + "account_id INTEGER "
- + ");";
- public MailDbOpenHelper(Context context) {
- // mContext = context;
- }
- public static File getStoragePath() {
- File d = Environment.getExternalStorageDirectory();
- File f = new File(d, DIRECTORY_NAME);
- return f;
- }
- public static File getDatabaseFile() {
- File d = getStoragePath();
- File f = new File(d, DATABASE_NAME);
- return f;
- }
- public synchronized SQLiteDatabase getReadableDatabase() {
- return getWritableDatabase();
- }
- public synchronized SQLiteDatabase getWritableDatabase() {
- if (mDatabase != null && mDatabase.isOpen()) {
- return mDatabase;
- }
- File dbPath = getStoragePath();
- if (!dbPath.exists()) {
- dbPath.mkdirs();
- }
- File dbFile = getDatabaseFile();
- SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
- int version = db.getVersion();
- if (version != DATABASE_VERSION) {
- db.beginTransaction();
- try {
- if (version == 0) {
- onCreate(db);
- } else {
- onUpgrade(db, version, DATABASE_VERSION);
- }
- db.setVersion(DATABASE_VERSION);
- db.setTransactionSuccessful();
- } finally {
- db.endTransaction();
- }
- }
- mDatabase = db;
- return mDatabase;
- }
- private void onCreate(SQLiteDatabase db) {
- db.execSQL(FOLDER_TABLE_CREATE);
- }
- private void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- }
- // private Context mContext;
- private SQLiteDatabase mDatabase;
- }
Advertisement
Add Comment
Please, Sign In to add comment