简体   繁体   English

Android sqlite db将数据加载到服务器并截断

[英]Android sqlite db load data to server and truncate

I have written an app that saves some data in sqlite db. 我写了一个将一些数据保存在sqlite db中的应用程序。 Periodically I want to send this data to server and then truncate the tables in sqlite (so that the app does not fill up the space on device). 我要定期将这些数据发送到服务器,然后在sqlite中截断表(这样应用程序就不会填满设备上的空间)。

I am using singleton object of SQLiteOpenHelper (which I have read is thread safe). 我正在使用SQLiteOpenHelper的单例对象(我读过的是线程安全的)。

So my question is - does the following code looks ok- 所以我的问题是-以下代码看起来还可以吗?

SQLiteOpenHelper openHelper = MyDBOpenHelper.getInsance();
SQLiteDatabase database = openHelper.getWritableDatabase();
database.beginTransaction();
Cursor cursor = database.rawQuery(SELECT_ALL_TABLE1_STMT, null);

while( cursor.moveToNext()) {
  // save result in tmp list/buffer
}

database.execSQL(DELETE_ALL_TABLE1_STMT);
database.endTransaction();
database.setTransactionSuccessful();

// send data to server
// and repeat the process for rest of the tables.

If there is another thread that is trying to write to the same table (that I am reading and later will truncate), then does the above code looks ok to handle that scenario? 如果有另一个线程正在尝试写入同一表(我正在读取,稍后将截断),那么上面的代码看起来可以处理这种情况吗?

thanks! 谢谢!

You need more input on this from here: 您需要在这里输入更多信息:

Plus AsyncTask, of course. 当然还有AsyncTask。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM