分析是在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;
答案 0 :(得分:11)
一个简单的解决方法是改变
unsigned long long affectedRows;
到
unsigned long long affectedRows = 0;
答案 1 :(得分:2)
如果self.sqlPut
和sqlPut
都是NULL
s,则不会初始化该值。也许,内部if
需要else
。