mardi 7 avril 2015

why sqlite not update row

hi I'm tired of searching and reviewing my code please help me! I want to update a row in table, I think the update but will show up when I see that has not changed much. where is probles code:


DataBaseHelper:



public class DataBaseHelper extends SQLiteOpenHelper {

private static String DB_PATH = "";
private static String DB_NAME ="surbiks";
private final Context mContext;
private SQLiteDatabase mDataBase;


static final int DATABASE_VERSION = 2;

public DataBaseHelper(Context context) {
super(context, DB_NAME, null,DATABASE_VERSION );

this.mContext = context;
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
createDataBase();
}



private void copyDataBase(){

try {

InputStream mInput = mContext.getAssets().open("db/images.db");
String outFileName = DB_PATH + DB_NAME;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer))>0){
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();

} catch (Exception e) {

}
}

public boolean open() throws SQLException
{

try {
String mPath = DB_PATH + DB_NAME;
mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
db = this.getWritableDatabase();
mDataBase=this.getWritableDatabase();
return mDataBase != null;
} catch (Exception e) {
}
return false;
}

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

@Override
public void onCreate(SQLiteDatabase db) {
}


}


and my update code in DataBaseHelper



public void set( ){

open();
String sql="update item_body set fav='1' where id='1'";

mDataBase.execSQL(sql);

close();
}


or this:



public boolean updateContact()
{
ContentValues args = new ContentValues();
open();
args.put("fav", "1");
return mDataBase.update("item_body", args, " id='1' " , null) > 0;

}


Thanks for help


Aucun commentaire:

Enregistrer un commentaire