我正在尝试从call_history.db中删除行。我可以在数据库中读取,我找到了我必须取消的行但是当我去启动查询以删除时它什么也没做,我删除了值,但是如果我尝试通过SSH连接到数据库相同的查询工作正常。 我指定我正在使用Jailbroken iPhone并且我的应用程序位于/ Applications文件夹中,然后不在沙箱中。 这是我使用的代码
strPhone是电话号码字符串
data * provaData1 = [[data alloc] init];
NSString * queryPhone = [[NSString alloc] initWithFormat:@"DELETE FROM call WHERE address LIKE '%%%@%%'", strPhone];
[provaData1 eliminaValoriDaDB:@"" :queryPhone withPath:@"var/wireless/Library/CallHistory/call_history.db"];
“数据”实现是这个
- (void)eliminaValoriDaDB:(NSString *)number :(NSString *)sqlString withPath:(NSString *)dbPath {
//NSString *dbPath=@"/User/Library/SMS/sms.db";
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
if(delStmt == nil)
{
const char *sql = [sqlString UTF8String];
//const char *sql = [sqlDel UTF8String];
if(sqlite3_prepare_v2(database, sql, -1, &delStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating del statement. '%s'", sqlite3_errmsg(database));
}
if (![number isEqualToString:@""])
{
sqlite3_bind_int(delStmt, 1, [number intValue]);
}
if (SQLITE_DONE!= sqlite3_step(delStmt)) {
NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database));
}
sqlite3_reset(delStmt);
delStmt = nil;
}
else
NSLog(@"error db not open");
sqlite3_close(database);}
请帮帮我....我不知道该怎么办 谢谢Andrea
答案 0 :(得分:0)
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
NSArray *subPaths = [fileManager subpathsAtPath:@"/private/var/wireless/Library/CallHistory"];
for (NSString *aPath in subPaths) {
BOOL isDirectory;
[fileManager fileExistsAtPath:aPath isDirectory:&isDirectory];
if (isDirectory) {
NSDictionary *attrib = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedLong:775], NSFilePosixPermissions, nil ];
NSError *error = nil;
[fileManager setAttributes:attrib ofItemAtPath:aPath error:error];
if (error)
{
NSLog(@"error: %@", error);
}
}
}