//
// ViewController.m
// UI-NO-17
//
// Created by Bruce on 15/8/12.
// Copyright (c) 2015年 Bruce. All rights reserved.
//
#import "ViewController.h"
#import "DataManager.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
DataManager *manager = [DataManager shareManager];
BOOL success = [manager createTableWithSql:@"create table if not exists user (id integer primary key autoincrement, name text not null unique, phone text, creatDate text);"];
if (success) {
NSLog(@"建表 成功 !!!!!!!!");
}
// 插入数据 sql公式:
// insert into 表名 (字段,字段,字段) values ('值','值','值');
NSString *name = @"葫儿子";
NSString *tel = @"18798763333";
NSString *date = @"2018-12-12";
NSString *sql = [NSString stringWithFormat:@"insert into user (name, phone,creatDate) values ('%@','%@','%@');",name,tel,date];
if ([manager insertMessageWithSql:sql] == YES) {
NSLog(@"插入数据成功");
}
// 删除SQL语句的公式:
// delete from 表名 where 字段 = '值';
if ([manager deleteMessageWithSql:@"delete from user where name = '葫芦娃';"]==YES) {
NSLog(@"删除数据成功");
}
// 更新数据公式:
// update 表名 set 字段 = '新值' where 字段 = '旧值';
if ([manager modifyMessageWithSql:@"update user set name = '孙悟空' where name = '葫娃';"]==YES) {
NSLog(@"修改数据成功");
}
// 查询数据
NSArray *list = [manager queryMessageWithSQL:@"select id,name,phone,creatDate from user where name like ?;" andObject:@"葫"];
if (list.count != 0) {
NSLog(@"%@",list);
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end