|
@@ -9,6 +9,10 @@
|
|
|
#import "iSalesDB.h"
|
|
#import "iSalesDB.h"
|
|
|
#import "AESCrypt.h"
|
|
#import "AESCrypt.h"
|
|
|
#import "AppDelegate.h"
|
|
#import "AppDelegate.h"
|
|
|
|
|
+
|
|
|
|
|
+//NSLock *dblock ;
|
|
|
|
|
+int count_dbconn;
|
|
|
|
|
+//int count_tmpdbconn;
|
|
|
@implementation iSalesDB
|
|
@implementation iSalesDB
|
|
|
|
|
|
|
|
+(BOOL)checkForField:(NSString *)table field:(NSString *)field db:(sqlite3 *)db
|
|
+(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)
|
|
//Get the Objective C string (much easier to manage)
|
|
|
NSString *ocString = [[NSString alloc] initWithUTF8String:(char *) string] ;
|
|
NSString *ocString = [[NSString alloc] initWithUTF8String:(char *) string] ;
|
|
|
NSString* decrypt=[AESCrypt fastdecrypt:ocString];
|
|
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];
|
|
const char *rString = [decrypt UTF8String];
|
|
|
|
|
|
|
@@ -109,8 +113,8 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
int nResult = 0;
|
|
int nResult = 0;
|
|
|
nResult=sqlite3_create_function(db, "decrypt", -1, SQLITE_ANY, 0, decryptfield, 0, 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);
|
|
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;
|
|
return nResult;
|
|
|
}
|
|
}
|
|
|
+(NSArray*) get_saveduser
|
|
+(NSArray*) get_saveduser
|
|
@@ -152,14 +156,14 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
sqlite3_finalize(statement);
|
|
sqlite3_finalize(statement);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
//+(void)testdata
|
|
//+(void)testdata
|
|
|
//{
|
|
//{
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// //---------------- init db --------------------
|
|
// //---------------- init db --------------------
|
|
|
// // NSString* date;
|
|
// // NSString* date;
|
|
|
// // NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
|
|
// // NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
|
|
@@ -186,12 +190,12 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
// // }
|
|
// // }
|
|
|
// // // end move;
|
|
// // // end move;
|
|
|
// //
|
|
// //
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
// sqlite3 *db = [iSalesDB get_db];
|
|
// sqlite3 *db = [iSalesDB get_db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// NSString* drop_model =@"DROP TABLE IF EXISTS MODEL;";
|
|
// NSString* drop_model =@"DROP TABLE IF EXISTS MODEL;";
|
|
|
// NSString* drop_IMAGE =@"DROP TABLE IF EXISTS model_image;";
|
|
// NSString* drop_IMAGE =@"DROP TABLE IF EXISTS model_image;";
|
|
|
// NSString* drop_image_price =@"DROP TABLE IF EXISTS model_price;";
|
|
// 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_wish =@"DROP TABLE IF EXISTS offline_wishlist;";
|
|
|
// NSString* drop_contact =@"DROP TABLE IF EXISTS offline_contact;";
|
|
// NSString* drop_contact =@"DROP TABLE IF EXISTS offline_contact;";
|
|
|
// NSString* drop_contact_image =@"DROP TABLE IF EXISTS contact_image;";
|
|
// NSString* drop_contact_image =@"DROP TABLE IF EXISTS contact_image;";
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:drop_model db:db];
|
|
// [iSalesDB execSql:drop_model db:db];
|
|
|
// [iSalesDB execSql:drop_IMAGE db:db];
|
|
// [iSalesDB execSql:drop_IMAGE db:db];
|
|
|
// [iSalesDB execSql:drop_image_price 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_wish db:db];
|
|
|
// [iSalesDB execSql:drop_contact db:db];
|
|
// [iSalesDB execSql:drop_contact db:db];
|
|
|
// [iSalesDB execSql:drop_contact_image 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_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_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_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_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_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_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_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_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_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));";
|
|
// // 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));
|
|
// // CREATE TABLE users (_id integer PRIMARY KEY,name varchar(20),pass varchar(20));
|
|
|
// // [self execSql:create_actions_info db:db];
|
|
// // [self execSql:create_actions_info db:db];
|
|
|
// // [self execSql:create_fields_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_history db:db];
|
|
|
// // [self execSql:create_location db:db];
|
|
// // [self execSql:create_location db:db];
|
|
|
// [iSalesDB execSql:create_model db:db];
|
|
// [iSalesDB execSql:create_model db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:create_image db:db];
|
|
// [iSalesDB execSql:create_image db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:create_model_price db:db];
|
|
// [iSalesDB execSql:create_model_price db:db];
|
|
|
// [iSalesDB execSql:create_category db:db];
|
|
// [iSalesDB execSql:create_category db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:create_offline_login db:db];
|
|
// [iSalesDB execSql:create_offline_login db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:create_offline_cart db:db];
|
|
// [iSalesDB execSql:create_offline_cart db:db];
|
|
|
// [iSalesDB execSql:create_offline_wish db:db];
|
|
// [iSalesDB execSql:create_offline_wish db:db];
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:create_offline_contact db:db];
|
|
// [iSalesDB execSql:create_offline_contact db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:create_contact_image 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==')";
|
|
// 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];
|
|
// [iSalesDB execSql:insert_user_queeniey db:db];
|
|
|
// // [self execSql:create_model_category db:db];
|
|
// // [self execSql:create_model_category db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// // if( ![self checkForField:@"search_history" field:@"level" db:db])
|
|
// // if( ![self checkForField:@"search_history" field:@"level" db:db])
|
|
|
// // {
|
|
// // {
|
|
|
// // NSString* alter_search_history = @"ALTER TABLE search_history ADD level INTEGER";
|
|
// // 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:[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];
|
|
// // [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");
|
|
// DebugLog (@"bottom of initializeDb");
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
// NSString* IMS_S=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_s.jpg";
|
|
// 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_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";
|
|
// NSString* IMS_L=@"http://113.28.30.235:80/site//u/NPD/20150715/3857_1455_l.jpg";
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// //----------------- fill data -------------------
|
|
// //----------------- fill data -------------------
|
|
|
// NSString* img_url1 = IMS_S;
|
|
// NSString* img_url1 = IMS_S;
|
|
|
// // NSString* img_url2 = IMS_M;
|
|
// // NSString* img_url2 = IMS_M;
|
|
|
// NSString* img_url3 = IMS_L;
|
|
// NSString* img_url3 = IMS_L;
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
|
|
// CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
|
|
|
// [iSalesDB execSql:@"begin" db:db];
|
|
// [iSalesDB execSql:@"begin" db:db];
|
|
|
// // NSString* exec = @"";
|
|
// // NSString* exec = @"";
|
|
|
// for(int i=0;i<1000;i++)
|
|
// for(int i=0;i<1000;i++)
|
|
|
// {
|
|
// {
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// int category = arc4random() % 4;
|
|
// 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 = [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_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_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_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_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];
|
|
// 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];
|
|
|
// //
|
|
// //
|
|
|
// // exec=[exec stringByAppendingString:sql_1];
|
|
// // exec=[exec stringByAppendingString:sql_1];
|
|
|
// // exec=[exec stringByAppendingString:sql_2];
|
|
// // exec=[exec stringByAppendingString:sql_2];
|
|
|
// // exec=[exec stringByAppendingString:sql_3];
|
|
// // exec=[exec stringByAppendingString:sql_3];
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:sql db:db];
|
|
// [iSalesDB execSql:sql db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// [iSalesDB execSql:sql_1 db:db];
|
|
// [iSalesDB execSql:sql_1 db:db];
|
|
|
// [iSalesDB execSql:sql_2 db:db];
|
|
// [iSalesDB execSql:sql_2 db:db];
|
|
|
// [iSalesDB execSql:sql_3 db:db];
|
|
// [iSalesDB execSql:sql_3 db:db];
|
|
|
// [iSalesDB execSql:sql_4 db:db];
|
|
// [iSalesDB execSql:sql_4 db:db];
|
|
|
// [iSalesDB execSql:sql_5 db:db];
|
|
// [iSalesDB execSql:sql_5 db:db];
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// }
|
|
// }
|
|
|
// // [iSalesDB execSql:exec 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='#001003#;' where category='0'" db:db];
|
|
|
// [iSalesDB execSql:@"update model set category='#001001#;' where category='1'" 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='#001002#;' where category='2'" db:db];
|
|
|
// [iSalesDB execSql:@"update model set category='#001003#;' where category='3'" db:db];
|
|
// [iSalesDB execSql:@"update model set category='#001003#;' where category='3'" db:db];
|
|
|
// [iSalesDB execSql:@"commit" db:db];
|
|
// [iSalesDB execSql:@"commit" db:db];
|
|
|
-// sqlite3_close(db);
|
|
|
|
|
-//
|
|
|
|
|
|
|
+// [iSalesDB close_db:db];
|
|
|
|
|
+//
|
|
|
// CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
|
|
// CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
// // ((double)(begintime-endtime))/(1000*1000);
|
|
// // ((double)(begintime-endtime))/(1000*1000);
|
|
|
// NSLog(@"time cost: %0.3f", end - start);
|
|
// NSLog(@"time cost: %0.3f", end - start);
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
//}
|
|
//}
|
|
|
|
|
+
|
|
|
+ (sqlite3*) get_db
|
|
+ (sqlite3*) get_db
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // if(dblock==nil)
|
|
|
|
|
+ // dblock= [[NSLock alloc] init];
|
|
|
|
|
+ // [dblock lock];
|
|
|
|
|
+
|
|
|
sqlite3* db = nil;
|
|
sqlite3* db = nil;
|
|
|
|
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
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];
|
|
NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
|
|
|
DebugLog(@"DB path:%@",database_path);
|
|
DebugLog(@"DB path:%@",database_path);
|
|
|
|
|
+ count_dbconn++;
|
|
|
|
|
+ NSLog(@"current dbconn: %d",count_dbconn);
|
|
|
if (sqlite3_open([database_path UTF8String], &db) != SQLITE_OK) {
|
|
if (sqlite3_open([database_path UTF8String], &db) != SQLITE_OK) {
|
|
|
|
|
|
|
|
DebugLog(@"sqlite3_open failed. msg:%s",sqlite3_errmsg(db));
|
|
DebugLog(@"sqlite3_open failed. msg:%s",sqlite3_errmsg(db));
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return 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
|
|
+ (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];
|
|
// NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
|
|
|
// DebugLog(@"DB path:%@",database_path);
|
|
// DebugLog(@"DB path:%@",database_path);
|
|
|
|
|
+ count_dbconn++;
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"current dbconn: %d",count_dbconn);
|
|
|
if (sqlite3_open([path UTF8String], &db) != SQLITE_OK) {
|
|
if (sqlite3_open([path UTF8String], &db) != SQLITE_OK) {
|
|
|
|
|
|
|
|
DebugLog(@"sqlite3_open failed. msg:%s",sqlite3_errmsg(db));
|
|
DebugLog(@"sqlite3_open failed. msg:%s",sqlite3_errmsg(db));
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return db;
|
|
return db;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -429,7 +462,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
// sqlite3 *db = [self get_db];
|
|
// sqlite3 *db = [self get_db];
|
|
|
//
|
|
//
|
|
|
// [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db: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];
|
|
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:@"http://" withString:@""];
|
|
|
path=[path stringByReplacingOccurrencesOfString:name 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)
|
|
if(path.length==0)
|
|
@@ -499,7 +532,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
// sqlite3 *db = [self get_db];
|
|
// sqlite3 *db = [self get_db];
|
|
|
//
|
|
//
|
|
|
// [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db: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];
|
|
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:@"https://" withString:@""];
|
|
|
path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
|
|
path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
|
|
|
-// path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
|
|
|
|
|
|
|
+ // path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
|
|
|
|
|
|
|
|
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
|
|
|
|
|
@@ -557,13 +590,14 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
// sqlite3_finalize(statement);
|
|
// sqlite3_finalize(statement);
|
|
|
|
|
|
|
|
|
|
|
|
|
- // sqlite3_close(db);
|
|
|
|
|
|
|
+ // [iSalesDB close_db:db];
|
|
|
return data;
|
|
return data;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
+ (int) initializeDb {
|
|
+ (int) initializeDb {
|
|
|
DebugLog (@"initializeDB");
|
|
DebugLog (@"initializeDB");
|
|
|
-
|
|
|
|
|
|
|
+ count_dbconn=0;
|
|
|
|
|
+ //count_tmpdbconn=0;
|
|
|
// return false;
|
|
// return false;
|
|
|
//
|
|
//
|
|
|
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
// 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])
|
|
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";
|
|
NSString* alter_search_history = @"ALTER TABLE offline_login ADD can_update_contact_info integer";
|
|
|
[self execSql:alter_search_history db:db];
|
|
[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
|
|
+(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 msg:%s",sqlite3_errmsg(db));
|
|
|
DebugLog(@"sqlite3_exec failed sql:%@",sql);
|
|
DebugLog(@"sqlite3_exec failed sql:%@",sql);
|
|
|
ret= RESULT_FALSE;
|
|
ret= RESULT_FALSE;
|
|
|
- // sqlite3_close(db);
|
|
|
|
|
|
|
+ // [iSalesDB close_db:db];
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
|
|
+// int result=sqlite3_wal_checkpoint(db, NULL);
|
|
|
|
|
+// }
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
+ (NSDictionary*) search_pdf:(int) offset limit:(int)limit keywords:(NSString*) keywords
|
|
+ (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"];
|
|
[json setValue:@"2" forKey:@"result"];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
return json;
|
|
return json;
|
|
|
}
|
|
}
|
|
|
+(int)execSql:(NSString *)sql
|
|
+(int)execSql:(NSString *)sql
|
|
@@ -771,7 +811,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
sqlite3 *db = [self get_db];
|
|
sqlite3 *db = [self get_db];
|
|
|
int ret=[self execSql:sql db:db];
|
|
int ret=[self execSql:sql db:db];
|
|
|
|
|
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
+ (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause
|
|
+ (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_finalize(statement);
|
|
|
}
|
|
}
|
|
|
- // sqlite3_close(db);
|
|
|
|
|
|
|
+ // [iSalesDB close_db:db];
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
+ (int) get_recordid:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby
|
|
+ (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_finalize(statement);
|
|
|
}
|
|
}
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -891,7 +931,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
|
|
|
|
|
sqlite3_finalize(statement);
|
|
sqlite3_finalize(statement);
|
|
|
}
|
|
}
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
|
|
|
|
|
|
|
|
|
|
return [dic copy];
|
|
return [dic copy];
|
|
@@ -913,7 +953,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
|
|
|
|
|
sqlite3_finalize(statement);
|
|
sqlite3_finalize(statement);
|
|
|
}
|
|
}
|
|
|
- sqlite3_close(db);
|
|
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|