简体   繁体   English

在iOS中处理超大型数据库

[英]Handling very large databases in iOS

I want to know how to handle very large DBs in iOS? 我想知道如何在iOS中处理非常大的数据库吗?

Explanation: 说明:

I am making an app for the company, it will be holding all daily transactions and operations (this means few hundreds to a couple thousands a day ). 我正在为公司制作一个应用程序,它将负责所有日常交易和运营(这意味着每天几百到几千个 )。 The app in fact just displays the daily transactions, but keeps everything in the DB just in case (so I can not delete them). 该应用程序实际上仅显示日常交易,但会将所有内容保留在数据库中,以防万一(因此我无法删除它们)。

As there is a need for the app to be highly reactive, I am searching for a way to efficiently load (Core Data Fetch) just the latest operations, without being slowed down in the long run when the DB gets really large. 由于需要使应用程序具有高度的响应性,因此我正在寻找一种方法来高效地加载(核心数据提取)仅最新的操作,而从长远来看,当数据库变大时,不会降低速度。 Knowing that whenever an operation is updated, I refresh the displayed table immediately. 知道每当操作更新时,我都会立即刷新显示的表。

I can't find any article dealing with this on iOS, so I can't find any good practice or a correct way to handle it. 我在iOS上找不到任何有关此问题的文章,因此找不到任何好的做法或正确的处理方式。

On a MySQL server, I'd do like this: * Set up a DB for daily "active" operations, when done, delete them and move them to a "finished" operations DB. 在MySQL服务器上,我会这样:*为日常的“活动”操作设置一个数据库,完成后将其删除,然后将其移至“完成的”操作数据库。 * Set up a Cron job to dump/backup daily/monthly DBs by night, and having a fresh lightweight one for the next day. *设置Cron作业以在夜间转储/备份每日/每月的数据库,并在第二天有一个新的轻量级数据库。

Sadly, it doesn't seem possible to create a dynamic table on iOS, and even creating a "finished" DB, this will still require accessing a heavy DB at each closed operation, which can lead to a low memory crash. 令人遗憾的是,似乎不可能在iOS上创建动态表,甚至无法创建“完成的”数据库,这仍然需要在每次关闭操作时访问较重的数据库,这可能导致内存不足的崩溃。

actually I think you can try sqlite api to match the same operations in your MySQL server. 实际上,我认为您可以尝试sqlite api来匹配MySQL服务器中的相同操作。 However, you will have to drop the CoreData and rewrite everything instead, ie, TableView, TableCell, etc. to deal with the DataSource like this: 但是,您必须删除CoreData并改写所有内容,例如TableView,TableCell等,以便像这样处理DataSource:

sqlite3 * tradeDB;
sqlite3_open_v2([path UTF8String], &tradeDB, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nil);
sqlite3_stmt * recordset;
int res = sqlite3_prepare_v2(tradeDB, "select count(*) from someTable", -1, &recordset, nil);
if (res!=SQLITE_OK) {
    return nil;
}//end if

res = sqlite3_step(recordset);
if (res!=SQLITE_ROW) {
    _result = nil;
}else{
    char * res_char = (char*)sqlite3_column_text(recordset, 0);
    if (!res_char)
        _result = nil;
    else
        _result = [NSString stringWithUTF8String:res_char];
    //end if
}//end if
sqlite3_finalize(recordset);

if (!_result) {
    _result = @"0";
}//end if
return self;

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

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