Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建表的问题 #66

Open
flysec opened this issue Jul 3, 2019 · 2 comments
Open

建表的问题 #66

flysec opened this issue Jul 3, 2019 · 2 comments

Comments

@flysec
Copy link

flysec commented Jul 3, 2019

建表的时候,如果用jq_createTable创建表,会先转为dict再去创建sql。
如果model里有pkid, 并且转后的dict里,pkid在最后的话,会从continue走掉,建表的括号无法闭合。生成的sql如下:

CREATE TABLE device (pkid INTEGER PRIMARY KEY, udid TEXT, account_id INTEGER, server_id INTEGER, login_at INTEGER,

代码如下:
NSMutableString *fieldStr = [[NSMutableString alloc] initWithFormat:@"CREATE TABLE %@ (pkid INTEGER PRIMARY KEY,", tableName];

int keyCount = 0;
for (NSString *key in dic) {
    
    keyCount++;
    if ((nameArr && [nameArr containsObject:key]) || [key isEqualToString:@"pkid"]) {
        continue;//问题出在这里,这里如果pkid是最后一个字段,就跳出去了,无法闭合括号
    }
    if (keyCount == dic.count) {
        [fieldStr appendFormat:@" %@ %@)", key, dic[key]];
        break;
    }
    
    [fieldStr appendFormat:@" %@ %@,", key, dic[key]];
}
@zhangchuanwei
Copy link

大兄弟你解决了吗?

@tianshangtian
Copy link

if ([fieldStr hasSuffix:@","]) {
[fieldStr replaceCharactersInRange:NSMakeRange(fieldStr.length-1, 1) withString:@")"];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants