iSalesDB+JKDB.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // iSalesDB+JKDB.m
  3. // iSales-NPD
  4. //
  5. // Created by Jack on 8/3/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "iSalesDB+JKDB.h"
  9. @implementation iSalesDB (JKDB)
  10. + (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block {
  11. __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  12. sqlite3 *db = [iSalesDB get_db];
  13. NSString *sqlQuery = sql;
  14. sqlite3_stmt * statement;
  15. if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
  16. long count = 0;
  17. while (sqlite3_step(statement) == SQLITE_ROW) {
  18. block(statement,dic,&count);
  19. }
  20. sqlite3_finalize(statement);
  21. }
  22. sqlite3_close(db);
  23. return [dic copy];
  24. }
  25. + (int)jk_execSql:(NSString *)sql withDatabase:(BOOL)database {
  26. int flag = RESULT_TRUE;
  27. if (database) {
  28. sqlite3 *db = [self get_db];
  29. if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, nil) != SQLITE_OK) {
  30. flag = RESULT_FALSE;
  31. }
  32. }
  33. return flag;
  34. }
  35. @end