將大量的數據插入到我的sqlite數據庫中。現在需要很長時間才能完成對用戶來說令人沮喪的過程。任何人都可以在這裏告訴我如何使這個過程快速或任何其他選擇。需要花費很長時間在sqlite數據庫中插入大量的數據
PLSS幫助我..
將大量的數據插入到我的sqlite數據庫中。現在需要很長時間才能完成對用戶來說令人沮喪的過程。任何人都可以在這裏告訴我如何使這個過程快速或任何其他選擇。需要花費很長時間在sqlite數據庫中插入大量的數據
PLSS幫助我..
如果你存儲的圖像或類似的事情,考慮的不是存儲在數據庫中,因爲它是非常低效這樣做。將這種二進制數據存儲在Documents文件夾中,並且如果需要在數據庫中跟蹤它,則通過將文件名存儲在數據庫中,而不是圖像來執行此操作。
如果可能,請在後臺執行這些操作,例如通過Grand Central Dispatch或NSOperationQueue
。這些技術也在Concurrency Programming Guide中討論。如果你正在用SQLite包裝器(例如優秀的FMDB(我衷心建議你調查一下,如果你還沒有的話))這樣做,你可以使用它的FMDatabaseQueue
(它使用GCD)來協調後臺數據庫操作和前臺數據庫查詢。因爲它使用隊列,所以只要可能就要確保在較小的任務中分割後臺數據庫操作,以避免阻塞前臺數據庫操作。
NSOperationQueue
提供用於運行其操作的線程。
創建NSInvocationOperation
對象並將其添加到NSOperationQueue
的數組中。
NSInvocationOperation *insertOperationObject1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod1) object:nil];
NSInvocationOperation *insertOperationObject2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod2) object:nil];
NSInvocationOperation *insertOperationObject3 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod3) object:nil];
//添加數據庫讀取操作的NSOperationQueue
NSOperationQueue *m_opqInsertQueue = [[[NSOperationQueue alloc] init] autorelease];
[m_opqCustomerProfileDataFetchQueue setMaxConcurrentOperationCount:1];
[m_opqCustomerProfileDataFetchQueue addOperations:[NSArray arrayWithObjects:insertOperationObject1, insertOperationObject2, insertOperationObject3, nil] waitUntilFinished:NO];
如果程序運行之前交易完成什麼關係呢? – borrrden 2012-08-01 06:32:45
嘗試lasy加載技術..即使有了這些,如果你使用了大量的數據庫,這是顯而易見的..你可以用NSUser的默認值幾次,而不是 – iMeMyself 2012-08-01 06:39:53