标题:
简单易用的iOS数据库操作框架(2)
[打印本页]
作者:
look_w
时间:
2019-2-18 20:36
标题:
简单易用的iOS数据库操作框架(2)
创建和数据库
[[JCDBManager sharedManager] createWithDBName
"testDB.sqlite"];
关闭数据库
[[JCDBManager sharedManager] closeDB];
创建表
[JCTestRecord createTable];
添加表字段
[JCTestRecord alterTableWithColumn
"testUnsignedLongLongInt"];
删除表
[JCTestRecord dropTable];
插入或替代当前记录
JCTestRecord *record = [[JCTestRecord alloc] init];
record.testPrimaryKey = [NSString stringWithFormat
"primaryKeyProperty%@", @(index + 1)];
record.testIgnore = @"ignoreProperty";
record.testMutableString = [[NSMutableString alloc] initWithString
"mutableStringProperty"];
record.testNumber = @(6.20);
record.testDecimalNumber = [[NSDecimalNumber alloc] initWithString
"2016"];
record.testDate = [NSDate date];
record.testData = [@"dataProperty" dataUsingEncoding:NSUTF8StringEncoding];
record.testMutableData = [NSMutableData dataWithData:[@"mutableDataProperty" dataUsingEncoding:NSUTF8StringEncoding]];
record.testBOOL = YES;
record.testShort = 6;
record.testInt = 20;
record.testLong = 20160620;
record.testInteger = index + 1;
record.testEnumType = (index + 1) % 3;
record.testInt64 = (index + 1)*24*3600;
record.testUInteger = 201606;
record.testFloat = 10.5;
record.testCGFloat = 1.26;
record.testDouble = 10.52;
record.testTimeInterval = 978307200.0;
record.testLongInt = 10000010;
record.testLongLongInt = 1000000110;
record.testUnsignedLongLongInt = 100000000111;
BOOL result = [record updateRecord];
更新当前记录字段值
result = [record updateRecordColumns
[@"testBOOL", @"testDate", @"testNumber"]
values
[@(NO), [NSDate dateWithTimeIntervalSince1970:9], @(6.22)]];
删除当前记录
result = [record deleteRecord];
查询记录
JCTestRecord *record = [JCTestRecord queryRecordWithPrimaryKeyValue
"primaryKeyProperty2"];
NSArray *queryRecords = [JCTestRecord queryRecordsWithConditions
{@"testEnumType"
(JCTestEnumTypeTwo)}];
queryRecords = [JCTestRecord queryRecordsWithConditionalExpression:@"WHERE testEnumType < ?"
arguments:@[@(JCTestEnumTypeTwo)]];
queryRecords = [JCTestRecord queryRecordsWithConditionalExpression:@"ORDER BY testEnumType DESC"
arguments:nil];
queryRecords = [JCTestRecord queryAllRecords];
查询记录的相关字段
NSArray *queryColumns = [JCTestRecord queryColumns:@[@"testPrimaryKey", @"testDate"]
conditionalExpression:@"WHERE testEnumType < ? ORDER BY testInteger DESC"
arguments:@[@(JCTestEnumTypeOne)]];
查询表中记录条数
uint64_t count = [JCTestRecord countRecordsWithConditions:@{@"testEnumType":@(JCTestEnumTypeTwo)}];
count = [JCTestRecord countRecordsWithConditionalExpression:@"WHERE testEnumType < ?"
arguments:@[@(JCTestEnumTypeOne)]];
count = [JCTestRecord countAllRecords];
删除记录
BOOL result = [JCTestRecord deleteRecordsWithConditions:@{@"testEnumType":@(JCTestEnumTypeTwo)}];
result = [JCTestRecord deleteRecordsWithConditionalExpression:@"WHERE testEnumType < ?"
arguments:@[@(JCTestEnumTypeOne)]];
result = [JCTestRecord deleteAllRecords];
以上就是该框架现有的内容,支持sqlite大部分的增删改查操作,对于可能出现的其他需求,还需要大家一起添砖加瓦。
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0