2011-08-01 43 views
2

我寫了數據庫副本。我已將我的數據庫放入資產forder.My數據庫大小爲4.5 MB。 如何分塊數據庫。Android數據庫大於1MB

package com.xont.db; 

    public class DataBaseMasterHelper extends SQLiteOpenHelper { 

// The Android's default system path of your application database. 
private static String DB_PATH = "/data/data/com.xont.controller/databases/"; 
private static String DB_NAME = "masterventura.db"; 
private SQLiteDatabase ventura; 
private Context myContext; 
private DataBaseHelper myDbHelper; 

public DataBaseMasterHelper(Context context) { 
    super(context, DB_NAME, null, 1); 
    this.myContext = context; 
} 

/** 
* Creates a empty database on the system and rewrites it with your own 
* database. 
**/ 
public void createDataBase() throws IOException { 
    boolean dbExist = checkDataBase(); 
    if (dbExist) { 
    } else { 
     this.getReadableDatabase(); 
     //this.getReadableDatabase().getPath(); 
     System.out.println(" ===== " +  this.getReadableDatabase().getPath()); 
     try { 
      copyDataBase(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

} 

public boolean checkDataBase() { 
    SQLiteDatabase checkDB = null; 
    try { 
     String myPath = DB_PATH + DB_NAME; 
     checkDB = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY); 
    } catch (SQLiteException e) { 
     e.printStackTrace(); 
    } 

    if (checkDB != null) { 
     checkDB.close(); 
    } 

    return checkDB != null ? true : false; 
} 

private void copyDataBase() throws IOException { 
    InputStream myInput = myContext.getAssets().open(DB_NAME); 
    String outFileName = DB_PATH + DB_NAME; 
    OutputStream myOutput = new FileOutputStream(outFileName); 
    byte[] buffer = new byte[1024]; 
    int length; 
    while ((length = myInput.read(buffer)) > 0) { 
     myOutput.write(buffer, 0, length); 
    } 
    myOutput.flush(); 
    myOutput.close(); 
    myInput.close(); 


} 

public void openDataBase() throws SQLException { 
    String myPath = DB_PATH + DB_NAME; 
    ventura = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY); 

} 

@Override 
public synchronized void close() { 
    if (ventura != null) 
     super.close(); 
     ventura.close(); 
} 

@Override 
public void onCreate(SQLiteDatabase db) { 
} 

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
} 

}

在copyDataBase()方法,我需要改變code.How我可以分裂database.Please幫我在這

在此先感謝...

+1

我看到的唯一方法是在'copyDataBase()'方法中打開數據庫並使用SQL語句處理數據。之後,你可以關閉它並複製到SD卡。數據庫大小可以通過丟棄無用的垃圾(打開數據庫並使用SQL語句訪問)來分塊。 –

回答