我正在我的 iOS 应用程序中进行同步。我的文档文件夹中已经有一组表,并且在同步期间我正在从服务器下载数据到一组新表中。我正在比较各个表的数量,如果它们相同,我正在使用自然连接来检查它们实际上是否相同。如果它们相同,那么我的内容是最新的,我不需要对我当前的表集进行任何更改,否则我将获取新的表集并将新数据存储为我的当前表。
问题是,当我对某些表进行自然连接时,虽然我在 SQLITEMANAGER 中看到两个表的信息相同,但自然连接会返回错误的答案。不知道为什么。count_together 是错误的,即使值相同。
这就是我实施检查的方式(仅用于说明):
singleton.table = YES;
int count_table1 = 0;
int count_table2 = 0;
int count_together = 0;
NSMutableArray *arrayTables = [[NSMutableArray alloc] initWithObjects:@"DATA",@"TABLE",@"NUMBERS",nil];
NSMutableArray *arrayTables2 = [[NSMutableArray alloc] initWithObjects:@"DATA2",@"TABLE2",@"NUMBERS2", nil];
for(int i =0; i<[arrayTables count]; i++)
{
count_table1 = [databaseManager checkCountOfTable:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@",[arrayTables objectAtIndex:i]]];
count_table2 = [databaseManager checkCountOfTable:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@",[arrayTables2 objectAtIndex:i]]];
NSLog(@"Count of Table 1 is %i",count_table1);
NSLog(@"Count of Table 2 is %i",count_table2);
if (singleton.table == YES)
{
if(count_table1 != count_table2)
{
singleton.table = NO;
}
else
{
count_together = [databaseManager checkCountOfTable:[NSString stringWithFormat: @"SELECT COUNT(*) FROM (%@ NATURAL JOIN %@)",[arrayTables objectAtIndex:i],[arrayTables2 objectAtIndex:i]]];
NSLog(@"Count of Table 1 is %i",count_table1);
NSLog(@"Count of Tables Together is %i",count_together);
if (count_table1 == count_together)
{
singleton.table = YES;
}
else
{
singleton.table = NO;
}
}
}
}
需要一些指导,欢迎提出建议。