| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 66676869 |
#pragma mark - FMDB数据库操作//插入-(void)insert{ if ([_db open]) { NSString *sql1 = [NSString stringWithFormat: @"INSERT INTO ‘%@‘ (‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘) VALUES (‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘, ‘%@‘)", TABLENAME, @"starting", @"destination", @"goodsName", @"car", @"goodsWeight", @"goodsVolume",@"intentionPrice",@"bail",@"mark",@"status",_startingLabel.text,_destinationLabel.text,goodsNameTextField.text,selectVehicleLabel.text,goodsWeightTextField.text,goodsVolumeTextField.text,intentionPriceTextField.text,bailTextField.text,markLabel.text,@"0"]; BOOL res = [_db executeUpdate:sql1]; if (!res) { NSLog(@"error when insert db table"); } else { NSLog(@"success to insert db table"); } [_db close]; }}//修改-(void)update{ if ([_db open]) { NSString *updateSql = [NSString stringWithFormat:@"update %@ set %@=‘%@‘ where %@=‘%@‘",TABLENAME,DESTINATION,@"目的地 上海",STARTING,@"芜湖 出发地"]; BOOL res = [_db executeUpdate:updateSql]; if (!res) { NSLog(@"error when insert db table"); } else { NSLog(@"success to insert db table"); } [_db close]; }}//删除-(void)delete{ if ([_db open]) { NSString *deleteSql = [NSString stringWithFormat: @"delete from %@ where %@ = ‘%@‘", TABLENAME, STARTING, @"芜湖 出发地"]; BOOL res = [_db executeUpdate:deleteSql]; if (!res) { NSLog(@"error when insert db table"); } else { NSLog(@"success to insert db table"); } [_db close]; }} //查询 - (void)query { if ([_db open]) { NSString * sql = [NSString stringWithFormat: @"SELECT * FROM %@",TABLENAME]; FMResultSet * rs = [_db executeQuery:sql]; while ([rs next]) { int Id = [rs intForColumn:@"ID"]; NSString * name = [rs stringForColumn:STARTING]; NSString * age = [rs stringForColumn:DESTINATION]; NSString * address = [rs stringForColumn:GOODSNAME]; NSLog(@"id = %d, name = %@, age = %@ address = %@", Id, name, age, address); } [_db close]; }} |