第三方FMDB的简单使用
1,导入第三方头文件
#import "FMDB.h"
//定义全局变量
@implementation InputInformationViewController
{
UITextField *_accountField;//帐号输入框
UITextField *_passwordsField;//密码输入框
FMDatabase *db;//数据库
}
//获取数据库
NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask , YES) lastObject];
NSLog(@"%@",doc);
NSString *fileName = [doc stringByAppendingPathComponent:@"information.sqlite"];
//获取数据库
db = [FMDatabase databaseWithPath:fileName];
if ([db open]) {
//创表
BOOL result = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS M_Information (id integer PRIMARY KEY AUTOINCREMENT, account NOT NULL,passwords text NOT NULL);"];
if (result) {
NSLog(@"创表成功");
}else{
NSLog(@"创表失败");
}
}
//获取数据
NSString *account = _accountField.text;
NSString *passwords = _passwordsField.text;
if([db executeUpdate:@"INSERT INTO M_Information(account,passwords) VALUES(?,?);",account,passwords]){
NSLog(@"111");
};
//[db executeQueryWithFormat:@"INSERT INTO M_Information(account,passwords)VALUES(%@,%@);",account,passwords];
[self query];//执行查询语句
//查询语句函数
ViewController *VC = [[ViewController alloc]init];
VC.dataArray = [[NSMutableArray alloc]init];
//执行查询语句
FMResultSet *resultSet = [db executeQuery:@"SELECT * FROM M_Information"];
//遍历结果集
while ([resultSet next]) {
//传递数据库中的数据
InformationModel *model = [[InformationModel alloc]init];
model.myAccount = [resultSet stringForColumn:@"account"];
model.myPasswords = [resultSet stringForColumn:@"passwords"];
[VC.dataArray addObject:model];
}
最新文章
- 【C#】ConcurrentBag<;T>; 方法
- 数据流 in redux
- 访问ControlTemplate内部的元素
- android系统360浏览器使用append动态添加元素出现黑色错乱背景
- 微软分布式缓存 appfabric
- 当在浏览器地址栏里输入URL后会发生什么事情
- Java 8 新特性1-函数式接口
- JAVA入门[7]-Mybatis generator(MBG)自动生成mybatis代码
- HibernateTemplate#setMaxResults()的坑
- java I/O框架 (三)基本流
- Kali Linux入坑之基本配置(2018.1)
- 用python爬取杭电oj的数据
- 微信小程序手机预览请求不到数据(最后一条不明所以)
- Linux 系统安全设置
- Flutter - AAPT: error: resource android:attr/dialogCornerRadius not found.
- springMVC学习三 注解开发环境搭建
- Haskell语言学习笔记(42)Bifunctor
- Retrofit源码解析(下)
- php 返回上一页并刷新
- MySQL Innodb 神秘消失