我在将数据插入sqlite数据库时遇到问题。
char *update="INSERT OR REPLACE INTO ct_subject (id,id_parent, title, description, link, address, phone, pos_lat, pos_long, no_votes, avg_vote, photo, id_comerc, id_city, placement, type, timestamp, mail) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
sqlite3_stmt *stmt;
if(sqlite3_prepare_v2(database, update, -1, &stmt, nil) == SQLITE_OK){
sqlite3_bind_int(stmt, 1, [[[newCategories objectAtIndex:i] valueForKey:@"id"] intValue]);
sqlite3_bind_int(stmt, 2, [[[newCategories objectAtIndex:i] valueForKey:@"id_parent"] intValue]);
sqlite3_bind_text(stmt, 3, [[[newCategories objectAtIndex:i] valueForKey:@"title"] UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 4, [[[newCategories objectAtIndex:i] valueForKey:@"description"] UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 5, [[[newCategories objectAtIndex:i] valueForKey:@"link"] UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 6, [[[newCategories objectAtIndex:i] valueForKey:@"address"] UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 7, [[[newCategories objectAtIndex:i] valueForKey:@"phone"] UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 8, [[[newCategories objectAtIndex:i] valueForKey:@"pos_lat"] UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 9, [[[newCategories objectAtIndex:i] valueForKey:@"pos_long"] UTF8String], -1, NULL);
sqlite3_bind_int(stmt, 10, [[[newCategories objectAtIndex:i] valueForKey:@"no_votes"] intValue]);
sqlite3_bind_text(stmt, 11, [[[newCategories objectAtIndex:i] valueForKey:@"avg_vote"] UTF8String], -1, NULL);
if ([[[newCategories objectAtIndex:i] valueForKey:@"photo"] length]!=0) {
NSMutableString *webUrl = (NSMutableString *)[[NSMutableString alloc] initWithString:@"http://www.crotune.com/public/images/subjects/"];
[webUrl appendString:[[newCategories objectAtIndex:i] valueForKey:@"photo"]];
UIImage *myImage = [self getWebImage:webUrl];
if(myImage != nil){
sqlite3_bind_blob(stmt, 12, [UIImagePNGRepresentation(myImage) bytes], [UIImagePNGRepresentation(myImage) length], NULL);
}
else {
sqlite3_bind_blob(stmt, 12, nil, -1, NULL);
}
[webUrl release];
[myImage release];
}
else {
sqlite3_bind_blob(stmt, 12, nil, -1, NULL);
//NSLog(@" ne dodajem sliku2");
}
sqlite3_bind_int(stmt, 13, [[[newCategories objectAtIndex:i] valueForKey:@"id_comerc"] intValue]);
sqlite3_bind_int(stmt, 14, [[[newCategories objectAtIndex:i] valueForKey:@"id_city"] intValue]);
sqlite3_bind_int(stmt, 15, [[[newCategories objectAtIndex:i] valueForKey:@"placement"] intValue]);
sqlite3_bind_int(stmt, 16, [[[newCategories objectAtIndex:i] valueForKey:@"type"] intValue]);
sqlite3_bind_int(stmt, 17, [[[newCategories objectAtIndex:i] valueForKey:@"timestamp"] intValue]);
sqlite3_bind_text(stmt, 18, [[[newCategories objectAtIndex:i] valueForKey:@"mail"] UTF8String], -1, NULL);
}
if (sqlite3_step(stmt) != SQLITE_DONE) {
NSLog(@"%s", sqlite3_errmsg(database));
NSAssert1(0,@"nemogu updateat table %s", errorMsg);
}
else {
NSLog(@"Ubacio %d",i);
}sqlite3_finalize(stmt);
它会开始吃内存,直到最终退出...在内存警告我再次关闭并打开数据库时,我已将缓存大小设置为50,如此处的一些帖子所述,并尝试将查询置于语句中 - 相同的结果.. 在iphone上插入300个插件或在iPad上插入约900个插件后,它只会让妈咪和应用程序退出... 任何帮助将不胜感激..
答案 0 :(得分:1)
哇。与CoreData相比,SQLite代码很难看。但是,嘿,他自己......
使用Allocations工具找出消耗所有内存的内容。在没有看到代码的情况下,UIImage *myImage = [self getWebImage:webUrl];
可能会过度保留图像数据吗?
除此之外,如果没有看到更多代码或更多证据,很难猜测可能会发生什么。