//
//  iSalesDB.h
//  RedAnt ERP Mobile
//
//  Created by Ray on 14-6-24.
//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "const.h"
#import <sqlite3.h>  
#import "config.h"

typedef void(^queryBlock)(sqlite3_stmt *stmt,NSMutableDictionary *container,long *count);
typedef void(^failureBlock)(NSMutableDictionary *container,NSString *err_msg);

@interface iSalesDB : NSObject


//+(void)testdata;
+ (int) initializeDb;
+(int)execSql:(NSString *)sql db:(sqlite3 *)db;
+(int)execSql:(NSString *)sql;
+ (sqlite3*) get_db;
+ (void) close_db:(sqlite3 *)db;
//+ (sqlite3*) get_rawdb;
+ (int) get_recordid:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby;
+ (int) get_recordid:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause;

+ (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause;
+ (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby;
+ (int) get_insertid:(NSString*) tablename db:(sqlite3*)db;



+ (void) save_pdf: (NSString*) temp_path filename:(NSString*) filename;


+ (int) get_recordcount:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause;

+ (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path;
+ (void) cache_img: (NSData*) imgData filename:(NSString*) name saveTo:(NSString*) path;


+ (NSDictionary*) search_pdf:(int) offset limit:(int)limit keywords:(NSString*) keywords;
+(NSArray*) get_saveduser;

+ (sqlite3*) get_db_at:(NSString* )path;
//+(int) AddExFunction:(sqlite3 *) db;

#pragma mark - JK

+ (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block;

+ (NSDictionary *)jk_query:(NSString *)sql db:(sqlite3 *)db close:(BOOL)close completion:(queryBlock)block;

+ (NSDictionary *)jk_query:(NSString *)sql completion:(queryBlock)block failure:(failureBlock)failure;

+ (NSString *)jk_queryText:(NSString *)sql;

@end
