首页 \ 问答 \ ActiveRecord中的SQL错误(SQL error in ActiveRecord)

ActiveRecord中的SQL错误(SQL error in ActiveRecord)

嗨我正在使用rails和活动记录,我的活动记录查询存在一些问题。

session[:profile_ids] = [2,4,5]  
@profiles = UserProfile.where("key = ? and id in (?)", 'Noc_Address',
     session[:profile_ids])

但我收到此错误:

Mysql::Error: You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 
'key = 'Noc_Address')' at line 1: SELECT `user_profiles`.* FROM 
`user_profiles`  WHERE (id in (361) and key = 'Noc_Address')

我怎么纠正它?

谢谢。


Hi i am using rails and active record and there is some problem with my active record query.

session[:profile_ids] = [2,4,5]  
@profiles = UserProfile.where("key = ? and id in (?)", 'Noc_Address',
     session[:profile_ids])

But i receive this error:

Mysql::Error: You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 
'key = 'Noc_Address')' at line 1: SELECT `user_profiles`.* FROM 
`user_profiles`  WHERE (id in (361) and key = 'Noc_Address')

How i can correct it?

Thanks.


原文:https://stackoverflow.com/questions/10927763
更新时间:2022-10-16 13:10

最满意答案

1.在虚拟终端中使用date命令来查看和设置系统时间
查看系统时钟的操作:
# date
设置系统时钟的操作:
# date 091713272003.30
通用的设置格式:
# date 月日时分年.秒
2.使用hwclock或clock命令查看和设置硬件时钟
查看硬件时钟的操作:
# hwclock --show 或
# clock --show
2003年09月17日 星期三 13时24分11秒 -0.482735 seconds
设置硬件时钟的操作:
# hwclock --set --date="09/17/2003 13:26:00"
或者
# clock --set --date="09/17/2003 13:26:00"
通用的设置格式:hwclock/clock --set --date=“月/日/年 时:分:秒”。
3.同步系统时钟和硬件时钟
Linux系统(笔者使用的是Red Hat 8.0,其它系统没有做过实验)默认重启后,硬件时钟和系统时钟同步。如果不大方便重新启动的话(服务器通常很少重启),使用clock或hwclock命令来同步系统时钟和硬件时钟。
硬件时钟与系统时钟同步:
# hwclock --hctosys
或者
# clock --hctosys
上面命令中,--hctosys表示Hardware Clock to SYStem clock。
系统时钟和硬件时钟同步:
# hwclock --systohc
或者
# clock --systohc
使用图形化系统设置工具设置时间
对于初学者来,笔者推荐使用图形化的时钟设置工具,如Red Hat 8.0中的日期与时间设置工具,可以在虚拟终端中键“redhat-config-time”命令,或者选择“K选单/系统设置/日期与时间”来启动日期时间设置工具。使用该工具不必考虑系统时间和硬件时间,只需从该对话框中设置日期时间,可同时设置、修改系统时钟和硬件时钟。
Internet同步时钟设置

在Windows XP日期与时间设置中有一项与Internet同步的功能,有了这项功能只要上网便可得到十分准确的时间。Red Hat 8.0也提供了这样的功能,在日期与时间设置工具对话框中的下部,有一个“启用网络时间协议”的选项,将该项选中就可以使用网络时间协议来同步Linux 系统时钟。选中该项后,其下面的服务器下拉列表框就变为可用状态,可从中选择一个时间服务器作为远程时间服务器。然后单击确定按钮,便可连接所设定的时间服务器,并与之同步时间。

其他回答

linux系统修改系统时间与时区的方法一:
修改系统时间。
linux系统时钟有两个,一个是硬件时钟,即bios时间,就是我们进行cmos设置时看到的时间,另一个是系统时钟,是linux系统kernel时间。当linux启动时,系统kernel会去读取硬件时钟的设置,然后系统时钟就会独立于硬件运作。有时我们会发现系统时钟和硬件时钟不一致,因此需要执行时间同步,下面就分享一下时间设置及时钟同步的命令使用方法。
date命令将日期设置为2015年6月18日
---- date -s 06/18/14
将时间设置为14点20分50秒
---- date -s 14:20:50
将时间设置为2015年6月18日14点16分30秒(mmddhhmm.ss)
----date 0618141614.30

2 hwclock/clock 命令查看、设置硬件时间
查看系统硬件时钟
hwclock --show 或者
clock --show
设置硬件时间
hwclock --set --date="06/18/14 14:55" (月/日/年时:分:秒)或者# clock --set --date="06/18/14 14:55" (月/日/年时:分:秒)
3 同步系统及硬件时钟。
下图中可以看到硬件和系统时钟相差半小时。可以使用hwclock或者clock进行同步,
硬件时钟与系统时钟同步:
# hwclock --hctosys 或者 # clock --hctosys hc代表硬件时间,sys代表系统时间,即用硬件时钟同步系统时钟
系统时钟和硬件时钟同步:
# hwclock --systohc或者# clock --systohc 即用系统时钟同步硬件时钟

linux系统修改系统时间与时区的方法二:
时区设置:
开始设置时区时,参考网上的资料,使用tzselect 命令来进行,结果发现tzselect命令只是告诉了设置时区的方法,而并不是真的去修改/etc/sysconfig/clock这个文件。换句话说就是tzselect命令仅仅告诉我们通过设置tz这个环境变量来选择的时区,然后将变量添加到.profile文件中。下面就简单介绍一下如何使用tzselect命令设置时区,以及如何通过修改/etc/sysconfig/clock配置文件来设置时区。
tzselect:
执行tzselect命令-->选择asia-->选择china-->选择east china - beijing, guangdong, shanghai, etc-->然后输入1。过程如下图:

执行完tzselect命令选择时区后,时区并没有更改,只是在命令最后提示你可以执行tz='asia/shanghai'; export tz 并将这行命令添加到.profile中,然后退出并重新登录。参考下图中date命令看到的结果,最终时区显示为cst,即中国标准时间。

修改配置文件来修改时区1、修改/etc/sysconfig/clock zone=asia/shanghai
2、rm /etc/localtime3、链接到上海时区文件
ln -sf /usr/share/zoneinfo/asia/shanghai /etc/localtime
执行完上述过程后,重启机器,即可看到时区已经更改。

相关问答

更多
  • Python设置环境变量的具体方法: 在系统变量里找到PATH,双击PATH
  • 可以使用date命令。date用于打印或设置系统日期和时间。 设置系统时间需要root权限。用法示例: 设置系统日期成2015年08月13日,这样会把具体时间设置清空成00:00:00 $ sudo date -s 20150813 设置系统时间为12:23:23 $ sudo date -s 12:23:23 同时设置日期和时间 $ sudo date -s "20150813 12:12:23″ 注意:由于日期和时间之间有空格,所以必须用引号引起来,否则命令会报错。 上述修改只是修改了linux的系统时 ...
  • Linux怎样修改系统时间 修改linux的时间可以使用date指令 修改日期: 时间设定成2009年5月10日的命令如下: #date -s 05/10/2009 修改时间: 将系统时间设定成上午10点18分0秒的命令如下。 #date -s 10:18:00 修改时区: 找到相应的时区文件 /usr/share/zoneinfo/Asia/Shanghai替换当前的/etc/localtime。 修改/etc/sysconfig/clock文件的内容为: ZONE=”Asia/Shanghai” UTC ...
  • linux系统修改系统时间与时区的方法一: 修改系统时间。 linux系统时钟有两个,一个是硬件时钟,即BIOS时间,就是我们进行CMOS设置时看到的时间,另一个是系统时钟,是linux系统Kernel时间。当Linux启动时,系统Kernel会去读取硬件时钟的设置,然后系统时钟就会独立于硬件运作。有时我们会发现系统时钟和硬件时钟不一致,因此需要执行时间同步,下面就分享一下时间设置及时钟同步的命令使用方法。 date命令将日期设置为2015年6月18日 ---- date -s 06/18/14 将时间设置 ...
  • 1.在虚拟终端中使用date命令来查看和设置系统时间 查看系统时钟的操作: # date 设置系统时钟的操作: # date 091713272003.30 通用的设置格式: # date 月日时分年.秒 2.使用hwclock或clock命令查看和设置硬件时钟 查看硬件时钟的操作: # hwclock --show 或 # clock --show 2003年09月17日 星期三 13时24分11秒 -0.482735 seconds 设置硬件时钟的操作: # hwclock --set --date=" ...
  • 更改双系统的启动顺序和等待时间,可以使用windows系统登录后,在电脑启动属性设置中更改默认启动系统选项,同时将等待时间进行调整。 更改方法可以参考如下步骤: 1、先进入你的windows系统,然后鼠标右键点击我的电脑,弹出菜单选择“属性”; 2、然后在系统管理窗口,单击左侧列表中的“高级系统设置”进入系统属性高级设置; 3、在系统属性窗口,点击“高级”选项卡下的“设置”按钮,进入系统启动具体设置; 4、至此,我们会在“启动和故障恢复”窗口,看一个“默认操作系统”的选项,如果你是双系统,在这个下拉列表中, ...
  • 没有任何内置功能,因为这种特定格式并不是表示时间的常用方式。 不过,构建自己的转换器真的很容易: import time def current_time_as_float(): lt = time.localtime() return ((lt.tm_sec / 60.) + lt.tm_min / 60.) + lt.tm_hour There's nothing built-in, as that particular format is not exactly a common w ...
  • 这可以通过一个简单的设计来解决,其中客户端由jqueries处理并使用java脚本,在用于升级系统数据的update shell命令中。 This could be resolved adopting to a simple design where client side is handled by jqueries and use of java scripts, in the update shell commands used to upgrade the system data.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)