PDA

View Full Version : load bulk data.. upto 3000 records from local db (in app)




bluehill
Mar 29, 2011, 02:16 AM
Can any one give alternative on this...

I have a table view with indexing, with each section having related records like Section A will have records starting with A and like that….

Thus the array format is like
[
[Ab,Ac,Ad,Ae,….],
[Ba,Bb,Bc,Bd,….],
……….
]

If i use threads n do lazy loading with User interface visible only starting records will be loaded initially, say list of A's & B's record are loaded.
Now if the user click "z" (tableview with indexing) he will not be able to view records related to z unless the thread has executed and table is reloaded.

Here is the code


static sqlite3 *database = nil;
static sqlite3_stmt *selectStmt = nil;
static sqlite3_stmt *selectThreadStmt = nil;

NSOperationQueue *queue = [NSOperationQueue new];


NSInvocationOperation *operation1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(showSortedContactsList) object:nil];

NSInvocationOperation *operation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector (showSortedFavContactsList) object:nil];

/* Add the operation to the queue */
[queue addOperation:operation1];
[queue addOperation:operation2];

[operation1 release];
[operation2 release];
[queue release];

+(void)showSortedContactsList{

NSMutableString *sqlnonalphnum=[NSMutableString stringWithFormat:@"Select S_id,S_name,S_state,S_city from Supplier where "];
NSLog(@"Dataload");
for (int i=65; i<91;i++) {
//NSMutableArray *tempArray=[[NSMutableArray alloc]init];

[sqlnonalphnum appendFormat:@"S_name not like '%c%%' and ",i];

NSString *sql = [NSString stringWithFormat:@"select S_id,S_name,S_state,S_city from Supplier where S_name like '%c%%'",i];

[Dictionary executeAddGroup:sql];
}
NSString *sqlnonan = [NSString stringWithFormat:@"%@%@",[sqlnonalphnum substringToIndex:[sqlnonalphnum length]-4],@"order by s_name"];

[Dictionary executeAddGroup:sqlnonan];
}

+(void)executeAddGroup:(NSString*)sql{

const char *sqlchar = [sql UTF8String];

if(sqlite3_prepare_v2(database, sqlchar, -1, &selectThreadStmt, NULL) == SQLITE_OK) {

NSMutableArray *tempArray=[[NSMutableArray alloc]init];
while(sqlite3_step(selectThreadStmt) == SQLITE_ROW) {

int sid = (int)sqlite3_column_int(selectThreadStmt, 0);
NSString *snm = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectThreadStmt, 1)];
NSString *sstate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectThreadStmt, 2)];
NSString *scity = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectThreadStmt, 3)];

SupplierQuickInfo *sqinfo = [[SupplierQuickInfo alloc]init];
sqinfo.ssid = sid;
sqinfo.sname = snm;
sqinfo.sstate=sstate;
sqinfo.scitysite=scity;
[tempArray addObject:sqinfo];
[sqinfo release];
}
[listOfContacts addObject:tempArray];

[tempArray release];
selectThreadStmt=nil;

}
}