在我的应用程序中,有多个线程访问数据库。我使用了 SQLite 包装器 FMDB。
我听说 FMDB 为我提供了通过 FMdatabaseQueue 处理多线程的功能。
因此,我使用它如下:
@property (nonatomic, strong) FMDatabaseQueue *queue;
_queue = [[FMDatabaseQueue alloc] initWithPath:path];
- (BOOL)deleteSchoolDatabase:(NSString *)name anduserId:(NSString*)studentId {
__block BOOL success = NO;
[self.queue inDatabase:^(FMDatabase *db) {
NSString *deleteStudentDBString = [NSString stringWithFormat:@"DELETE FROM user WHERE name=%@ AND studentId=%@",name,studentId,nil];
success = [db executeQuery:deleteStudentDBString];
NSAssert((![db hadError]), [db lastErrorMessage]);
if ([db hadError]) {
DebugLog(@"Error : %@", [db lastErrorMessage]);
success = NO;
}
}];
return success;
}
我也使用上述格式进行抓取,即
[self.queue inDatabase:^(FMDatabase *db) {
//fetch details
}];
但是现在我得到了错误
Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]
query: 'DELETE FROM user WHERE name='abc' AND studentId='12346';'
我还查看了以下链接: https://groups.google.com/forum/#!topic/fmdb/oeu38he7UvQ
而且我想一旦完成我就会关闭这个系列。仍然,错误正在发生。 这只发生在一张 table 上。在其他表中可以从数据库中删除数据。
提前致谢。
最佳答案
我能够解决我的问题。我使用了错误的方法来删除数据。 我们需要使用“executeUpdate”来删除数据。 因此,请检查您的查询是否正确。
- (BOOL)deleteSchoolDatabase:(NSString *)name anduserId:(NSString*)studentId {
__block BOOL success = NO;
[self.queue inDatabase:^(FMDatabase *db) {
NSString *deleteStudentDBString = [NSString stringWithFormat:@"DELETE FROM user WHERE name=%@ AND studentId=%@",name,studentId,nil];
success = [db executeUpdate:deleteStudentDBString];
NSAssert((![db hadError]), [db lastErrorMessage]);
if ([db hadError]) {
DebugLog(@"Error : %@", [db lastErrorMessage]);
success = NO;
}
}];
return success;
}
谢谢。
关于ios - 出现错误,因为在执行 [FMDatabaseQueue inDatabase :]? 之后至少有一个打开的结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41340005/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c