1

Im inserting a huge amount of data into my sqlite database. Now it takes a long time to complete the process which would be frustuating for the user. Could anyone here give me any idea on how to make this process fast or any alternative.

Plss help me..

  • Does it matter if the transaction finishes before the program moves on? – borrrden Aug 01 '12 at 06:32
  • try lasy loading technique .. even with these if you are using much of DB this is obvious .. you can user NSUser Defaults few times instead – iMeMyself Aug 01 '12 at 06:39

2 Answers2

1
  1. If you're storing images or things like that, consider not storing that in the database, as it's pretty inefficient to do so. Store that sort of binary data in the Documents folder and if you need to keep track of it in the database, do so by storing the filenames in the database, but not the image.

  2. If at all possible, do these operations in the background, such as through Grand Central Dispatch or NSOperationQueue. These technologies are also discussed in the Concurrency Programming Guide. If you're doing this with a SQLite wrapper, such as the excellent FMDB (which I heartily recommend you investigate if you haven't already), you can use its FMDatabaseQueue (which uses GCD) to coordinate background database operations with foreground database queries. Because it's using queues, you'll just want to make sure to break the background database operations in smaller tasks if possible to avoid the perception of blocking foreground database operations.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
0

NSOperationQueue provide the threads used to run their operations.

Create NSInvocationOperation objects and add it in the array of 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];

//adding database fetch operations to an NSOperationQueue

 NSOperationQueue     *m_opqInsertQueue = [[[NSOperationQueue alloc] init] autorelease];
        [m_opqCustomerProfileDataFetchQueue setMaxConcurrentOperationCount:1];
        [m_opqCustomerProfileDataFetchQueue addOperations:[NSArray arrayWithObjects:insertOperationObject1, insertOperationObject2, insertOperationObject3,  nil] waitUntilFinished:NO];
Anil Kothari
  • 7,653
  • 4
  • 20
  • 25