dimanche 7 juin 2015

SQLite store and retrieve double value

I want to store and retrieve double value in database but i getting one issue when I insert latitude value it's insert perfectly but when I retrieve latitude value it's getting me 0.0 means null....below code

import com.play.findnearplace.FD;

public class Database extends SQLiteOpenHelper {
    protected static final int DATABASE_VERSION = 1;
    protected static final String DATABASE_NAME = "place";
    protected static final String TABLE_NAME = "tbl_place";

    public Database(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        String createdb = "CREATE TABLE IF NOT EXISTS "
                + TABLE_NAME
                + "(id INTEGER PRIMARY KEY AUTOINCREMENT,title VARCHAR NOT NULL ,description TEXT NOT NULL , refereceid TEXT NOT NULL ,place_id TEXT NOT NULL, delat DOUBLE ,delon DOUBLE)";
        db.execSQL(createdb);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF NOT EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public void insertdata(String title,String decription,String refernce,String place_id,Double delat,Double delon){
        SQLiteDatabase db=getWritableDatabase();
        ContentValues v =new ContentValues();
        Logger.i("Query",refernce);
        v.put("title",title);
        v.put("description",decription);
        v.put("refereceid",refernce);
        v.put("place_id",place_id);
        v.put("delat",delat);//here value of delat="2252215.25"

        v.put("delon",delon);
        db.insert(TABLE_NAME,null, v);
        db.close();
    }

    public void isLikedelete(int id) {
        // TODO Auto-generated method stub
        SQLiteDatabase db = this.getWritableDatabase(); 
                db.delete(TABLE_NAME, "id="+id, null);
                db.close();         
    }

    public void isLikealldelete() {
        // TODO Auto-generated method stub
        SQLiteDatabase db = this.getWritableDatabase(); 
                db.delete(TABLE_NAME,null, null);
            //db.execSQL("delete from "+ TABLE_NAME);
                db.close();         
    }

    public void isLikeDeleteByRef(String place_id) {
        // TODO Auto-generated method stub

        SQLiteDatabase db = this.getWritableDatabase(); 

                db.delete(TABLE_NAME, "place_id="+"'"+place_id+"'", null);
                db.close();         
    }

    public List<FD> bookmarkdata(){
        SQLiteDatabase db=getReadableDatabase();
        List<FD> book=new ArrayList<FD>();
        String query="select * from "+ TABLE_NAME;
        Cursor c=db.rawQuery(query,null);


        if(c.moveToFirst()){
            do{
                FD bookmark = new FD();
                bookmark.setid(c.getInt(0));
                bookmark.settitle(c.getString(1));
                bookmark.setshort_title(c.getString(2));
                bookmark.setreference(c.getString(3));
                bookmark.setlat(c.getDouble(4));
                bookmark.setlon(c.getDouble(5));
                Logger.i("DAta",""+c.getDouble(4));//but here value getting c.getDouble(4)=0.0
                book.add(bookmark);
            }while(c.moveToNext());
        }
        db.close();
        c.close();

        return book;
        }

    public boolean checkdataexist(String place_id){
        SQLiteDatabase db=getReadableDatabase();

        String query="select id from "+ TABLE_NAME +" where place_id='"+place_id+"'";
        Logger.i("Query",query);
        Cursor c=db.rawQuery(query,null);
        int count=c.getCount();
        boolean status;
        if (count==0){
            status= false;
        }else{
            status= true;
        }
        db.close();
        c.close();
        return status;
        }


}

in insertdata() method insert value fine but when I retrieve latitude value in bookmarkdata() method its getting me null(0.0) whats a issue here ?

Aucun commentaire:

Enregistrer un commentaire