您的位置:首页 > 数据库

数据库操作

2016-01-12 22:40 141 查看
//增加一个tabel

NSString *path=[NSHomeDirectory() stringByAppendingString:@"/Documents/mydata.sqlite"];
    NSLog(@"%@",NSHomeDirectory());
    db=[FMDatabase databaseWithPath:path];

NSString *sql=@"create table if not exists mytable (id text primary key,name text,age text)";

[db executeUpdate:sql]

 //插入多组对象
    if ([db open]) {
        [db executeUpdate:@"insert into mytable(id,name,age) select '5','nan','nv' union all select  'nihao','wohao','dajiahao'"];
        //通过id删除对象
//        [db executeUpdate:@"delete from mytable where id='5'"];
        //在指定组更新指定对象
//        [db executeUpdate:@"update mytable set name='hello' where id='nihao'"];
        //通过id找出相应得一组数据;
        FMResultSet *reset=[db executeQuery:@"select * from
mytable where id='nihao'"];
        if (reset.next) {
            NSString *str1=[reset stringForColumn:@"id"];
            NSString *str2=[reset stringForColumn:@"name"];
            NSString *str3=[reset stringForColumn:@"age"];
            NSLog(@".....%@,%@,%@",str1,str2,str3);
        }
        
    }
    
    [db close];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: