数据库操作
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];
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];
相关文章推荐
- 【技术支持】使用eclipse登陆oracle
- mysql存储过程事务处理小经验
- MySQL ERROR 1045 (28000): Access denied for user解决方法
- CentOS7安装memcached
- Redis的安装及使用
- 常用sql(转)
- XXMySQL数据库运维变更流程
- MSSQL只能访问特定的数据库
- Mongodb千万级数据在python下的综合压力测试及应用探讨
- 业务数据库开发上线流程v1.0
- mysql报Fatal error encountered during command execution的解决办法
- Redis消息队列
- Redis client Python usage
- Oracle数据迁移至HBase操作记录
- Oracle数据迁移至HBase操作记录
- 数据库优化---索引设计
- centos下 redis安装配置及简单测试
- 初学数据库,不喜勿喷,如果有错请提出
- 在SQL server中设置表的自动编号功能
- oracle中实现截取字符串(substr)、查找字符串位置(instr)、替换字符串(replace)