在使用关系数据库这么长时间之后,我真的很努力地理解这个新概念......
任何人都可以解释我应该如何存储说,类别层次结构?
在关系数据库中,我有:
类别:
CategoryId
ParentCategoryId
名称
或者那种性质的东西..
我正在从csv导入数据,我需要将一些值转换为BigDecimal,如果无法解析则会引发错误.
从测试开始,BigDecimal("无效数字")返回一个0的BigDecimal.这没关系,但有点凌乱,除了有效值为0 ...
Float("无效数字")的行为不同并抛出异常......
我目前的解决方案是:
class String
def to_bd
begin
Float(self)
rescue
raise "Unable to parse: #{self}"
end
BigDecimal(self)
end
end
Run Code Online (Sandbox Code Playgroud)
我完全错过了什么吗?
编辑:
我把我的mysql等待超时缩小到这一行:
IF @resultsFound > 0 THEN
INSERT INTO product_search_query (QueryText, CategoryId) VALUES (keywords, topLevelCategoryId);
END IF;
Run Code Online (Sandbox Code Playgroud)
知道为什么会导致问题吗?我无法解决这个问题!
嗨伙计们,我写了一个存储过程来搜索某些类别的产品,由于我遇到的某些限制,我无法做我想要的(限制,但仍然返回找到的总行数,排序等.)
这意味着将1,2,3 in的类别ID拆分为临时表,然后根据排序选项和限制构建全文搜索查询,执行查询字符串,然后选择结果总数.
现在,我知道我不是MySQL大师,离它很远,我已经有了它的工作,但我一直在等待产品搜索等等.所以我认为这可能会导致某种问题?
有没有人有任何想法如何我可以整理它,甚至以一种我可能不知道的更好的方式做到这一点?
谢谢..
DELIMITER $$
DROP PROCEDURE IF EXISTS `product_search` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `product_search`(keywords text, categories text, topLevelCategoryId int, sortOrder int, startOffset int, itemsToReturn int)
BEGIN
declare foundPos tinyint unsigned;
declare tmpTxt text;
declare delimLen tinyint unsigned;
declare element text;
declare resultingNum int unsigned;
drop temporary table if exists categoryIds;
create temporary table categoryIds
(
`CategoryId` int
) …Run Code Online (Sandbox Code Playgroud) 我是rails的新手,我正在尝试使用rspec测试控制器.我的第一个测试是在调用show动作时,它应该通过url查找Category.
问题是当我添加存根代码时,我收到以下错误:
未定义的方法`find'for#
我的测试看起来像这样:
require 'spec_helper'
describe CategoriesController do
describe "GET /category-name/" do
before(:each) do
@category = mock_model(Category)
Category.stub!(:find).with(:first, :conditions => ["url = :url", {:url => "category-name"}]).and_return(@category)
end
it "should find the category by url" do
controller.show
Category.should_receive(:find).with(:first, :conditions => ["url = :url", {:url => "category-name"}]).and_return(@category)
end
end
end
Run Code Online (Sandbox Code Playgroud)