似乎是 MySQL 的 Bug; 要求:
SELECT *
FROM table
WHERE (
id LIKE '%тест 199%'
OR `user` LIKE '%тест 199%'
OR `user_datetime` LIKE '%тест 199%'
OR `user_comments` LIKE '%тест 199%' )
ORDER BY id desc
LIMIT 0, 10
[Err] 1271 - 操作“like”的排序规则混合非法
当我们使用拉丁语时。 要求:
SELECT *
FROM table
WHERE (
id LIKE '%test 199%'
OR `user` LIKE '%test 199%'
OR `user_datetime` LIKE '%test 199%'
OR `user_comments` LIKE '%test 199%' )
ORDER BY id desc
LIMIT 0, 10
请求成功;
如何处理?
我所有的请求都是自动生成的,我不能改变逻辑因为函数生成器有很多依赖。
设置:
SET NAMES utf8
Character set utf8 -- UTF-8 Unicode
Collation utf8_general_ci
@eggyal 的UPD
Request:
SHOW CREATE TABLE `comments`
Response:
CREATE TABLE `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user` varchar(255) NOT NULL DEFAULT '',
`user_datetime` timestamp NULL DEFAULT NULL,
`user_comments` varchar(128) DEFAULT NULL,
UNIQUE KEY `id` (`id`) USING BTREE,
KEY `user_comments` (`user_comments`),
) ENGINE=InnoDB AUTO_INCREMENT=128456 DEFAULT CHARSET=utf8
MySQL 版本 5.5.10
最佳答案
您使用的是什么版本的 MySQL?如 the manual 中所述:
As of MySQL 5.5.3, implicit conversion of a numeric or temporal value to string produces a value that has a character set and collation determined by the
character_set_connectionandcollation_connectionsystem variables. (These variables commonly are set withSET NAMES. For information about connection character sets, see Section 10.1.4, “Connection Character Sets and Collations”.)This change means that such a conversion results in a character (nonbinary) string (a
CHAR,VARCHAR, orLONGTEXTvalue), except when the connection character set is set tobinary. In that case, the conversion result is a binary string (aBINARY,VARBINARY, orLONGBLOBvalue).Before MySQL 5.5.3, an implicit conversion always produced a binary string, regardless of the connection character set. Such implicit conversions to string typically occur for functions that are passed numeric or temporal values when string values are more usual, and thus could have effects beyond the type of the converted value.
因此,当使用 LIKE 运算符时,将 TIMESTAMP 列隐式转换为字符串将始终导致字符串binary 字符集,如果您使用的 MySQL 版本早于 5.5.3,则不考虑 SET NAMES(奇怪的是,sqlfiddle 也是如此,它声称是 5.5。 20);由于此类字符串无法与 utf8 字符集中的字符串进行比较,因此您必须将 user_datetime 列显式转换为 UTF-8 字符串:
SELECT *
FROM `comments`
WHERE (
`id` LIKE '%тест 199%'
OR `user` LIKE '%тест 199%'
OR CONVERT(`user_datetime` USING utf8) LIKE '%тест 199%'
OR `user_comments` LIKE '%тест 199%'
)
ORDER BY `id` DESC
LIMIT 0, 10
关于mysql - 运算符喜欢,字段类型时间戳和西里尔字母? MySQL错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10379299/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
请帮助我理解范围运算符...和..之间的区别,作为Ruby中使用的“触发器”。这是PragmaticProgrammersguidetoRuby中的一个示例:a=(11..20).collect{|i|(i%4==0)..(i%3==0)?i:nil}返回:[nil,12,nil,nil,nil,16,17,18,nil,20]还有:a=(11..20).collect{|i|(i%4==0)...(i%3==0)?i:nil}返回:[nil,12,13,14,15,16,17,18,nil,20] 最佳答案 触发器(又名f/f)是
我遵循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
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee