1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#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];
}
}
|