删除SQLite的记录andoid [英] Delete records from sqlite in andoid

查看:138
本文介绍了删除SQLite的记录andoid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是很简单的问题,但我是新来的SQLite和Android。我的应用程序数据库拥有记录上传到服务器的四个表。我想删除已同步到服务器的记录,我不知道是不是直接运行该查询或者我应该先取记录光标,然后通过删除循环。任何人都可以给我一个样品code的方向。先谢谢了。

I know this is simple question but I'm new to sqlite and android. My app database has four tables for uploading records to server. I want to delete those records which have been synced to server, I don't know whether to run the query directly or should i take the records first in cursor and then delete through the for loop. Can anybody give me the direction with a sample code. Thanks in advance.

推荐答案

既然你不打算保留任何记录推到服务器后,脱机状态。

Since you are not going to keep any records offline after pushing to server.

您可以删除表中的所有记录成功的API调用之后。

you can just delete all the records of the table after the successful API call.

public void deleteAll(String tableName){

SQLiteDatabase db = this.getWritableDatabase();

db.execSQL("DELETE FROM "+tableName); 

db.close();

}

如果您打算保留记录离线你可以有一个像状态一个单独的列,以反映记录(这取决于要求)

if you plan to keep records offline you can have a separate column like status to reflect various states of the record(It depends upon the requirement)

值 - >含义

A - >补充,而不是同步到服务器

A -> Added and not synced to server

的S - >同步的服务器

S -> Synced to server

米 - >修改了同步记录

M -> Modified the synced record

DL - >本地删除

DL -> Deleted locally

D - >无论是在服务器和应用程序完全删除

D -> completely deleted both in server and app.

您可以使用更新 SQL命令修改现有列的状态。

you can use Update sql command for modifying status of existing column.

如果您计划的基础上删除状态的一些记录 value.Let的D是完全useless.so我们可以继续喜欢。

If you plan to delete some records based on Status value.Let's D is completely useless.so we can go ahead like.

public void deleteMarked(String tableName){

SQLiteDatabase db = this.getWritableDatabase();

db.execSQL("DELETE FROM "+tableName+" where status='D'");

db.close();

}

这篇关于删除SQLite的记录andoid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆