每天都写点东西出来 -- 第 10 天

简述:这是一个 iOS 的 Sqlite 数据库的查询组件。比较简洁,而且只关注查询部分。


根据查询时指定要获取的类型得到指定的数据格式,本组件共提供四种结果类型。


idname
0A
1B


dictionary结果类型

{
    id = (0,1);
    name = (A,B)
}

array结果类型

(
    (0,1),
    (A,B)
)

arrayDictionary结果类型

(
    {
        id = 0;
        name = A;
    },
    {
        id = 1;
        name = B;
    }
)


arrayArray结果类型

(
    (0,A),
    (1,B)
)



dictionary、array、arrayDictionary、arrayArray 该四种结果类型可以相互转换。




代码如下:

//
//  MZCQuery.h
//  MZCKit
//
//  Created by yococo on 15/11/14.
//  Copyright (c) 2015年 yococo. All rights reserved.
//

#import <Foundation/Foundation.h>

#import <sqlite3.h>

#import "MZCQueryResult.h"

@interface MZCQuery : NSObject

@property(nonatomic,readonly) NSString* path;


+ (instancetype) defaultQuery;

+ (instancetype) defaultQueryWithPath:(NSString*) path;

- (instancetype) initWithPath:(NSString*) path;



#pragma mark -
- (MZCQueryResult*) queryResultWithSQl:(NSString*) sql Type:(MZCQueryResultType) type;

/*
 type 默认为 MZCQueryResultTypeArrayDictionary.
 */
- (MZCQueryResult*) queryResultWithSQl:(NSString*) sql;

@end


//
//  MZCQueryResult.h
//  MZCKit
//
//  Created by yococo on 15/11/14.
//  Copyright (c) 2015年 yococo. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, MZCQueryResultType) {
    MZCQueryResultTypeDictionary,
    MZCQueryResultTypeArray,
    MZCQueryResultTypeArrayDictionary,
    MZCQueryResultTypeArrayArray,
};

@interface MZCQueryResult : NSObject

@property(nonatomic,readonly) MZCQueryResultType type;

@property(nonatomic,readonly) NSArray* fields;

@property(nonatomic,readonly) id result;


#pragma mark -
- (instancetype) initWithType:(MZCQueryResultType)type fields:(NSArray*)fields result:(id)result;


#pragma mark - 转换
//将对象 转换成 另一个类型的对象
- (MZCQueryResult*) resultByConvertToType:(MZCQueryResultType) type;

//将对象的结果 转换成 另一个类型的结果
- (id) convertToType:(MZCQueryResultType) type;

@end




















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值