我正在重构一些旧代码并偶然发现了这个命名查询(它在 mysql 之上使用 hibernate):
delete F from
foo F
inner join user DU on F.user_id = DU.id
where
(COALESCE(:userAlternateId,null) is null or DU.alternate_id like :userAlternateId )
and ( COALESCE(:fooId,null) is null or F.foo_id like :fooId )
and (
( COALESCE(:fromUpdated,null) is null or F.updated_at>=:fromUpdated )
and ( COALESCE(:toUpdated,null) is null or F.updated_at<=:toUpdated )
)
Run Code Online (Sandbox Code Playgroud)
我不明白为什么COALESCE要以这种方式使用它:
COALESCE(:userAlternateId,null) is null
这是性能黑客还是它使查询数据库独立还是......?
顺便说一句userAlternateId,是字符串/varchar,其他 id 是长整型和from-to日期
我有这个构造函数抛出异常
GenericSocket::GenericSocket(const string& hostname,
const string& servname):
_hostname(hostname),
_servname(servname)
{
initHints();
int rv;
if((rv = getaddrinfo(_hostname.c_str(),
_servname.c_str(),
&_hints,
&_servinfo)) != 0) {
throw GenericSocketException();
}
}
Run Code Online (Sandbox Code Playgroud)
initHints()执行_hints的memset并设置一些变量.
我用google测试框架测试它,如下所示:
TEST(CreateObject2, getaddrinfoException)
{
mgs_addrinfo_return = 1;
ASSERT_THROW(new GenericSocket("testhost", "4242"), GenericSocketException);
}
Run Code Online (Sandbox Code Playgroud)
测试因核心转储失败:
[ RUN ] CreateObject2.getaddrinfoException
socket creation failed
terminate called after throwing an instance of 'common::GenericSocketException'
what(): Socket creation failed
[1] 43360 abort (core dumped) ./bin/test_common
Run Code Online (Sandbox Code Playgroud)
除了我不知道到底出了什么问题的事实,我怀疑一些未初始化的对象被删除(?),很多似乎发生在幕后,所以我开始怀疑在构造函数中抛出异常是否是好习惯.是否可以更好地将此功能放在另一个我可以在创建对象后调用的函数中,然后处理异常?
什么是CQL等价物:INCR MyCounter ['123'] ['test'] BY 1