Git Product home page Git Product logo

Comments (3)

Haley-Wong avatar Haley-Wong commented on September 16, 2024

不好意思,才看到,解决了么?

发自 网易邮箱大师
在2015年12月14日 17:29,JiangYaLei 写道:

(BOOL)update
{
JKDBHelper *jkDB = [JKDBHelper shareInstance];
__block BOOL res = NO;
[jkDBdbQueue inDatabase:^(FMDatabase *db) {
NSString *tableName = NSStringFromClass(selfclass);
id primaryValue = [self valueForKey:primaryId];
if (!primaryValue || primaryValue <= 0) {
return ;
}
NSMutableString *keyString = [NSMutableString string];
NSMutableArray *updateValues = [NSMutableArray array];
for (int i = 0; i < selfcolumeNamescount; i++) {
NSString *proname = [selfcolumeNames objectAtIndex:i];
if ([proname isEqualToString:primaryId]) {
continue;
}
[keyString appendFormat:@" %@=?,", proname];
id value = [self valueForKey:proname];
if (!value) {
value = @"";
}
[updateValues addObject:value];
}

//删除最后那个逗号
[keyString deleteCharactersInRange:NSMakeRange(keyStringlength - 1, 1)];
NSString *sql = [NSString stringWithFormat:@"UPDATE %@ SET %@ WHERE %@ = ?;", tableName, keyString, primaryId];
[updateValues addObject:primaryValue];
res = [db executeUpdate:sql withArgumentsInArray:updateValues];
NSLog(res?@"更新成功":@"更新失败");

}];
return res;
}

打印更新成功,但是表中的数据没有变化,求解,在线急,你QQ是多少


Reply to this email directly or view it on GitHub.

from jkdbmodel.

hughdev avatar hughdev commented on September 16, 2024

解决了,更新模型的时候需要设置一下pk.问一下,saveorUpdate,这个方法什么时候我需要主动设置模型的pk吗?

from jkdbmodel.

Haley-Wong avatar Haley-Wong commented on September 16, 2024

这个方法其实内部是通过主键PK来判断,如果主键存在,则执行update,如果主键不存在,则执行save。所以要看你的数据pk是否有值~

from jkdbmodel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.