FMDB使用注意事项

1、数据格式必须是NSObject对象,即使在数据表中是整型(integer)、浮点型(float),如

    NSString * dishId = [_infoDictionary objectForKey:@"id"];

    NSString * dishName = [_infoDictionary objectForKey:@"name"];

    NSString * specialPrice = [NSString stringWithFormat:@"%@",[_infoDictionary objectForKey:@"favorablePrice"]]; NSString * price = [NSString stringWithFormat:@"%@",[_infoDictionary objectForKey:@"price"]];

    NSString * countStr = @"1";

    BOOL insert = [database executeUpdate:@"insert into menu values (?,?,?,?,?)",dishId,dishName,specialPrice,price,countStr];

上面是正确的代码,如果使用如下格式插入数据,则会bad access..

    NSString * dishId = [_infoDictionary objectForKey:@"id"];

    NSString * dishName = [_infoDictionary objectForKey:@"name"];

 NSString * specialPrice = [_infoDictionary objectForKey:@"favorablePrice"]; NSString * price = [_infoDictionary objectForKey:@"price"];

    NSString * countStr = @"1";

    BOOL insert = [database executeUpdate:@"insert into menu values (?,?,?,?,?)",dishId,dishName,specialPrice,price,countStr];

注意,

[_infoDictionary objectForKey:@"price"]与
[_infoDictionary objectForKey:@"favorablePrice"]
是浮点型字符串,如@"12.5"

你可能感兴趣的:(DB)