|
@@ -350,4 +350,170 @@
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
++ (NSString *)prepareUploadSQLOfUser:(NSString *)user withDiviceID:(NSString *)deviceID {
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableString *sqlStr = [NSMutableString string];
|
|
|
|
|
+ sqlite3 *db = [self get_db];
|
|
|
|
|
+
|
|
|
|
|
+ // favorites
|
|
|
|
|
+ NSString *favorites_sql = [NSString stringWithFormat:@"select ifnull(name,''), ifnull(params, ''), ifnull(action, ''), ifnull(module_name, ''), ifnull(user, ''), ifnull(create_time, '') from favorites where user = '%@';", user];
|
|
|
|
|
+ sqlite3_stmt *favorites_statment;
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, favorites_sql.UTF8String, -1, &favorites_statment, NULL) == SQLITE_OK) {
|
|
|
|
|
+ while (sqlite3_step(favorites_statment) == SQLITE_ROW) {
|
|
|
|
|
+
|
|
|
|
|
+ char *ch_name = (char *)sqlite3_column_text(favorites_statment, 0);
|
|
|
|
|
+ char *ch_params = (char *)sqlite3_column_text(favorites_statment, 1);
|
|
|
|
|
+ char *ch_action = (char *)sqlite3_column_text(favorites_statment, 2);
|
|
|
|
|
+ char *ch_module_name = (char *)sqlite3_column_text(favorites_statment, 3);
|
|
|
|
|
+ char *ch_user = (char *)sqlite3_column_text(favorites_statment, 4);
|
|
|
|
|
+ char *ch_create_time = (char *)sqlite3_column_text(favorites_statment, 5);
|
|
|
|
|
+
|
|
|
|
|
+ NSString *str_name = [NSString stringWithUTF8String:ch_name];
|
|
|
|
|
+ NSString *str_params = [NSString stringWithUTF8String:ch_params];
|
|
|
|
|
+ NSString *str_action = [NSString stringWithUTF8String:ch_action];
|
|
|
|
|
+ NSString *str_module_name = [NSString stringWithUTF8String:ch_module_name];
|
|
|
|
|
+ NSString *str_user = [NSString stringWithUTF8String:ch_user];
|
|
|
|
|
+ NSString *str_create_time = [NSString stringWithUTF8String:ch_create_time];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *insert_sql = [NSString stringWithFormat:@"insert into favorites (name, params, action, module_name, user_name, device_id, create_time) values ('%@', '%@', '%@', '%@', '%@', '%@', '%@');", str_name, str_params, str_action, str_module_name, str_user, deviceID, str_create_time];
|
|
|
|
|
+ [sqlStr appendString:insert_sql];
|
|
|
|
|
+ [sqlStr appendString:@"\r\n"];
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlite3_finalize(favorites_statment);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // fields_info
|
|
|
|
|
+ NSString *fieldsSql = [NSString stringWithFormat:@"select ifnull(name, ''), ifnull(aname, ''), ifnull(field_type, 0), ifnull(function_name, ''), ifnull(behavior, 0), ifnull(priority, 0), ifnull(show, 0), ifnull(user, '') from fields_info where user = '%@';",user];
|
|
|
|
|
+ sqlite3_stmt *fields_statment;
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, fieldsSql.UTF8String, -1, &fields_statment, NULL) == SQLITE_OK) {
|
|
|
|
|
+ while (sqlite3_step(fields_statment) == SQLITE_ROW) {
|
|
|
|
|
+
|
|
|
|
|
+ char *ch_name = (char *)sqlite3_column_text(fields_statment, 0);
|
|
|
|
|
+ char *ch_aname = (char *)sqlite3_column_text(fields_statment, 1);
|
|
|
|
|
+ int field_type = sqlite3_column_int(fields_statment, 2);
|
|
|
|
|
+ char *ch_function_name = (char *)sqlite3_column_text(fields_statment, 3);
|
|
|
|
|
+ int behavior = sqlite3_column_int(fields_statment, 4);
|
|
|
|
|
+ int priority = sqlite3_column_int(fields_statment, 5);
|
|
|
|
|
+ int show = sqlite3_column_int(fields_statment, 6);
|
|
|
|
|
+ char *ch_user = (char *)sqlite3_column_text(fields_statment, 7);
|
|
|
|
|
+
|
|
|
|
|
+ NSString *str_name = [NSString stringWithUTF8String:ch_name];
|
|
|
|
|
+ NSString *str_aname = [NSString stringWithUTF8String:ch_aname];
|
|
|
|
|
+ NSString *str_function_name = [NSString stringWithUTF8String:ch_function_name];
|
|
|
|
|
+ NSString *str_user = [NSString stringWithUTF8String:ch_user];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *insert_sql = [NSString stringWithFormat:@"insert into fields_info (name, aname, field_type, function_name, behavior, priority, show, user_name, device_id) values ('%@', '%@', %d, '%@', %d, %d, %d, '%@', '%@');", str_name, str_aname, field_type, str_function_name, behavior, priority, show, str_user, deviceID];
|
|
|
|
|
+ [sqlStr appendString:insert_sql];
|
|
|
|
|
+ [sqlStr appendString:@"\r\n"];
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlite3_finalize(fields_statment);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // history
|
|
|
|
|
+ NSString *historySql = [NSString stringWithFormat:@"select ifnull(name, ''), ifnull(params, ''), ifnull(action, ''), ifnull(module_name, ''), ifnull(user, ''), ifnull(create_time, '') from history where user = '%@';",user];
|
|
|
|
|
+ sqlite3_stmt *history_statment;
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, historySql.UTF8String, -1, &history_statment, NULL) == SQLITE_OK) {
|
|
|
|
|
+ while (sqlite3_step(history_statment) == SQLITE_ROW) {
|
|
|
|
|
+ char *ch_name = (char *)sqlite3_column_text(history_statment, 0);
|
|
|
|
|
+ char *ch_params = (char *)sqlite3_column_text(history_statment, 1);
|
|
|
|
|
+ char *ch_action = (char *)sqlite3_column_text(history_statment, 2);
|
|
|
|
|
+ char *ch_module_name = (char *)sqlite3_column_text(history_statment, 3);
|
|
|
|
|
+ char *ch_user = (char *)sqlite3_column_text(history_statment, 4);
|
|
|
|
|
+ char *ch_create_time = (char *)sqlite3_column_text(history_statment, 5);
|
|
|
|
|
+
|
|
|
|
|
+ NSString *str_name = [NSString stringWithUTF8String:ch_name];
|
|
|
|
|
+ NSString *str_params = [NSString stringWithUTF8String:ch_params];
|
|
|
|
|
+ NSString *str_action = [NSString stringWithUTF8String:ch_action];
|
|
|
|
|
+ NSString *str_module_name = [NSString stringWithUTF8String:ch_module_name];
|
|
|
|
|
+ NSString *str_user = [NSString stringWithUTF8String:ch_user];
|
|
|
|
|
+ NSString *str_create_time = [NSString stringWithUTF8String:ch_create_time];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *insert_sql = [NSString stringWithFormat:@"insert into history (name, params, action, module_name, user_name, device_id, create_time) values ('%@', '%@', '%@', '%@', '%@', '%@', '%@');", str_name, str_params, str_action, str_module_name, str_user, deviceID, str_create_time];
|
|
|
|
|
+ [sqlStr appendString:insert_sql];
|
|
|
|
|
+ [sqlStr appendString:@"\r\n"];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_finalize(history_statment);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // search history
|
|
|
|
|
+ NSString *searchHistorySql = [NSString stringWithFormat:@"select ifnull(h_val, ''), ifnull(h_field, ''), ifnull(level, 0), ifnull(user, ''), ifnull(h_time, '') from search_history where user = '%@';",user];
|
|
|
|
|
+ sqlite3_stmt *search_history_statment;
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, searchHistorySql.UTF8String, -1, &search_history_statment, NULL) == SQLITE_OK) {
|
|
|
|
|
+ while (sqlite3_step(search_history_statment) == SQLITE_ROW) {
|
|
|
|
|
+ char *ch_val = (char *)sqlite3_column_text(search_history_statment, 0);
|
|
|
|
|
+ char *ch_field = (char *)sqlite3_column_text(search_history_statment, 1);
|
|
|
|
|
+ int level = sqlite3_column_int(search_history_statment, 2);
|
|
|
|
|
+ char *ch_user = (char *)sqlite3_column_text(search_history_statment, 3);
|
|
|
|
|
+ char *ch_time = (char *)sqlite3_column_text(search_history_statment, 4);
|
|
|
|
|
+
|
|
|
|
|
+ NSString *str_val = [NSString stringWithUTF8String:ch_val];
|
|
|
|
|
+ NSString *str_field = [NSString stringWithUTF8String:ch_field];
|
|
|
|
|
+ NSString *str_user = [NSString stringWithUTF8String:ch_user];
|
|
|
|
|
+ NSString *str_time = [NSString stringWithUTF8String:ch_time];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *insert_sql = [NSString stringWithFormat:@"insert into search_history (h_val, h_field, level, user_name, device_id, h_time) values ('%@', '%@', %d, '%@', '%@', '%@');",str_val, str_field, level, str_user, deviceID, str_time];
|
|
|
|
|
+ [sqlStr appendString:insert_sql];
|
|
|
|
|
+ [sqlStr appendString:@"\r\n"];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_finalize(search_history_statment);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_close(db);
|
|
|
|
|
+
|
|
|
|
|
+ return sqlStr.copy;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++ (BOOL)hasDatabaseFile {
|
|
|
|
|
+
|
|
|
|
|
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+ NSString *documents = [paths objectAtIndex:0];
|
|
|
|
|
+ NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
+
|
|
|
|
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:database_path]) {
|
|
|
|
|
+ return YES;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return NO;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++ (BOOL)isCachedDataForUser:(NSString *)user {
|
|
|
|
|
+
|
|
|
|
|
+ BOOL hasDatabase = [self hasDatabaseFile];
|
|
|
|
|
+ if (!hasDatabase) {
|
|
|
|
|
+ return NO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ __block BOOL result = NO;
|
|
|
|
|
+
|
|
|
|
|
+ NSString *has_sql = [NSString stringWithFormat:@"select count(0) from (select user from favorites union all select user from fields_info union all select user from history union all select user from search_history) where user = '%@';", user];
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_stmt * statement;
|
|
|
|
|
+ sqlite3 *db = [self get_db];
|
|
|
|
|
+
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, [has_sql UTF8String], -1, &statement, nil) == SQLITE_OK) {
|
|
|
|
|
+
|
|
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW) {
|
|
|
|
|
+ int c = sqlite3_column_int(statement, 0);
|
|
|
|
|
+ result = c > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_finalize(statement);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ DebugLog(@"excute sql:%@ error: %s",sql,sqlite3_errmsg(db));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_close(db);
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
++ (void)cleanCacheDataForUser:(NSString *)user {
|
|
|
|
|
+ NSString *sql = [NSString stringWithFormat:@"delete from favorites where user = '%@';delete from fields_info where user = '%@';delete from history where user = '%@';delete from search_history where user = '%@';",user,user,user,user];
|
|
|
|
|
+ [self jk_excute:sql completion:^(BOOL success) {
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|