Skip to content

Instantly share code, notes, and snippets.

@Superlokkus
Created September 14, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Superlokkus/ea4a28e197fea67cec4e to your computer and use it in GitHub Desktop.
Save Superlokkus/ea4a28e197fea67cec4e to your computer and use it in GitHub Desktop.
odb view statement-cache.txx compile-time bug
Error 3 error C2514: 'odb::mssql::object_statements<odb::access::object_traits<type>::object_type>' : class has no constructors c:\users\klm\downloads\libodb-mssql-2.4.0\odb\mssql\statement-cache.txx 36 1 odb_playground
Error 2 error C2440: 'static_cast' : cannot convert from 'odb::mssql::statements_base' to 'statements_type &' c:\users\klm\downloads\libodb-mssql-2.4.0\odb\mssql\statement-cache.txx 33 1 odb_playground
// odb_playground.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <memory>
#include <thread>
#include <string>
#include <locale>
#include <codecvt>
#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 "type-odb.hxx"
#include "view-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::unique_ptr<odb::database> db(
new odb::mssql::database("dsn=mddb_local_32", odb::mssql::isolation_read_committed, static_cast<SQLHENV>(0), connection_factory)
);
{
odb::session s;
odb::transaction t(db->begin());
odb::result<type_view> result(
db->query <type_view>());
for (auto i : result){
std::cout << i.in_view_type->name << "\n";
}
}
}
catch (const odb::database_exception &e) {
std::cout << "ODB database error: " << e.what() << std::endl;
}
return 0;
}
/*! @file type.h
To be compiled first with the odb compiler
*/
#ifndef TYPE_H
#define TYPE_H
#include <string>
#include <memory>
#include <odb/core.hxx>
#pragma db object table("type") session pointer(std::shared_ptr<type>)
class type
{
public:
#pragma db column("test_id") type("tinyint") not_null id
int8_t test_id;
#pragma db column("test_string") type("char(2)") not_null
std::string name;
type() : test_id(0) {}
};
#endif
/*! @file view.h
To be compiled first with the odb compiler
*/
#ifndef VIEW_H
#define VIEW_H
#include <memory>
#include <odb/core.hxx>
#include "type.h"
#pragma db view object(type)
class type_view{
public:
std::shared_ptr<type> in_view_type;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment