|
|
@@ -689,6 +689,11 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
|
|
|
//if(appDelegate.offline_mode)
|
|
|
{
|
|
|
+ /*************************ALTER TABLE From V1.4 to V1.5************************************/
|
|
|
+
|
|
|
+ [self alterTable:@"model" columns:@"product" rename:YES db:db]; // 需要在创建product之间改名
|
|
|
+
|
|
|
+
|
|
|
[self execSql:create_product db:db];
|
|
|
[self execSql:create_wishlist db:db];
|
|
|
[self execSql:create_price db:db];
|
|
|
@@ -724,7 +729,7 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
|
|
|
/*************************ALTER TABLE From V1.4 to V1.5************************************/
|
|
|
|
|
|
- [self alterTable:@"model" columns:@"product" rename:YES db:db];
|
|
|
+// [self alterTable:@"model" columns:@"product" rename:YES db:db];
|
|
|
|
|
|
[self alterTable:@"product" columns:@"has_bundle integer;is_active integer;item_id integer" rename:NO db:db];
|
|
|
|
|
|
@@ -1001,16 +1006,30 @@ void decryptfield (sqlite3_context *context, int argc, sqlite3_value **argv) {
|
|
|
|
|
|
if (rename) {
|
|
|
|
|
|
- NSString *check_table_exist = [NSString stringWithFormat:@"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='%@';",column_str_or_new_table_name];
|
|
|
- __block BOOL exist = NO;
|
|
|
- [self jk_query:check_table_exist db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+ NSString *check_new_table_exist = [NSString stringWithFormat:@"SELECT name FROM sqlite_master WHERE type='table' AND (name='%@' or name = '%@');",table,column_str_or_new_table_name];
|
|
|
+
|
|
|
+ __block BOOL new_exist = NO;
|
|
|
+ __block BOOL old_exist = NO;
|
|
|
+
|
|
|
+ [self jk_query:check_new_table_exist db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
+
|
|
|
+ const char *name = (char *)sqlite3_column_text(stmt, 0);
|
|
|
+ if (name == NULL) {
|
|
|
+ name = "";
|
|
|
+ }
|
|
|
+ NSString *nsname = [NSString stringWithUTF8String:name];
|
|
|
+
|
|
|
+ if (!old_exist)
|
|
|
+ old_exist = [nsname isEqualToString:table];
|
|
|
+
|
|
|
+ if (!new_exist)
|
|
|
+ new_exist = [nsname isEqualToString:column_str_or_new_table_name];
|
|
|
|
|
|
- int ct = sqlite3_column_int(stmt, 0);
|
|
|
- exist = ct ? YES : NO;
|
|
|
}];
|
|
|
|
|
|
- if (!exist) {
|
|
|
- NSString *rename_model_to_product = [NSString stringWithFormat:@"alter %@ rename to %@;",table,column_str_or_new_table_name];
|
|
|
+
|
|
|
+ if (!new_exist && old_exist) {
|
|
|
+ NSString *rename_model_to_product = [NSString stringWithFormat:@"alter table %@ rename to %@;",table,column_str_or_new_table_name];
|
|
|
[self execSql:rename_model_to_product db:db];
|
|
|
}
|
|
|
|