[odb-users] Assumed bug in odb::query in_range when range is empty
Markus Klemm
markus at markusklemm.net
Mon Sep 14 05:26:47 EDT 2015
Hi everyone,
I think I found a bug in odb::query<>::field:in_range(begin,end) :
If the given range is empty i.e. begin == end, the resulting sql query ("WHERE [type].[field] IN ()") is malformend or at least MS SQL server does not like it.
It's basiclly the bug I encountered in the last messages of the mail thread ("ORDER BY clause in ODB query language"/Thu Sep 10 05:20:09 EDT 2015), but I minized it to the following code:
Full example/Gist with syntax-highlighting: https://gist.github.com/Superlokkus/e23a5be5bcebf738b1a0
#pragma db object table("files") bulk(5000) session pointer(std::shared_ptr<file>)
class file
{
public:
#pragma db column("file_id") type("uniqueidentifier") id not_null
boost::uuids::uuid file_id;
#pragma db column("file_name") type("nvarchar(256)") not_null
std::wstring file_name;
};
std::vector<decltype(file::file_id)> files;
odb::query<file> query = odb::query<file>::file_id.in_range(files.cbegin(), files.cend());
odb::session s;
odb::transaction t(db->begin());
t.tracer(odb::stderr_tracer);
odb::result<file> result(
db->query <file>(query));
for (const auto &f : result){
std::wcout << f.file_name << std::endl;
}
Output
"SELECT [files].[file_id], [files].[file_name] FROM [files] WHERE [files].[file_i
d] IN ()
ODB database error: 102 (42000): [Microsoft][SQL Server Native Client 11.0][SQL
Server]Falsche Syntax in der Nõhe von ')'.
8180 (42000): [Microsoft][SQL Server Native Client 11.0][SQL Server]Anweisung(en
) konnte(n) nicht vorbereitet werden."
Falsche Syntax in der Nõhe von ')'. == Wrong syntax near ')'
Anweisung(en) konnte(n) nicht vorbereitet werden. == Could not prepare query
I wish you a nice (or at least bearable) monday
Markus Klemm
More information about the odb-users
mailing list