消息表达式中的参数是未经初始化的值,对于NS数字,无符号长

时间:2011-04-06 19:03:58

标签: objective-c c cocoa

分析是在subj中生成警告。 有什么建议吗?

const char *cString = [query UTF8String]; 
unsigned long long affectedRows;

if (self.sqlPut != NULL) { 
    mysql_query(self.sqlPut,cString); 
    affectedRows = mysql_affected_rows(self.sqlPut);
    if (affectedRows == 0) NSLog(@"MYSQL: Query: %@ was failed  with error:%s\n and error number:%d",query,mysql_error(self.sqlPut),mysql_errno(self.sqlPut));
}
else {
    [self mysqlConnect];
    if (sqlPut != NULL) {
        mysql_query(self.sqlPut,cString);
        affectedRows = mysql_affected_rows(self.sqlPut);
        if (affectedRows == 0) NSLog(@"MYSQL: Query: %@ was failed  with error:%s\n and error number:%d",query,mysql_error(self.sqlPut),mysql_errno(self.sqlPut));
    }
}
NSNumber *affectedRowsNumber = [[[NSNumber alloc] initWithUnsignedLongLong:affectedRows] autorelease];
return affectedRowsNumber;

2 个答案:

答案 0 :(得分:11)

一个简单的解决方法是改变

unsigned long long affectedRows;

unsigned long long affectedRows = 0;

答案 1 :(得分:2)

如果self.sqlPutsqlPut都是NULL s,则不会初始化该值。也许,内部if需要else