我正在尝试在 Cocoa macOS 应用程序中使用 SQLite.swift 和 Swift 检索表中的记录数。根据README ,这可以使用以下方法实现:
let users = Table("users")
...
let count = try db.scalar(users.count)
但是,当执行此代码时(从按钮单击事件处理程序),将抛出以下异常:
Fatal error: 'try!' expression unexpectedly raised an error: unrecognized token: ":" (code: 1): file...
有问题的代码是下面的 db 访问行。 db 对象被分配了一个 Connection 对象,该对象在 View 加载时从一个单独的 Database 结构函数返回。我相信这是有效且无关的,因为其他代码区域正在使用相同的方法成功打开与数据库的连接。
let login = Login()
var db : Connection?
...
let count = try! db?.scalar(login.table.count)
这是它生成的查询表达式。在文本中,这似乎是 SELECT count(_:)(*) FROM login。
但是,有趣的是,如果我使用以下行,则会返回正确的结果。
let count = try! db?.scalar(“SELECT COUNT(*) FROM login”)
此 Login 对象的模型是:
import SQLite
public struct Login {
let table = Table("login")
// Bunch of properties for various record fields
init() {}
}
任何和所有帮助将不胜感激。提前致谢!
最佳答案
正如我所怀疑的那样,它原来是 SQLite.swift 本身的问题。几天前,我在 GitHub 上发现了以下报告此问题的 SQLite.swift 问题。
问题如下,据记者描述,tanzolone :
In Xcode 10.2 beta 4 the macro#functionshows a different behaviour. As SQLite.swift relies on #function in different subroutines for the composition of SQLite queries, several bugs linked to invalid SQLite statements seem to be introduced.
I have just run the SQLite.swift tests with Xcode 10.2 beta 4 and there are several failures linked to this issue.
An example as follows: In the following helper function (Helpers.swift line 107):
func wrap<T>(_ expression: Expressible, function: String = #function) -> Expression<T> { return function.wrap(expression) }when called from
static func count(_ star: Star) -> Expression<UnderlyingType>the value of the function when running in Xcode 10.2 beta 4 is
count(_:)instead ofcount. This leads to invalid SQLite statements of the typeSELECT count(_:)(*) myTable.
项目维护人员现在已经在 master 的最新 HEAD 中解决了这个问题(当前为 1a908a7da11852f252e7c6b6366a4d9f8a7d5272)。
在我的项目中,需要更新的行在我的 Podfile 中如下:
pod 'SQLite.swift/SQLCipher', :git => 'https://github.com/stephencelis/SQLite.swift.git', :commit => 'ed8f603f856e9f1f4adb76b63b7234547257ec5a'
这已更新为:
pod 'SQLite.swift/SQLCipher', :git => 'https://github.com/stephencelis/SQLite.swift.git', :branch => 'master'
或者,可以引用提交本身:
pod 'SQLite.swift/SQLCipher', :git => 'https://github.com/stephencelis/SQLite.swift.git', :commit => '1a908a7da11852f252e7c6b6366a4d9f8a7d5272'
为了更新此引用,我在我的项目根目录中执行了以下 CLI 步骤来删除、更新和安装项目 pod:
$ pod cache clean --all
$ rm -rf Pods/
$ rm Podfile.lock
$ open -a Xcode Podfile # Updated the SQLite.swift project ref to the above
$ pod install
这就解决了问题,不再抛出异常。
关于swift - SQLite.swift:由于无法识别的 token 无法检索表计数: ":",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55755296/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我遵循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
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
似乎无法为此找到有效的答案。我正在阅读Rails教程的第10章第10.1.2节,但似乎无法使邮件程序预览正常工作。我发现处理错误的所有答案都与教程的不同部分相关,我假设我犯的错误正盯着我的脸。我已经完成并将教程中的代码复制/粘贴到相关文件中,但到目前为止,我还看不出我输入的内容与教程中的内容有什么区别。到目前为止,建议是在函数定义中添加或删除参数user,但这并没有解决问题。触发错误的url是http://localhost:3000/rails/mailers/user_mailer/account_activation.http://localhost:3000/rails/mai