sqlite在2.1下的异常处理解决

package com.gd.zyrs;

import java.io.File;

import android.content.Context;
import android.content.ContextWrapper;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

class DatabaseContext extends ContextWrapper {

	private static final String DEBUG_CONTEXT = "DatabaseContext";

	public DatabaseContext(Context base) {
		super(base);
	}

	@Override
	public File getDatabasePath(String fullName) {
		String dbfile = fullName;
		if (!dbfile.endsWith(".db")) {
			dbfile += ".db";
		}

		File result = new File(dbfile);

		if (!result.getParentFile().exists()) {
			result.getParentFile().mkdirs();
		}

		if (Log.isLoggable(DEBUG_CONTEXT, Log.WARN)) {
			Log.w(DEBUG_CONTEXT,
					"getDatabasePath(" + fullName + ") = "
							+ result.getAbsolutePath());
		}

		return result;
	}

	@Override
	public SQLiteDatabase openOrCreateDatabase(String name, int mode,
			SQLiteDatabase.CursorFactory factory) {
		SQLiteDatabase result = SQLiteDatabase.openOrCreateDatabase(
				getDatabasePath(name), null);
		// SQLiteDatabase result = super.openOrCreateDatabase(name, mode,
		// factory);
		if (Log.isLoggable(DEBUG_CONTEXT, Log.WARN)) {
			Log.w(DEBUG_CONTEXT, "openOrCreateDatabase(" + name + ",,) = "
					+ result.getPath());
		}
		return result;
	}
}

就可以了

相关推荐