| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // FavoritesData.m
- // Apex Mobile
- //
- // Created by Ray on 14-4-25.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "FavoritesData.h"
- @implementation FavoritesData
- -(long) get_count
- {
- return self.pagedata.count;
- }
- - (id)init
- {
- self = [super init];
- if (self) {
- self.pagedata =[[NSMutableArray alloc]init];
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- // NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
- //
- // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
- // appDelegate.user = user;
- // appDelegate.password = password;
-
- sqlite3 *db =[ApexMobileDB get_db];
- NSString *quary = [NSString stringWithFormat:@"select _id,create_time,params,module_name,action,name from favorites where user='%@' order by _id desc",appDelegate.user];
-
-
-
- sqlite3_stmt *stmt;
- if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
- DebugLog(@"sql:%@",quary);
- while (sqlite3_step(stmt)==SQLITE_ROW)
- {
- // NSString *aname = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
- int _id = sqlite3_column_int(stmt, 0);
- // NSString* str_time = sqlite3
- NSString* create_time = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
- NSString* params =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 2)];
- NSString* module_name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 3)];
- NSString* action =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 4)];
- NSString* name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 5)];
- NSMutableDictionary * map = [[NSMutableDictionary alloc] init];
- [map setValue:[NSString stringWithFormat:@"%d",_id] forKey:@"_id"];
- [map setValue:[NSString stringWithFormat:create_time,create_time] forKey:@"create_time"];
- [map setValue:params forKey:@"params"];
- [map setValue:module_name forKey:@"module_name"];
- [map setValue:name forKey:@"name"];
- [map setValue:action forKey:@"action"];
-
- [self.pagedata addObject:map];
-
-
- }
-
- sqlite3_finalize(stmt);
- }
- //用完了一定记得关闭,释放内存
- sqlite3_close(db);
-
- }
- return self;
- }
- - (void)deleteAll:(void(^)(BOOL))complete {
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- NSString *sql = [NSString stringWithFormat:@"delete from favorites where user='%@';",appDelegate.user];
- __weak typeof(self) weakSelf = self;
- [ApexMobileDB jk_excute:sql completion:^(BOOL success) {
- if (success) {
- [weakSelf.pagedata removeAllObjects];
- }
- if (complete) {
- complete(success);
- }
- }];
-
- }
- @end
|