|
@@ -11,6 +11,31 @@
|
|
|
#import "AppDelegate.h"
|
|
#import "AppDelegate.h"
|
|
|
@implementation iSalesDB
|
|
@implementation iSalesDB
|
|
|
|
|
|
|
|
|
|
++(BOOL)checkForField:(NSString *)table field:(NSString *)field db:(sqlite3 *)db
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ sqlite3_stmt *stmt;
|
|
|
|
|
+ NSString *sql = [NSString stringWithFormat:@"PRAGMA table_info(%@)",table];
|
|
|
|
|
+ if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, NULL) == SQLITE_OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ while(sqlite3_step(stmt) == SQLITE_ROW)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *fieldName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
|
|
|
|
|
+ if([field isEqualToString:fieldName])
|
|
|
|
|
+ {
|
|
|
|
|
+ sqlite3_finalize(stmt);
|
|
|
|
|
+ return YES;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return NO;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
void encryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
void encryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
assert(argc == 1);
|
|
assert(argc == 1);
|
|
|
switch (sqlite3_value_type(argv[0])){
|
|
switch (sqlite3_value_type(argv[0])){
|
|
@@ -132,198 +157,198 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-+(void)testdata
|
|
|
|
|
-{
|
|
|
|
|
-
|
|
|
|
|
- //---------------- init db --------------------
|
|
|
|
|
- // NSString* date;
|
|
|
|
|
- // NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
|
|
|
|
|
- // [formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"];
|
|
|
|
|
- // date = [formatter stringFromDate:[NSDate date]];
|
|
|
|
|
- //
|
|
|
|
|
- // NSString* dbname=[NSString stringWithFormat:@"%@.db",date];
|
|
|
|
|
- //
|
|
|
|
|
- // DebugLog (@"initializeDB");
|
|
|
|
|
- //
|
|
|
|
|
- // // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
- // NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];//[paths objectAtIndex:0];
|
|
|
|
|
- // NSString *database_path = [documents stringByAppendingPathComponent:dbname];
|
|
|
|
|
- //
|
|
|
|
|
- //
|
|
|
|
|
- // // move db file from document to cache ;
|
|
|
|
|
- // // NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
|
- // NSString *documentFolderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] ;//[searchPaths objectAtIndex: 0];
|
|
|
|
|
- // NSString* dbFilePath = [documentFolderPath stringByAppendingPathComponent:dbname];
|
|
|
|
|
- // if ([[NSFileManager defaultManager] fileExistsAtPath: dbFilePath])
|
|
|
|
|
- // {
|
|
|
|
|
- // [[NSFileManager defaultManager] moveItemAtPath:dbFilePath toPath:database_path error:nil];
|
|
|
|
|
- //
|
|
|
|
|
- // }
|
|
|
|
|
- // // 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;";
|
|
|
|
|
- NSString* drop_category =@"DROP TABLE IF EXISTS category;";
|
|
|
|
|
- NSString* drop_login =@"DROP TABLE IF EXISTS offline_login;";
|
|
|
|
|
- NSString* drop_cart =@"DROP TABLE IF EXISTS offline_cart;";
|
|
|
|
|
- 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];
|
|
|
|
|
- [iSalesDB execSql:drop_category db:db];
|
|
|
|
|
- [iSalesDB execSql:drop_login db:db];
|
|
|
|
|
- [iSalesDB execSql:drop_cart db:db];
|
|
|
|
|
- [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];
|
|
|
|
|
- // [self execSql:create_search_history db:db];
|
|
|
|
|
- // [self execSql:create_push_message db:db];
|
|
|
|
|
- // [self execSql:create_favorites db:db];
|
|
|
|
|
- // [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";
|
|
|
|
|
- // [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);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- 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);
|
|
|
|
|
-
|
|
|
|
|
- CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
|
|
|
|
|
-
|
|
|
|
|
- // ((double)(begintime-endtime))/(1000*1000);
|
|
|
|
|
- NSLog(@"time cost: %0.3f", end - start);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
|
|
+//+(void)testdata
|
|
|
|
|
+//{
|
|
|
|
|
+//
|
|
|
|
|
+// //---------------- init db --------------------
|
|
|
|
|
+// // NSString* date;
|
|
|
|
|
+// // NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
|
|
|
|
|
+// // [formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"];
|
|
|
|
|
+// // date = [formatter stringFromDate:[NSDate date]];
|
|
|
|
|
+// //
|
|
|
|
|
+// // NSString* dbname=[NSString stringWithFormat:@"%@.db",date];
|
|
|
|
|
+// //
|
|
|
|
|
+// // DebugLog (@"initializeDB");
|
|
|
|
|
+// //
|
|
|
|
|
+// // // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+// // NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];//[paths objectAtIndex:0];
|
|
|
|
|
+// // NSString *database_path = [documents stringByAppendingPathComponent:dbname];
|
|
|
|
|
+// //
|
|
|
|
|
+// //
|
|
|
|
|
+// // // move db file from document to cache ;
|
|
|
|
|
+// // // NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+// // NSString *documentFolderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] ;//[searchPaths objectAtIndex: 0];
|
|
|
|
|
+// // NSString* dbFilePath = [documentFolderPath stringByAppendingPathComponent:dbname];
|
|
|
|
|
+// // if ([[NSFileManager defaultManager] fileExistsAtPath: dbFilePath])
|
|
|
|
|
+// // {
|
|
|
|
|
+// // [[NSFileManager defaultManager] moveItemAtPath:dbFilePath toPath:database_path error:nil];
|
|
|
|
|
+// //
|
|
|
|
|
+// // }
|
|
|
|
|
+// // // 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;";
|
|
|
|
|
+// NSString* drop_category =@"DROP TABLE IF EXISTS category;";
|
|
|
|
|
+// NSString* drop_login =@"DROP TABLE IF EXISTS offline_login;";
|
|
|
|
|
+// NSString* drop_cart =@"DROP TABLE IF EXISTS offline_cart;";
|
|
|
|
|
+// 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];
|
|
|
|
|
+// [iSalesDB execSql:drop_category db:db];
|
|
|
|
|
+// [iSalesDB execSql:drop_login db:db];
|
|
|
|
|
+// [iSalesDB execSql:drop_cart db:db];
|
|
|
|
|
+// [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];
|
|
|
|
|
+// // [self execSql:create_search_history db:db];
|
|
|
|
|
+// // [self execSql:create_push_message db:db];
|
|
|
|
|
+// // [self execSql:create_favorites db:db];
|
|
|
|
|
+// // [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";
|
|
|
|
|
+// // [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);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// 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);
|
|
|
|
|
+//
|
|
|
|
|
+// CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
|
|
|
|
|
+//
|
|
|
|
|
+// // ((double)(begintime-endtime))/(1000*1000);
|
|
|
|
|
+// NSLog(@"time cost: %0.3f", end - start);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//}
|
|
|
+ (sqlite3*) get_db
|
|
+ (sqlite3*) get_db
|
|
|
{
|
|
{
|
|
|
sqlite3* db = nil;
|
|
sqlite3* db = nil;
|
|
@@ -580,9 +605,9 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
NSString* create_offline_setting=@"CREATE TABLE IF NOT EXISTS offline_setting ( _id INTEGER PRIMARY KEY, name VARCHAR(20),value VARCHAR(40));";
|
|
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, mode VARCHAR(20), default_price text, price text, user_id integer);";
|
|
|
|
|
|
|
+ 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), 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, order_id text not null,status integer, general_notes TEXT ,internal_notes text,signature text,user_type integer,contact_id text,sales_code TEXT,user_id integer, create_time TIMESTAMP default (datetime('now', 'localtime')));";
|
|
|
|
|
|
|
+ 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')));";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -629,11 +654,11 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
|
|
|
|
|
[self execSql:create_login_info db:db];
|
|
[self execSql:create_login_info db:db];
|
|
|
|
|
|
|
|
- // if( ![self checkForField:@"search_history" field:@"level" db:db])
|
|
|
|
|
- // {
|
|
|
|
|
- // NSString* alter_search_history = @"ALTER TABLE search_history ADD level INTEGER";
|
|
|
|
|
- // [self execSql:alter_search_history 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];
|
|
|
|
|
+ }
|
|
|
// NSTimeInterval time=[[NSDate date] timeIntervalSince1970];
|
|
// NSTimeInterval time=[[NSDate date] timeIntervalSince1970];
|
|
|
// double t = time-2592000; //NSTimeInterval返回的是double类型
|
|
// double t = time-2592000; //NSTimeInterval返回的是double类型
|
|
|
// NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
// NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|