-
-
Save Superlokkus/e23a5be5bcebf738b1a0 to your computer and use it in GitHub Desktop.
ODB query::... in_range bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <ctime> | |
#include <memory> | |
#include <boost/date_time/posix_time/posix_time_types.hpp> | |
#include <boost/uuid/uuid.hpp> | |
#include <odb/core.hxx> | |
#include <boost/optional.hpp> | |
#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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <memory> | |
#include <thread> | |
#include <string> | |
#include <locale> | |
#include <codecvt> | |
#include <future> | |
#include <boost/date_time/posix_time/posix_time.hpp> | |
#include <boost/date_time/gregorian/gregorian.hpp> | |
#include <boost/uuid/uuid_io.hpp> | |
#include <odb/core.hxx> | |
#include <odb/database.hxx> | |
#include <odb/mssql/database.hxx> | |
#include <odb/mssql/connection-factory.hxx> | |
#include <odb/mssql/exceptions.hxx> | |
#include "file-odb.hxx" | |
int main(int argc, char* argv[]) | |
{ | |
try{ | |
std::auto_ptr<odb::mssql::connection_pool_factory> connection_factory( | |
new odb::mssql::connection_pool_factory(0, std::thread::hardware_concurrency())); | |
std::shared_ptr<odb::database> db( | |
new odb::mssql::database("dsn=mddb_local_32", odb::mssql::isolation_read_committed, static_cast<SQLHENV>(0), connection_factory) | |
); | |
{ | |
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; | |
} | |
} | |
} | |
catch (const odb::database_exception &e) { | |
std::cout << "ODB database error: " << e.what() << std::endl; | |
throw; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment