0
votes

my sqlite table structure is :

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)

and now I want to insert one record into the table, insert column : ( date , photopath , wheelId , wheelSize , frontWheelx , frontWheely , rearWheelx , rearWheely ) and ignore column : (latitude , longitude , locationDescription , placemark)

my code is :

    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;

when I run the program, it crashed !! Help me !!

1
when I only insert one column :BOOL succeed = [lunGaiDataBase executeUpdate:@"insert into location (wheelId) values(?)", location.wheelId]; It also crashed ! - staryin

1 Answers

0
votes

If i've not mistaken, your crash message would be something like "EXC_BAD_EXCESS" right?

Try this :

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

Since wheelId is declared as NSInteger, you've got to pass it as

[NSNumber numberWithInt:location.wheelId]