ios:如何使用fmdb将空值插入sqlite

时间:2013-02-07 06:55:08

标签: ios sqlite

我的sqlite表结构是:

CREATE TABLE "location" ("latitude" DOUBLE,"longitude" DOUBLE,"date" DATETIME,"locationDescription" VARCHAR,"photopath" VARCHAR,"placemark" BLOB,"wheelId" INTEGER,"wheelSize" DOUBLE,"frontWheelx" DOUBLE,"frontWheely" DOUBLE,"rearWheelx" DOUBLE,"rearWheely" DOUBLE)

现在我想在表格中插入一条记录,插入列:(日期,photopath,wheelId,wheelSize,frontWheelx,frontWheely,rearWheelx,rearWheely)并忽略列:(纬度,经度,locationDescription,地标)

我的代码是:

    BOOL succeed = [lunGaiDataBase executeUpdate:@"insert into location (date, photopath, wheelid, wheelsize, frontwheelx, frontwheely, rearwheelx, rearwheely) values(?,?,?,?,?,?,?,?)",
     location.date,location.photoPath, location.wheelId,location.wheelSize,location.frontWheelx,location.frontWheely,location.rearWheelx,location.rearWheely];


my location class is :

    @property (nonatomic, assign) double latitude;
    @property (nonatomic, assign) double  longitude;
    @property (nonatomic, retain) NSDate * date;
    @property (nonatomic, retain) NSString * locationDescription;
    @property (nonatomic, retain) NSString * photoPath;
    //@property (nonatomic, retain) NSString * category;
    @property (nonatomic, retain) CLPlacemark * placemark;
    @property (nonatomic, assign) NSInteger  wheelId;
    @property (nonatomic, assign) double frontWheelx;
    @property (nonatomic, assign) double frontWheely;
    @property (nonatomic, assign) double rearWheelx;
    @property (nonatomic, assign) double rearWheely;
    @property (nonatomic, assign) double wheelSize;

当我运行该程序时,它崩溃了!!帮帮我!!

1 个答案:

答案 0 :(得分:0)

如果我没有弄错的话,你的崩溃信息会像"EXC_BAD_EXCESS"那样对吗?

试试这个:

BOOL succeed = [lunGaiDataBase executeUpdate:@"insert into location (wheelId) values(?)",
 [NSNumber numberWithInt:location.wheelId]];

由于wheelId被声明为NSInteger,您必须将其作为

传递
[NSNumber numberWithInt:location.wheelId]