0

我有一个带有 tre 列的 sqlite 数据库:id、纬度、经度。纬度和经度是双倍的,例如 43.98722。当我在我的 android 设备中复制这个数据库时,经度和纬度的值变成 4.398722e+07 所以这可能不适用于我的应用程序。我怎么解决这个问题?也许是我的 dbhelper 通过 InputStream 和 OutputStream 复制一个外部数据库犯了这个错误?

4

2 回答 2

0
public class MyOpenHelper extends SQLiteOpenHelper{


private static String DB_PATH = "/data/data/pack.pullman/databases/";

private static String DB_NAME = "orari";

private SQLiteDatabase myDataBase; 

private final Context myContext;


public MyOpenHelper(Context context) {
    super(context, DB_NAME, null, 1);
    if(android.os.Build.VERSION.SDK_INT >= 4.2){
        DB_PATH = context.getApplicationInfo().dataDir + "/databases/";         
    } else {
       DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
    }
    this.myContext = context; 
}   

public void createDataBase() throws IOException{

    boolean dbExist = checkDataBase();

    if(dbExist){

    }else{

        this.getReadableDatabase();

        try {

            copyDataBase();


        } catch (IOException e) {

            throw new Error("Error copying database");

        }
    }

}


private boolean checkDataBase(){

    SQLiteDatabase checkDB = null;

    try{
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

    }catch(SQLiteException e){


    }

    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);
    }

    //Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();

}

public void openDataBase() throws SQLException{

    //Open the database
    String myPath = DB_PATH + DB_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);


}

@Override
public synchronized void close() {

        if(myDataBase != null)
            myDataBase.close();

        super.close();

}
@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

    }
于 2013-07-12T15:22:19.047 回答
0
    public List<Coordinate> vediCoordinate(){
    SQLiteDatabase db=oh.getReadableDatabase();
    String c[]=new String[]{"lat","long","via"};
    cu=db.query("linee", c, null, null, null, null, null);
    int rows=cu.getCount();
    LinkedList<Coordinate> risultato=new LinkedList<Coordinate>();
    cu.moveToFirst();
    for(int i=0;i<rows;i++){
        risultato.add(i,new Coordinate(cu.getDouble(cu.getColumnIndex("lat")),cu.getDouble(cu.getColumnIndex("long")),cu.getString(cu.getColumnIndex("via"))));
        cu.moveToNext();
    }
    cu.close();
    return risultato;   
}
于 2013-07-12T15:41:25.877 回答