Comments (3)
不好意思,才看到,解决了么?
发自 网易邮箱大师
在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.
解决了,更新模型的时候需要设置一下pk.问一下,saveorUpdate,这个方法什么时候我需要主动设置模型的pk吗?
from jkdbmodel.
这个方法其实内部是通过主键PK来判断,如果主键存在,则执行update,如果主键不存在,则执行save。所以要看你的数据pk是否有值~
from jkdbmodel.
Related Issues (20)
- NSCoding
- 如何取得项目中已经存在的数据库文件
- 相同的数据save会重复插入数据库。是否可以插入的时候判断一下? HOT 2
- 切换文件夹后,怎么返回默认的文件夹呢 HOT 1
- 关于创建表的时机的问题 HOT 1
- 我存在的数据类型是float,比如3.14,但取出来却变成了3,求大神帮忙解决 HOT 1
- 关于查询的问题
- 无法 利用继承 ,添加父类的属性字段 到当前子类表中 HOT 3
- 个人对JKDB数组,float double 封装 HOT 6
- 主键问题
- 关于FMDBQueue的问题 HOT 2
- 关于查询数据的问题 HOT 1
- 不支持自定义主键
- 我往数据库存入了NSData数据类型,但是取出来的data却是空的 HOT 2
- 这个封装现在还维护吗?适合现在开发用吗? HOT 1
- 删除的方法有问题,删除肯定失败
- 查询有问题
- 异步update多条数据数据时,只update一条数据 HOT 1
- 老哥我想pull
- 请问,怎么给字段添加索引呢?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jkdbmodel.