Преглед изворни кода

增加检查表是否存在

Pen Li пре 9 година
родитељ
комит
a99db39ead

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 12 - 2
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -1001,8 +1001,18 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     if (rename) {
         
-        NSString *rename_model_to_product = [NSString stringWithFormat:@"alter %@ rename to %@;",table,column_str_or_new_table_name];
-        [self execSql:rename_model_to_product db:db];
+        NSString *check_table_exist = [NSString stringWithFormat:@"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='%@';",column_str_or_new_table_name];
+        __block BOOL exist = NO;
+        [self jk_query:check_table_exist db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+            
+            int ct = sqlite3_column_int(stmt, 0);
+            exist = ct ? YES : 0;
+        }];
+        
+        if (!exist) {
+            NSString *rename_model_to_product = [NSString stringWithFormat:@"alter %@ rename to %@;",table,column_str_or_new_table_name];
+            [self execSql:rename_model_to_product db:db];
+        }
         
     } else {