SQLite


SQLite 은 HSP 에서 기본으로 제공하는 API로 별도의 설정 없이 사용 가능하다.
SQLite 은 iOS 내부에서 제공하는 SQLite 을 제어할 수 있는 기능을 제공하며 Optional 한 기능이므로 사용자가 별도로 개발하여 사용해도 무방하다. 


open

open 은 디비 파일을 연다. 

Example

///////////////
// 3.10.18 이상
///////////////
let sqlite = DAPSqlite()
let param = DAPSqliteOpenParam()
param.dbName = "hone.sqlite"
sqlite.execute(with: param, completion: { (dict) in
   
}) { (resultError) in
   
}


///////////////
// 3.10.18 이하
///////////////
let sqlite = DAPSqlite()
let params = ["hone.sqlite"] as [Any]
sqlite.execute(withActionName: "open", params: params, completion: { (dict) in
   guard let resultDict = dict else {
       return
    }

}) { (resultError) in
   guard let error = resultError else {
       return
    }
}

///////////////
// 3.10.18 이상
///////////////
DAPSqlite *deviceAPI = [DAPSqlite new];
DAPSqliteOpenParam *infoParam = [DAPSqliteOpenParam new];
infoParam.dbName = @"hone.sqlite";
[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
} failure:^(NSError *error) {
}];

///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPSqlite new];
NSArray *params = [NSArray arrayWithObjects:@"hone.sqlite", nil];
[deviceAPI executeWithActionName:@"open" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

close

close 은 디비 파일을 닫는다. 

Example

///////////////
// 3.10.18 이상
///////////////
let sqlite = DAPSqlite()
let param = DAPSqliteCloseParam()
param.dbName = "hone.sqlite"
sqlite.execute(with: param, completion: { (dict) in
   
}) { (resultError) in
   
}


///////////////
// 3.10.18 이하
///////////////
let sqlite = DAPSqlite()
let params = ["hone.sqlite"] as [Any]
sqlite.execute(withActionName: "close", params: params, completion: { (dict) in
   guard let resultDict = dict else {
       return
    }

}) { (resultError) in
   guard let error = resultError else {
       return
    }
}

///////////////
// 3.10.18 이상
///////////////
DAPSqlite *deviceAPI = [DAPSqlite new];
DAPSqliteCloseParam *infoParam = [DAPSqliteCloseParam new];
infoParam.dbName = @"hone.sqlite";
[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
} failure:^(NSError *error) {
}];


///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPSqlite new];
NSArray *params = [NSArray arrayWithObjects:@"hone.sqlite", nil];
[deviceAPI executeWithActionName:@"close" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

executePragmaStatement

executePragmaStatement 은 디비에 쿼리를 실행한다.

Example

///////////////
// 3.10.18 이상
///////////////
let sqlite = DAPSqlite()
let param = DAPSqliteExecutePragmaStatementParam()
param.dbName = "hone.sqlite"
param.query = "INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')"
sqlite.execute(with: param, completion: { (dict) in
   
}) { (resultError) in
   
}


///////////////
// 3.10.18 이하
///////////////
let sqlite = DAPSqlite()
let params = ["hone.sqlite", "INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')"] as [Any]
sqlite.execute(withActionName: "executePragmaStatement", params: params, completion: { (dict) in
   guard let resultDict = dict else {
       return
    }

}) { (resultError) in
   guard let error = resultError else {
       return
    }
}
///////////////
// 3.10.18 이상
///////////////
DAPSqlite *deviceAPI = [DAPSqlite new];
DAPSqliteExecutePragmaStatementParam *infoParam = [DAPSqliteExecutePragmaStatementParam new];
infoParam.dbName = @"hone.sqlite";
infoParam.query = @"INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')";
[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
} failure:^(NSError *error) {
}];


///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPSqlite new];
NSArray *params = [NSArray arrayWithObjects:@"hone.sqlite", @"INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')", nil];
[deviceAPI executeWithActionName:@"executePragmaStatement" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

executeSqlBatch

executeSqlBatch 은 디비에 여러개의 쿼리를 실행한다.

Example

///////////////
// 3.10.18 이상
///////////////
let sqlite = DAPSqlite()
let param = DAPSqliteExecuteSqlBatchParam()
param.dbName = "hone.sqlite"
param.queries = ["INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')", "INSERT INTO test ('_id', 'text') VALUES (2, 'TEST')", "INSERT INTO test ('_id', 'text') VALUES (3, 'TEST')"]
sqlite.execute(with: param, completion: { (dict) in
   
}) { (resultError) in
   
}


///////////////
// 3.10.18 이하
///////////////
let sqlite = DAPSqlite()
let batchs = ["INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')", "INSERT INTO test ('_id', 'text') VALUES (2, 'TEST')", "INSERT INTO test ('_id', 'text') VALUES (3, 'TEST')"]
let params = ["hone.sqlite", batchs] as [Any]
sqlite.execute(withActionName: "executePragmaStatement", params: params, completion: { (dict) in
   guard let resultDict = dict else {
       return
    }

}) { (resultError) in
   guard let error = resultError else {
       return
    }
}
///////////////
// 3.10.18 이상
///////////////
DAPSqlite *deviceAPI = [DAPSqlite new];
DAPSqliteExecuteSqlBatchParam *infoParam = [DAPSqliteExecuteSqlBatchParam new];
infoParam.dbName = @"hone.sqlite";
infoParam.queries = [NSArray arrayWithObjects:
                 @"INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')",
                 @"INSERT INTO test ('_id', 'text') VALUES (2, 'TEST')",
                 @"INSERT INTO test ('_id', 'text') VALUES (3, 'TEST')",
                 nil];

[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
} failure:^(NSError *error) {
}];



///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPSqlite new];
NSArray *batch = [NSArray arrayWithObjects:
                 @"INSERT INTO test ('_id', 'text') VALUES (1, 'TEST')",
                 @"INSERT INTO test ('_id', 'text') VALUES (2, 'TEST')",
                 @"INSERT INTO test ('_id', 'text') VALUES (3, 'TEST')",
                 nil];
NSArray *params = [NSArray arrayWithObjects:@"hone.sqlite", batch, nil];
[deviceAPI executeWithActionName:@"executeSqlBatch" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];