第三方FMDB的简单使用
2016-09-13 13:33
357 查看
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];
}
#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];
}
相关文章推荐
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- 使用FMDB第三方写简单的demo
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- sqlite第三方类库:FMDB使用(转载)
- sqlite第三方类库:FMDB使用
- IOS第三方数据库FMDatabase的简单使用
- iOS关于数据库的操作(使用第三方类库FMDB)
- IOS数据持久化存储之SQLite3第三方库FMDB的使用
- phone开发中第三方框架SDWebImage的简单使用
- 数据持久化(三)使用第三方类库FMDB
- iOS关于数据库的操作(使用第三方类库FMDB)
- iOS关于SQLite数据库的操作(使用第三方类库FMDB)
- Sqlite第三方类库:FMDB使用
- sqlite第三方类库:FMDB使用(转载)
- iOS开发之Sqlite 第三方库FMDB的使用
- iOS 第三方类库FMDB的使用
- fmdb 使用简单教程
- ios数据存储中关于Sqlite3使用第三方框架FMDB