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

160805
change db journal to wal
add db connection monitor.
Change reset icon

Ray Zhang пре 9 година
родитељ
комит
c2f927f1c2

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


Разлика између датотеке није приказан због своје велике величине
+ 203 - 203
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist


+ 1 - 1
RedAnt ERP Mobile/common/Functions/cart/CartViewController.m

@@ -2088,7 +2088,7 @@ commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  forRowAtIndexPath:
     //    sqlite3* db = [ApexMobileDB get_db];
     //    NSString* sql = [NSString stringWithFormat:@"delete from history where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
     //    [ApexMobileDB execSql:sql db:db];
-    //    sqlite3_close(db);
+    //    [iSalesDB close_db:db];
     //
     //    [self.data.pagedata removeObjectAtIndex:indexPath.row];
     //

+ 39 - 38
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -33,7 +33,8 @@
     }
     return true;
     //
-    sqlite3_close(db);
+    //[iSalesDB close_db:db];
+    [iSalesDB close_db:db];
 }
 +(NSDictionary*) offline_deletewishlist :(NSMutableDictionary *) params
 {
@@ -51,7 +52,7 @@
     NSString* sqlQuery = [NSString stringWithFormat:@"delete from wishlist where _id in (%@);",collectId];
     [iSalesDB execSql:sqlQuery];
     int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     appDelegate.wish_count =count;
     
@@ -84,7 +85,7 @@
         }
     }
     int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     appDelegate.wish_count =count;
     
@@ -174,7 +175,7 @@
         
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }
@@ -337,7 +338,7 @@
         
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }
@@ -401,7 +402,7 @@
         
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     if(dprice==DBL_MAX)
         ret= nil;
@@ -453,7 +454,7 @@
         
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
     
@@ -505,7 +506,7 @@
         
         if(contact_id.length<=0)
         {
-            sqlite3_close(db);
+            [iSalesDB close_db:db];
             return nil;
         }
         
@@ -543,7 +544,7 @@
         sqlite3_finalize(statement);
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
     
@@ -598,7 +599,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     DebugLog(@"data string: %@",ret );
     
     
@@ -653,7 +654,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     DebugLog(@"data string: %@",ret );
     
     
@@ -952,7 +953,7 @@
     NSLog(@"count:%d",count);
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
     
     return ret;
@@ -1050,7 +1051,7 @@
     NSLog(@"count:%d",count);
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     
@@ -1162,7 +1163,7 @@
     NSLog(@"count:%d",count);
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     
@@ -1306,7 +1307,7 @@
     NSLog(@"count:%d",count);
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     
@@ -1453,7 +1454,7 @@
     //
     //
     //
-    //    sqlite3_close(db);
+    //    [iSalesDB close_db:db];
     //
     //
     //
@@ -1566,7 +1567,7 @@
         
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return [RAUtils dict2data:ret];
 }
@@ -1684,7 +1685,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     
@@ -1982,7 +1983,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     
@@ -2041,7 +2042,7 @@
         //            sqlite3 *db = [self get_db];
         //
         //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
-        //            sqlite3_close(db);
+        //            [iSalesDB close_db:db];
         //        }
     }
     return ret;
@@ -2095,7 +2096,7 @@
         //            sqlite3 *db = [self get_db];
         //
         //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
-        //            sqlite3_close(db);
+        //            [iSalesDB close_db:db];
         //        }
     }
     
@@ -2401,7 +2402,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     
@@ -2483,7 +2484,7 @@
     NSLog(@"count:%d",count);
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     return ret;
@@ -2551,7 +2552,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }
@@ -2640,7 +2641,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }
@@ -2682,7 +2683,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }
@@ -2734,7 +2735,7 @@
     
     
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }
@@ -2784,7 +2785,7 @@
 //        sqlite3_finalize(statement);
 //    }
 //    
-//    sqlite3_close(db);
+//    [iSalesDB close_db:db];
 //    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
 //    return dic;
 
@@ -2847,7 +2848,7 @@
 //        sqlite3_finalize(statement);
 //    }
 //    
-//    sqlite3_close(db);
+//    [iSalesDB close_db:db];
 //    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
 //    return dic;
     
@@ -2910,7 +2911,7 @@
 //        sqlite3_finalize(statement);
 //    }
 //    
-//    sqlite3_close(db);
+//    [iSalesDB close_db:db];
 //    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
 //    return dic;
     
@@ -2967,7 +2968,7 @@
 //        sqlite3_finalize(statement);
 //    }
 //    
-//    sqlite3_close(db);
+//    [iSalesDB close_db:db];
 //    
 //    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
 //    
@@ -3028,7 +3029,7 @@
 //        
 //        sqlite3_finalize(statement);
 //    }
-//    sqlite3_close(db);
+//    [iSalesDB close_db:db];
 //    
 //    [dic setValue:[NSNumber numberWithInt:dic.allKeys.count] forKey:@"count"];
 //    
@@ -3078,7 +3079,7 @@
         
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
     
@@ -3099,7 +3100,7 @@
         
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }
@@ -3128,7 +3129,7 @@
 //        
 //        sqlite3_finalize(statement);
 //    }
-//    sqlite3_close(db);
+//    [iSalesDB close_db:db];
 //
 //    return dic;
     
@@ -3377,7 +3378,7 @@
         
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return name;
 }
@@ -3398,7 +3399,7 @@
         
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
 
     return ret;
 }
@@ -3419,7 +3420,7 @@
         
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
 
     
     return ret;

+ 1 - 1
RedAnt ERP Mobile/common/Functions/sidemenu/LoginViewController.m

@@ -228,7 +228,7 @@
                         [iSalesDB execSql:savelogin db:db];
                     }
                     
-                    sqlite3_close(db);
+                    [iSalesDB close_db:db];
 
 //                    [defaults setBool:TRUE forKey:@"autologin"];
                 }

+ 4 - 0
RedAnt ERP Mobile/common/data_provider/iSalesDB.h

@@ -15,11 +15,15 @@ typedef void(^queryBlock)(sqlite3_stmt *stmt,NSMutableDictionary *container,long
 
 
 @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;
 

+ 227 - 187
RedAnt ERP Mobile/common/data_provider/iSalesDB.m

@@ -9,6 +9,10 @@
 #import "iSalesDB.h"
 #import "AESCrypt.h"
 #import "AppDelegate.h"
+
+//NSLock *dblock ;
+int count_dbconn;
+//int count_tmpdbconn;
 @implementation iSalesDB
 
 +(BOOL)checkForField:(NSString *)table field:(NSString *)field db:(sqlite3 *)db
@@ -77,14 +81,14 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
             //Get the Objective C string (much easier to manage)
             NSString *ocString = [[NSString alloc] initWithUTF8String:(char *) string] ;
             NSString* decrypt=[AESCrypt fastdecrypt:ocString];
-//            //Split it on punctuation and spaces
-//            NSMutableCharacterSet *cset = [NSCharacterSet punctuationCharacterSet];
-//            [cset addCharactersInString:@" "];
-//            NSArray *tokens = [ocString componentsSeparatedByCharactersInSet:cset];
-//            //Sort it
-//            NSArray *sortedArray = [tokens sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
-//            ocString = [sortedArray componentsJoinedByString:@" "];
-//            ocString = [ocString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+            //            //Split it on punctuation and spaces
+            //            NSMutableCharacterSet *cset = [NSCharacterSet punctuationCharacterSet];
+            //            [cset addCharactersInString:@" "];
+            //            NSArray *tokens = [ocString componentsSeparatedByCharactersInSet:cset];
+            //            //Sort it
+            //            NSArray *sortedArray = [tokens sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
+            //            ocString = [sortedArray componentsJoinedByString:@" "];
+            //            ocString = [ocString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
             
             const char *rString = [decrypt UTF8String];
             
@@ -109,8 +113,8 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     int nResult	= 0;
     nResult=sqlite3_create_function(db, "decrypt", -1, SQLITE_ANY, 0, decryptfield, 0, 0);
     nResult=sqlite3_create_function(db, "encrypt", -1, SQLITE_ANY, 0, encryptfield, 0, 0);
-//  sqlite3_create_function(database, "yourAwesome", 4, SQLITE_UTF8, NULL, &yourAwesomeFunc, NULL, NULL);
-//    nResult	= sqlite3_create_function(db, "containi", -1, SQLITE_ANY, 0, icuContainiFunc, 0, 0);
+    //  sqlite3_create_function(database, "yourAwesome", 4, SQLITE_UTF8, NULL, &yourAwesomeFunc, NULL, NULL);
+    //    nResult	= sqlite3_create_function(db, "containi", -1, SQLITE_ANY, 0, icuContainiFunc, 0, 0);
     return nResult;
 }
 +(NSArray*) get_saveduser
@@ -152,14 +156,14 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
             sqlite3_finalize(statement);
         }
         
-        sqlite3_close(db);
+        [iSalesDB close_db:db];
         
         return ret;
     }
 }
 //+(void)testdata
 //{
-//    
+//
 //    //---------------- init db --------------------
 //    //    NSString* date;
 //    //    NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
@@ -186,12 +190,12 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 //    //    }
 //    //    // end move;
 //    //
-//    
-//    
-//    
-//    
+//
+//
+//
+//
 //    sqlite3 *db = [iSalesDB get_db];
-//    
+//
 //    NSString* drop_model =@"DROP TABLE IF EXISTS MODEL;";
 //    NSString* drop_IMAGE =@"DROP TABLE IF EXISTS model_image;";
 //    NSString* drop_image_price =@"DROP TABLE IF EXISTS model_price;";
@@ -201,8 +205,8 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 //    NSString* drop_wish =@"DROP TABLE IF EXISTS offline_wishlist;";
 //    NSString* drop_contact =@"DROP TABLE IF EXISTS offline_contact;";
 //    NSString* drop_contact_image =@"DROP TABLE IF EXISTS contact_image;";
-//    
-//    
+//
+//
 //    [iSalesDB execSql:drop_model db:db];
 //    [iSalesDB execSql:drop_IMAGE db:db];
 //    [iSalesDB execSql:drop_image_price db:db];
@@ -212,30 +216,30 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 //    [iSalesDB execSql:drop_wish db:db];
 //    [iSalesDB execSql:drop_contact db:db];
 //    [iSalesDB execSql:drop_contact_image db:db];
-//    
+//
 //    NSString* create_model=@"CREATE TABLE IF NOT EXISTS model ( _id INTEGER PRIMARY KEY, name VARCHAR(20), description VARCHAR(20), product_id INTEGER, color VARCHAR(20), legcolor VARCHAR(20) ,availability INTEGER,  incoming_stock INTEGER , demension VARCHAR(20), seat_height VARCHAR(20), material VARCHAR(20), box_dim VARCHAR(20), volume VARCHAR(20), weight VARCHAR(20), model_set VARCHAR(20), load_ability VARCHAR(20),default_category VARCHAR(20), category VARCHAR(100),fabric_content VARCHAR(20), assembling VARCHAR(20), made_in VARCHAR(20), special_remarks VARCHAR(20),stockUom integer,fashion VARCHAR(20), isnew integer,property_field VARCHAR(20),property_display VARCHAR(20),selector_field VARCHAR(20),selector_display VARCHAR(20),ETA DATE);";
-//    
-//    
-//    
+//
+//
+//
 //    NSString* create_image=@"CREATE TABLE IF NOT EXISTS model_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256), type integer, product_id INTEGER);";
-//    
+//
 //    NSString* create_model_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , type integer);";
 //    NSString* create_category=@"CREATE TABLE IF NOT EXISTS category ( _id INTEGER PRIMARY KEY, code VARCHAR(20),name VARCHAR(20));";
-//    
+//
 //    NSString* create_offline_login=@"CREATE TABLE IF NOT EXISTS offline_login ( _id INTEGER PRIMARY KEY, username VARCHAR(40),password VARCHAR(40), can_show_price integer ,can_see_price integer,contact_id VARCHAR(20),user_type integer,can_cancel_order integer,can_set_cart_price integer,can_create_portfolio integer, can_delete_order integer,can_submit_order integer,can_set_tearsheet_price integer,can_create_order integer, mode VARCHAR(20), sales_code VARCHAR(20));";
-//    
-//    
-//    
+//
+//
+//
 //    NSString* create_offline_cart=@"CREATE TABLE IF NOT EXISTS offline_cart ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , discount float , so_no VARCHAR(40));";
 //    NSString* create_offline_wish=@"CREATE TABLE IF NOT EXISTS offline_wishlist ( _id INTEGER PRIMARY KEY, product_id INTEGER);";
-//    
+//
 //    NSString* create_offline_contact=@"CREATE TABLE IF NOT EXISTS offline_contact ( _id INTEGER PRIMARY KEY, country VARCHAR(40),company_name VARCHAR(40),contact_id VARCHAR(20),addr_1 text, addr_2 text , addr_3 text, addr_4 text, zipcode varchar(20),state  VARCHAR(40), city VARCHAR(40), first_name VARCHAR(40) ,last_name  VARCHAR(40),phone VARCHAR(40),fax VARCHAR(40),email VARCHAR(40),notes text, price_type  VARCHAR(40), sales_rep VARCHAR(40), type VARCHAR(40),create_time timestamp,editable integer,contact_name VARCHAR(40) , addr text);";
-//    
+//
 //    NSString* create_contact_image=@"CREATE TABLE IF NOT EXISTS contact_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256),  contact_id VARCHAR(20));";
-//    
-//    
+//
+//
 //    //   NSString* create_model_category=@"CREATE TABLE IF NOT EXISTS model_category ( _id INTEGER PRIMARY KEY, product_id INTEGER,code VARCHAR(20));";
-//    
+//
 //    //        CREATE TABLE users (_id integer PRIMARY KEY,name varchar(20),pass varchar(20));
 //    //        [self execSql:create_actions_info db:db];
 //    //        [self execSql:create_fields_info db:db];
@@ -245,26 +249,26 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 //    //        [self execSql:create_history db:db];
 //    //        [self execSql:create_location db:db];
 //    [iSalesDB execSql:create_model db:db];
-//    
+//
 //    [iSalesDB execSql:create_image db:db];
-//    
+//
 //    [iSalesDB execSql:create_model_price db:db];
 //    [iSalesDB execSql:create_category db:db];
-//    
+//
 //    [iSalesDB execSql:create_offline_login db:db];
-//    
+//
 //    [iSalesDB execSql:create_offline_cart db:db];
 //    [iSalesDB execSql:create_offline_wish db:db];
-//    
-//    
+//
+//
 //    [iSalesDB execSql:create_offline_contact db:db];
-//    
+//
 //    [iSalesDB execSql:create_contact_image db:db];
-//    
+//
 //    NSString * insert_user_queeniey=@"insert into offline_login(can_show_price,can_see_price,contact_id,user_type,can_cancel_order,can_set_cart_price,can_create_portfolio,can_delete_order,can_submit_order,can_set_tearsheet_price,can_create_order,mode,username,password) values(1,1,'NPD',1,1,1,1,1,1,1,1,'Regular Mode','QueenieY','lj0EPk2Th9zZCVwrcskZOA==')";
 //    [iSalesDB execSql:insert_user_queeniey db:db];
 //    //   [self execSql:create_model_category db:db];
-//    
+//
 //    //        if( ![self checkForField:@"search_history" field:@"level" db:db])
 //    //        {
 //    //            NSString* alter_search_history = @"ALTER TABLE search_history ADD level INTEGER";
@@ -279,78 +283,85 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
 //    //
 //    //    //    [self execSql:[NSString stringWithFormat:@"delete from search_history where h_time<%@",timestr ] db:db];
 //    //        [self execSql:@"delete from search_history where julianday('now', 'localtime')-julianday(h_time, 'localtime')>30" db:db];
-//    //  int ret=sqlite3_close(db);
-//    
-//    
+//    //  int ret=[iSalesDB close_db:db];
+//
+//
 //    DebugLog (@"bottom of initializeDb");
-//    
-//    
+//
+//
 //    NSString* IMS_S=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_s.jpg";
 //    //NSString* IMS_M=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_m.jpg";
 //    NSString* IMS_L=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_l.jpg";
-//    
+//
 //    //----------------- fill data -------------------
 //    NSString* img_url1 = IMS_S;
 //    //   NSString* img_url2 = IMS_M;
 //    NSString* img_url3 = IMS_L;
-//    
+//
 //    CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
 //    [iSalesDB execSql:@"begin" db:db];
 //    //   NSString* exec = @"";
 //    for(int i=0;i<1000;i++)
 //    {
-//        
+//
 //        int category = arc4random() % 4;
 //        NSString* sql = [NSString stringWithFormat:@"insert into model(ETA,property_display,property_field,selector_display,isnew,selector_field,fashion,stockUom,name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,material,box_dim,volume,weight,model_set,load_ability,default_category,category,fabric_content,assembling,made_in,special_remarks) values('07/13/2016','Leg Color','legcolor','Color',1,'color','108526-48-BS%d',1,'108526-48-BS%d','Charlotte Fabric Counter Stool Brushed Smoke Legs, Putty%d',%d,'red color%d','white color%d',15%d,25%d,'20.00\"w  22.00\"d  39.00\"h%d','26.0\"h','Solid Birch Wood%d','20.50\"w  23.00\"d  40.00\"h',10.91%d,23.00%d,'Sold in quantities of 1','Load ability%d','%d','%d','77%% Polyester, 15%% Cotton, 8%% Linen', 'Fully Assembled;%d','China%d','Special Remarks%d');",i,i,i,i,i,i,i,i,i,i,i,i,i,category,category,i,i,i];
-//        
-//        
+//
+//
 //        NSString* sql_1=[NSString stringWithFormat:@"insert into model_price (product_id,price,type) values(%d,12.%d,0);",i,i%100];
 //        NSString* sql_2=[NSString stringWithFormat:@"insert into model_price (product_id,price,type) values(%d,12.%d,1);",i,i%100];
 //        NSString* sql_3=[NSString stringWithFormat:@"insert into model_price (product_id,price,type) values(%d,12.%d,2);",i,i%100];
-//        
-//        
-//        
+//
+//
+//
 //        NSString* sql_4=[NSString stringWithFormat:@"insert into model_image(product_id,type,url) values(%d,0,'%@')",i,img_url1];
 //        NSString* sql_5=[NSString stringWithFormat:@"insert into model_image(product_id,type,url) values(%d,1,'%@')",i,img_url3];
-//        
+//
 //        //        exec=[exec stringByAppendingString:sql];
 //        //
 //        //        exec=[exec stringByAppendingString:sql_1];
 //        //        exec=[exec stringByAppendingString:sql_2];
 //        //        exec=[exec stringByAppendingString:sql_3];
-//        
-//        
+//
+//
 //        [iSalesDB execSql:sql db:db];
-//        
+//
 //        [iSalesDB execSql:sql_1 db:db];
 //        [iSalesDB execSql:sql_2 db:db];
 //        [iSalesDB execSql:sql_3 db:db];
 //        [iSalesDB execSql:sql_4 db:db];
 //        [iSalesDB execSql:sql_5 db:db];
-//        
+//
 //    }
 //    //    [iSalesDB execSql:exec db:db];
-//    
+//
 //    [iSalesDB execSql:@"update model set category='#001003#;' where category='0'" db:db];
 //    [iSalesDB execSql:@"update model set category='#001001#;' where category='1'" db:db];
 //    [iSalesDB execSql:@"update model set category='#001002#;' where category='2'" db:db];
 //    [iSalesDB execSql:@"update model set category='#001003#;' where category='3'" db:db];
 //    [iSalesDB execSql:@"commit" db:db];
-//    sqlite3_close(db);
-//    
+//    [iSalesDB close_db:db];
+//
 //    CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
-//    
+//
 //    //  ((double)(begintime-endtime))/(1000*1000);
 //    NSLog(@"time cost: %0.3f", end - start);
-//    
-//    
-//    
-//    
-//    
-//    
+//
+//
+//
+//
+//
+//
 //}
+
 + (sqlite3*) get_db
 {
+    
+    
+    //    if(dblock==nil)
+    //        dblock=  [[NSLock alloc] init];
+    //  [dblock lock];
+    
     sqlite3* db = nil;
     
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
@@ -358,13 +369,31 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
     
     DebugLog(@"DB path:%@",database_path);
+    count_dbconn++;
+    NSLog(@"current dbconn: %d",count_dbconn);
     if (sqlite3_open([database_path UTF8String], &db) != SQLITE_OK) {
         
         DebugLog(@"sqlite3_open failed. msg:%s",sqlite3_errmsg(db));
-        sqlite3_close(db);
+        [iSalesDB close_db:db];
     }
+
     return db;
     
+    
+    
+    
+}
++ (void) close_db:(sqlite3 *)db
+{
+    
+    
+    sqlite3_close(db);
+    count_dbconn--;
+    NSLog(@"current dbconn: %d",count_dbconn);
+    //   [dblock unlock];
+    
+    
+    
 }
 
 + (sqlite3*) get_db_at:(NSString* )path
@@ -376,11 +405,15 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     //    NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
     
     //    DebugLog(@"DB path:%@",database_path);
+    count_dbconn++;
+    
+    NSLog(@"current dbconn: %d",count_dbconn);
     if (sqlite3_open([path UTF8String], &db) != SQLITE_OK) {
         
         DebugLog(@"sqlite3_open failed. msg:%s",sqlite3_errmsg(db));
-        sqlite3_close(db);
+        [iSalesDB close_db:db];
     }
+
     return db;
     
 }
@@ -429,7 +462,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         //            sqlite3 *db = [self get_db];
         //
         //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
-        //            sqlite3_close(db);
+        //            [iSalesDB close_db:db];
         //        }
     }
     NSString *save_path = [pdf_cache stringByAppendingPathComponent:filename];
@@ -453,22 +486,22 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
     path=[path stringByReplacingOccurrencesOfString:name withString:@""];
     
-//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
-//    NSString *cachefolder = [paths objectAtIndex:0];
-//    NSString *img_cache = [cachefolder stringByAppendingPathComponent:[NSString stringWithFormat:@"img_cache/%@",@"www.newpacificdirect.com/u/NPD/20160615/mytest/"]];
-//    if ([[NSFileManager defaultManager] fileExistsAtPath:img_cache]) {
-//        
-//        NSLog(@"目录已经存在了");
-//        
-//    }
-//    else
-//    {
-//        NSError *error = nil;
-//        bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:img_cache withIntermediateDirectories:YES attributes:nil error:&error];
-//        
-//        if(!bsuccess)
-//            DebugLog(@"Create temp folder failed");
-//    }
+    //    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    //    NSString *cachefolder = [paths objectAtIndex:0];
+    //    NSString *img_cache = [cachefolder stringByAppendingPathComponent:[NSString stringWithFormat:@"img_cache/%@",@"www.newpacificdirect.com/u/NPD/20160615/mytest/"]];
+    //    if ([[NSFileManager defaultManager] fileExistsAtPath:img_cache]) {
+    //
+    //        NSLog(@"目录已经存在了");
+    //
+    //    }
+    //    else
+    //    {
+    //        NSError *error = nil;
+    //        bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:img_cache withIntermediateDirectories:YES attributes:nil error:&error];
+    //
+    //        if(!bsuccess)
+    //            DebugLog(@"Create temp folder failed");
+    //    }
     
     
     if(path.length==0)
@@ -499,7 +532,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         //            sqlite3 *db = [self get_db];
         //
         //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
-        //            sqlite3_close(db);
+        //            [iSalesDB close_db:db];
         //        }
     }
     NSString *filePath = [img_cache stringByAppendingPathComponent:name];
@@ -517,7 +550,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     path=[path stringByReplacingOccurrencesOfString:@"https://" withString:@""];
     path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
-//    path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
+    //    path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
     
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     
@@ -557,13 +590,14 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     //    sqlite3_finalize(statement);
     
     
-    // sqlite3_close(db);
+    // [iSalesDB close_db:db];
     return data;
     
 }
 + (int) initializeDb {
     DebugLog (@"initializeDB");
-    
+    count_dbconn=0;
+    //count_tmpdbconn=0;
     //    return false;
     //
     //       NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
@@ -587,113 +621,115 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     
     
     
-
-        sqlite3 *db = [self get_db];
-        
-        NSString* create_model=@"CREATE TABLE IF NOT EXISTS model ( _id INTEGER, name VARCHAR(20,0), description VARCHAR(20,0), product_id INTEGER, color VARCHAR(20,0), legcolor VARCHAR(20,0), availability INTEGER, incoming_stock INTEGER, ETA DATE, demension VARCHAR(20,0), seat_height VARCHAR(20,0), material VARCHAR(20,0), box_dim VARCHAR(20,0), volume VARCHAR(20,0), weight VARCHAR(20,0), model_set VARCHAR(20,0), load_ability VARCHAR(20,0), default_category VARCHAR(20,0), category VARCHAR(100,0), fabric_content VARCHAR(20,0), assembling VARCHAR(20,0), made_in VARCHAR(20,0), special_remarks VARCHAR(20,0), stockUom integer, fashion VARCHAR(20,0), isnew integer, property_field VARCHAR(20,0), property_display VARCHAR(20,0), selector_field VARCHAR(20,0), selector_display VARCHAR(20,0), product_group VARCHAR(20,0), packaging VARCHAR(20,0), closeout integer ,best_seller integer,bundle_item text,alert VARCHAR(20,0),PRIMARY KEY(_id));";
-        
-        NSString* create_price=@"CREATE TABLE IF NOT EXISTS price ( _id INTEGER PRIMARY KEY, name text,  type integer,  order_by integer);";
-        
-        
-        NSString* create_wishlist=@"CREATE TABLE IF NOT EXISTS wishlist ( _id INTEGER PRIMARY KEY, user_id INTEGER,  product_id integer , create_time TIMESTAMP default (datetime('now', 'localtime')));";
-        
-        
-        NSString* create_image=@"CREATE TABLE IF NOT EXISTS model_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url text, type integer, product_id INTEGER, default_img integer);";
-        
-        NSString* create_model_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,price text , type integer, price_name text, expire_datetime datetime);";
-        NSString* create_category=@"CREATE TABLE IF NOT EXISTS category ( _id INTEGER PRIMARY KEY, code VARCHAR(20),name VARCHAR(20));";
-        NSString* create_offline_setting=@"CREATE TABLE IF NOT EXISTS offline_setting ( _id INTEGER PRIMARY KEY, name VARCHAR(20),value VARCHAR(40));";
-        
-        
-        NSString* create_offline_login=@"CREATE TABLE IF NOT EXISTS offline_login ( _id INTEGER PRIMARY KEY, username VARCHAR(40),password VARCHAR(40), can_show_price integer ,can_see_price integer,contact_id VARCHAR(20),user_type integer,can_cancel_order integer,can_set_cart_price integer,can_create_portfolio integer, can_delete_order integer,can_submit_order integer,can_set_tearsheet_price integer,can_create_order integer, can_update_contact_info integer, mode VARCHAR(20), default_price text, price text, user_id integer,sales_code text);";
     
-     NSString* create_offline_order=@"CREATE TABLE IF NOT EXISTS offline_order ( _id INTEGER PRIMARY KEY,so_id text, order_id text ,status integer, general_notes TEXT ,internal_notes text,signature  text,user_type integer,contact_id text,sales_rep TEXT,create_by TEXT, total_price float, create_time TIMESTAMP default (datetime('now', 'localtime')));";
+    sqlite3 *db = [self get_db];
     
-
-        
+    [self execSql:@"PRAGMA journal_mode = WAL;" db:db];
+    
+    NSString* create_model=@"CREATE TABLE IF NOT EXISTS model ( _id INTEGER, name VARCHAR(20,0), description VARCHAR(20,0), product_id INTEGER, color VARCHAR(20,0), legcolor VARCHAR(20,0), availability INTEGER, incoming_stock INTEGER, ETA DATE, demension VARCHAR(20,0), seat_height VARCHAR(20,0), material VARCHAR(20,0), box_dim VARCHAR(20,0), volume VARCHAR(20,0), weight VARCHAR(20,0), model_set VARCHAR(20,0), load_ability VARCHAR(20,0), default_category VARCHAR(20,0), category VARCHAR(100,0), fabric_content VARCHAR(20,0), assembling VARCHAR(20,0), made_in VARCHAR(20,0), special_remarks VARCHAR(20,0), stockUom integer, fashion VARCHAR(20,0), isnew integer, property_field VARCHAR(20,0), property_display VARCHAR(20,0), selector_field VARCHAR(20,0), selector_display VARCHAR(20,0), product_group VARCHAR(20,0), packaging VARCHAR(20,0), closeout integer ,best_seller integer,bundle_item text,alert VARCHAR(20,0),PRIMARY KEY(_id));";
+    
+    NSString* create_price=@"CREATE TABLE IF NOT EXISTS price ( _id INTEGER PRIMARY KEY, name text,  type integer,  order_by integer);";
+    
+    
+    NSString* create_wishlist=@"CREATE TABLE IF NOT EXISTS wishlist ( _id INTEGER PRIMARY KEY, user_id INTEGER,  product_id integer , create_time TIMESTAMP default (datetime('now', 'localtime')));";
+    
+    
+    NSString* create_image=@"CREATE TABLE IF NOT EXISTS model_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url text, type integer, product_id INTEGER, default_img integer);";
+    
+    NSString* create_model_price=@"CREATE TABLE IF NOT EXISTS model_price ( _id INTEGER PRIMARY KEY, product_id INTEGER,price text , type integer, price_name text, expire_datetime datetime);";
+    NSString* create_category=@"CREATE TABLE IF NOT EXISTS category ( _id INTEGER PRIMARY KEY, code VARCHAR(20),name VARCHAR(20));";
+    NSString* create_offline_setting=@"CREATE TABLE IF NOT EXISTS offline_setting ( _id INTEGER PRIMARY KEY, name VARCHAR(20),value VARCHAR(40));";
+    
+    
+    NSString* create_offline_login=@"CREATE TABLE IF NOT EXISTS offline_login ( _id INTEGER PRIMARY KEY, username VARCHAR(40),password VARCHAR(40), can_show_price integer ,can_see_price integer,contact_id VARCHAR(20),user_type integer,can_cancel_order integer,can_set_cart_price integer,can_create_portfolio integer, can_delete_order integer,can_submit_order integer,can_set_tearsheet_price integer,can_create_order integer, can_update_contact_info integer, mode VARCHAR(20), default_price text, price text, user_id integer,sales_code text);";
+    
+    NSString* create_offline_order=@"CREATE TABLE IF NOT EXISTS offline_order ( _id INTEGER PRIMARY KEY,so_id text, order_id text ,status integer, general_notes TEXT ,internal_notes text,signature  text,user_type integer,contact_id text,sales_rep TEXT,create_by TEXT, total_price float, create_time TIMESTAMP default (datetime('now', 'localtime')));";
+    
+    
+    
+    
+    NSString* create_offline_cart=@"CREATE TABLE IF NOT EXISTS offline_cart ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , discount float , so_no VARCHAR(40));";
+    NSString* create_offline_wish=@"CREATE TABLE IF NOT EXISTS offline_wishlist ( _id INTEGER PRIMARY KEY, product_id INTEGER);";
+    
+    
+    NSString* create_offline_contact=@"CREATE TABLE IF NOT EXISTS offline_contact (_id INTEGER, country VARCHAR(40,0), company_name VARCHAR(40,0), contact_id VARCHAR(20,0), addr_1 text, addr_2 text, addr_3 text, addr_4 text, zipcode varchar(20,0), state VARCHAR(40,0), city VARCHAR(40,0), first_name VARCHAR(40,0), last_name VARCHAR(40,0), phone VARCHAR(40,0), fax VARCHAR(40,0), email VARCHAR(40,0), notes text, price_type VARCHAR(40,0), sales_rep VARCHAR(40,0), type VARCHAR(40,0), create_time timestamp default (datetime('now', 'localtime')), editable integer, contact_name VARCHAR(40,0), addr text, Sales_Order_Customer integer, Sales_Order_Freight_Bill_To integer, Sales_Order_Ship_From integer, Sales_Order_Merchandise_Bill_To integer, Contact_Return_To integer, Sales_Order_Ship_To integer,img_0 TEXT,img_1 TEXT,img_2 TEXT,related_cid VARCHAR(20,0), PRIMARY KEY(_id) );";
+    
+    NSString* create_contact_image=@"CREATE TABLE IF NOT EXISTS contact_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256), contact_id VARCHAR(20));";
+    
+    
+    NSString* create_login_info=@"CREATE TABLE IF NOT EXISTS login_info ( _id INTEGER PRIMARY KEY, name VARCHAR(256), pwd VARCHAR(256), lastlogin timestamp );";
+    
+    NSString* create_offline_country=@"CREATE TABLE IF NOT EXISTS offline_country ( _id INTEGER PRIMARY KEY, name text,code VARCHAR(16), countrycode_id integer);";
+    
+    NSString* create_offline_state=@"CREATE TABLE IF NOT EXISTS offline_state ( _id INTEGER PRIMARY KEY, name text,code VARCHAR(16), country_code VARCHAR(16));";
+    
+    NSString* create_offline_zipcode=@"CREATE TABLE IF NOT EXISTS offline_zipcode ( _id INTEGER PRIMARY KEY, country text, state text, city text,state_code VARCHAR(16), country_code VARCHAR(16), zipcode VARCHAR(16));";
+    
+    NSString* create_offline_salesrep=@"CREATE TABLE IF NOT EXISTS offline_salesrep ( _id INTEGER PRIMARY KEY, name text, code text,salesrep_id integer);";
+    
+    //
+    
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    //if(appDelegate.offline_mode)
+    {
+        [self execSql:create_model db:db];
+        [self execSql:create_wishlist db:db];
+        [self execSql:create_price db:db];
+        [self execSql:create_image db:db];
         
-        NSString* create_offline_cart=@"CREATE TABLE IF NOT EXISTS offline_cart ( _id INTEGER PRIMARY KEY, product_id INTEGER,price float , discount float , so_no VARCHAR(40));";
-        NSString* create_offline_wish=@"CREATE TABLE IF NOT EXISTS offline_wishlist ( _id INTEGER PRIMARY KEY, product_id INTEGER);";
+        [self execSql:create_model_price db:db];
+        [self execSql:create_category db:db];
+        [self execSql:create_offline_setting db:db];
         
+        [self execSql:create_offline_login db:db];
         
-        NSString* create_offline_contact=@"CREATE TABLE IF NOT EXISTS offline_contact (_id INTEGER, country VARCHAR(40,0), company_name VARCHAR(40,0), contact_id VARCHAR(20,0), addr_1 text, addr_2 text, addr_3 text, addr_4 text, zipcode varchar(20,0), state VARCHAR(40,0), city VARCHAR(40,0), first_name VARCHAR(40,0), last_name VARCHAR(40,0), phone VARCHAR(40,0), fax VARCHAR(40,0), email VARCHAR(40,0), notes text, price_type VARCHAR(40,0), sales_rep VARCHAR(40,0), type VARCHAR(40,0), create_time timestamp default (datetime('now', 'localtime')), editable integer, contact_name VARCHAR(40,0), addr text, Sales_Order_Customer integer, Sales_Order_Freight_Bill_To integer, Sales_Order_Ship_From integer, Sales_Order_Merchandise_Bill_To integer, Contact_Return_To integer, Sales_Order_Ship_To integer,img_0 TEXT,img_1 TEXT,img_2 TEXT,related_cid VARCHAR(20,0), PRIMARY KEY(_id) );";
+        [self execSql:create_offline_cart db:db];
         
-        NSString* create_contact_image=@"CREATE TABLE IF NOT EXISTS contact_image ( _id INTEGER PRIMARY KEY, name VARCHAR(20), url VARCHAR(256), contact_id VARCHAR(20));";
+        [self execSql:create_offline_wish db:db];
         
+        [self execSql:create_offline_contact db:db];
         
-        NSString* create_login_info=@"CREATE TABLE IF NOT EXISTS login_info ( _id INTEGER PRIMARY KEY, name VARCHAR(256), pwd VARCHAR(256), lastlogin timestamp );";
-    
-        NSString* create_offline_country=@"CREATE TABLE IF NOT EXISTS offline_country ( _id INTEGER PRIMARY KEY, name text,code VARCHAR(16), countrycode_id integer);";
-    
-        NSString* create_offline_state=@"CREATE TABLE IF NOT EXISTS offline_state ( _id INTEGER PRIMARY KEY, name text,code VARCHAR(16), country_code VARCHAR(16));";
-    
-        NSString* create_offline_zipcode=@"CREATE TABLE IF NOT EXISTS offline_zipcode ( _id INTEGER PRIMARY KEY, country text, state text, city text,state_code VARCHAR(16), country_code VARCHAR(16), zipcode VARCHAR(16));";
-    
-        NSString* create_offline_salesrep=@"CREATE TABLE IF NOT EXISTS offline_salesrep ( _id INTEGER PRIMARY KEY, name text, code text,salesrep_id integer);";
-    
-        //
+        [self execSql:create_contact_image db:db];
         
-        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+        [self execSql:create_offline_order db:db];
         
-        //if(appDelegate.offline_mode)
-        {
-            [self execSql:create_model db:db];
-            [self execSql:create_wishlist db:db];
-            [self execSql:create_price db:db];
-            [self execSql:create_image db:db];
-            
-            [self execSql:create_model_price db:db];
-            [self execSql:create_category db:db];
-            [self execSql:create_offline_setting db:db];
-            
-            [self execSql:create_offline_login db:db];
-            
-            [self execSql:create_offline_cart db:db];
-            
-            [self execSql:create_offline_wish db:db];
-            
-            [self execSql:create_offline_contact db:db];
-            
-            [self execSql:create_contact_image db:db];
-            
-            [self execSql:create_offline_order db:db];
-            
-            [self execSql:create_offline_country db:db];
-            [self execSql:create_offline_state db:db];
-            [self execSql:create_offline_zipcode db:db];
-            [self execSql:create_offline_salesrep db:db];
-            
-            
-        }
+        [self execSql:create_offline_country db:db];
+        [self execSql:create_offline_state db:db];
+        [self execSql:create_offline_zipcode db:db];
+        [self execSql:create_offline_salesrep db:db];
         
-        [self execSql:create_login_info db:db];
         
-                if( ![self checkForField:@"offline_login" field:@"sales_code" db:db])
-                {
-                    NSString* alter_search_history = @"ALTER TABLE offline_login ADD sales_code text";
-                    [self execSql:alter_search_history db:db];
-                }
+    }
+    
+    [self execSql:create_login_info db:db];
+    
+    if( ![self checkForField:@"offline_login" field:@"sales_code" db:db])
+    {
+        NSString* alter_search_history = @"ALTER TABLE offline_login ADD sales_code text";
+        [self execSql:alter_search_history db:db];
+    }
     if( ![self checkForField:@"offline_login" field:@"can_update_contact_info" db:db])
     {
         NSString* alter_search_history = @"ALTER TABLE offline_login ADD can_update_contact_info integer";
         [self execSql:alter_search_history db:db];
     }
     
-        //        NSTimeInterval time=[[NSDate date] timeIntervalSince1970];
-        //        double t = time-2592000;      //NSTimeInterval返回的是double类型
-        //        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-        //        [formatter setDateFormat:@"yyyy-MM-dd"];
-        //
-        //        NSString*timestr=[formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:t]];
-        //
-        //    //    [self execSql:[NSString stringWithFormat:@"delete from search_history where h_time<%@",timestr ] db:db];
-        //        [self execSql:@"delete from search_history where julianday('now', 'localtime')-julianday(h_time, 'localtime')>30" db:db];
-        int ret=sqlite3_close(db);
-        return ret;
-        //        int aaa = 0;
+    //        NSTimeInterval time=[[NSDate date] timeIntervalSince1970];
+    //        double t = time-2592000;      //NSTimeInterval返回的是double类型
+    //        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+    //        [formatter setDateFormat:@"yyyy-MM-dd"];
+    //
+    //        NSString*timestr=[formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:t]];
+    //
+    //    //    [self execSql:[NSString stringWithFormat:@"delete from search_history where h_time<%@",timestr ] db:db];
+    //        [self execSql:@"delete from search_history where julianday('now', 'localtime')-julianday(h_time, 'localtime')>30" db:db];
+    [iSalesDB close_db:db];
+    return 0;
+    //        int aaa = 0;
     
     
-   // DebugLog (@"bottom of initializeDb");
+    // DebugLog (@"bottom of initializeDb");
 }
 +(int)execSql:(NSString *)sql db:(sqlite3 *)db
 {
@@ -705,9 +741,13 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         DebugLog(@"sqlite3_exec failed msg:%s",sqlite3_errmsg(db));
         DebugLog(@"sqlite3_exec failed sql:%@",sql);
         ret= RESULT_FALSE;
-        // sqlite3_close(db);
+        // [iSalesDB close_db:db];
         
     }
+//    else
+//    {
+//        int result=sqlite3_wal_checkpoint(db, NULL);
+//    }
     return ret;
 }
 + (NSDictionary*) search_pdf:(int) offset limit:(int)limit keywords:(NSString*) keywords
@@ -762,7 +802,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         [json setValue:@"2" forKey:@"result"];
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     return json;
 }
 +(int)execSql:(NSString *)sql
@@ -771,7 +811,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
     sqlite3 *db = [self get_db];
     int ret=[self execSql:sql db:db];
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     return ret;
 }
 + (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause
@@ -807,7 +847,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         }
         sqlite3_finalize(statement);
     }
-    //   sqlite3_close(db);
+    //   [iSalesDB close_db:db];
     return ret;
 }
 + (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby
@@ -834,7 +874,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         }
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     return ret;
     
 }
@@ -891,7 +931,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     
     return [dic copy];
@@ -913,7 +953,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
         
         sqlite3_finalize(statement);
     }
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
     
     return ret;
 }

+ 0 - 5
RedAnt ERP Mobile/iSales-NPD.xcodeproj/xcuserdata/Ray.xcuserdatad/xcschemes/RedAnt ERP Suite.xcscheme

@@ -79,11 +79,6 @@
          </EnvironmentVariable>
       </EnvironmentVariables>
       <AdditionalOptions>
-         <AdditionalOption
-            key = "NSZombieEnabled"
-            value = "YES"
-            isEnabled = "YES">
-         </AdditionalOption>
       </AdditionalOptions>
    </LaunchAction>
    <ProfileAction

+ 5 - 4
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -569,7 +569,7 @@
         sqlite3_finalize(statement);
     }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
 }
 
 -(void)test_descrypt1
@@ -611,7 +611,7 @@
 //        sqlite3_finalize(statement);
 //    }
     
-    sqlite3_close(db);
+    [iSalesDB close_db:db];
 }
 
 - (void)applicationWillResignActive:(UIApplication *)application
@@ -926,7 +926,7 @@
         //            sqlite3 *db = [self get_db];
         //
         //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
-        //            sqlite3_close(db);
+        //            [iSalesDB close_db:db];
         //        }
     }
     
@@ -1564,7 +1564,8 @@
                     }
                 }
                 @finally {
-                    sqlite3_close(tdb);
+                    //sqlite3_close(tdb);
+                    [iSalesDB close_db:tdb];
                     //  [self SelectData];
                 }
                 

+ 3 - 3
RedAnt ERP Mobile/iSales-NPD/Images.xcassets/reset.imageset/Contents.json

@@ -2,17 +2,17 @@
   "images" : [
     {
       "idiom" : "universal",
-      "filename" : "reset.png",
+      "filename" : "appicon.png",
       "scale" : "1x"
     },
     {
       "idiom" : "universal",
-      "filename" : "reset@2x.png",
+      "filename" : "appicon-1.png",
       "scale" : "2x"
     },
     {
       "idiom" : "universal",
-      "filename" : "reset@3x.png",
+      "filename" : "appicon-2.png",
       "scale" : "3x"
     }
   ],

BIN
RedAnt ERP Mobile/iSales-NPD/Images.xcassets/reset.imageset/appicon-1.png


BIN
RedAnt ERP Mobile/iSales-NPD/Images.xcassets/reset.imageset/appicon-2.png


BIN
RedAnt ERP Mobile/iSales-NPD/Images.xcassets/reset.imageset/appicon.png


BIN
RedAnt ERP Mobile/iSales-NPD/Images.xcassets/reset.imageset/reset.png


BIN
RedAnt ERP Mobile/iSales-NPD/Images.xcassets/reset.imageset/reset@2x.png


BIN
RedAnt ERP Mobile/iSales-NPD/Images.xcassets/reset.imageset/reset@3x.png


Неке датотеке нису приказане због велике количине промена