Просмотр исходного кода

160810
modify offline import sql, rollback if execute return wrong.

Ray Zhang 9 лет назад
Родитель
Сommit
4241d2f5e8
1 измененных файлов с 31 добавлено и 1 удалено
  1. 31 1
      RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

+ 31 - 1
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -1533,7 +1533,17 @@
                             NSString* sql = [NSString stringWithContentsOfFile:sqlpath encoding:NSUTF8StringEncoding error:&error];
                             //NSLog(@"NSString类方法读取的内容是:\n%@",content);
                             
-                            sqlite3_exec(tdb, [sql UTF8String], NULL, NULL, &errmsg);
+                            
+                            
+                            
+                            if(sqlite3_exec(tdb, [sql UTF8String], NULL, NULL, &errmsg)!=SQLITE_OK)
+                            {
+                                //throw exception;
+                                if(errmsg==nil)
+                                    errmsg="Unknown error.";
+                                NSString *nsmsg = [[NSString alloc]initWithUTF8String:errmsg];
+                                [NSException raise:@"offline update sql error" format:@"MSG:%@",nsmsg];
+                            }
                             
                             sqlite3_free(errmsg);
                         }
@@ -1556,16 +1566,36 @@
                 
                 @catch (NSException *exception) {
                     char *errmsg=NULL;
+                    [self add_downloadlog:[NSString stringWithFormat:@"updating local database error, %@",exception.description]];
                     [self add_downloadlog:@"updating local database failed rollback..."];
                     if (sqlite3_exec(tdb, "rollback", NULL, NULL, &errmsg)==SQLITE_OK) {
                         NSLog(@"回滚事务");
                         
+                        
+                        
+                        
+                        
 
                     }
                     else
                     {
                         [self add_downloadlog:@"rollback failed."];
                     }
+                    
+                    
+                    NSMutableDictionary* currenttask=[self.download_task [[NSString stringWithFormat:@"item_%d",self.current_task]] mutableCopy];
+                    currenttask[@"status"] = @"pause";
+                    //int retry=[self.download_task [[NSString stringWithFormat:@"item_%d",self.current_task]][@"retry"] intValue];
+                    currenttask[@"retry"]= [NSNumber numberWithInt:DOWNLOAD_RETRY_TIMES];
+                    self.download_task [[NSString stringWithFormat:@"item_%d",self.current_task]]=currenttask;
+                    
+                    //    self.currentLength = 0;
+                    //    self.fileLength = 0;
+                    [self.fileHandle closeFile];
+                    self.fileHandle = nil;
+                    [self.connection cancel];
+                    self.connection = nil;
+                    //break;
                 }
                 @finally {