即时消息odb :: result <my_type>例如odb :: query <my_type>失败

时间:2015-08-21 14:47:29

标签: odb

我正在编写我的第一个odb代码并且无法使这个基本工作,尽管只有db连接代码可以工作:

/*! @file overview_record.h
*/
#ifndef OVERVIEW_RECORD_H
#define OVERVIEW_RECORD_H
#include <string>
#include <odb/core.hxx>
#include <odb/nullable.hxx>

#pragma db object table("mddb_overview") no_id 

    class overview_record
    {
    public:

#pragma db column("product_name") type("nvarchar(64)")
        std::wstring product_name;

#pragma db column("order_number") type("int")
        long order_number;
    };

#endif

驱动程序代码:

    // odb_playground.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <memory>
#include <thread>

#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 "overview_record-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::transaction t(db->begin());
        db->query<overview_record>();
        //odb::result<overview_record> result();
        //auto it = result.begin();
        //while(true)
        //{
        //  static int i = 0;
        //  if (i++ > 10)
        //      break;
        //  std::cout << "Order_number " << it->order_number << " product_name " << it->product_name << std::endl;
        //  ++i;

        //}
        t.commit();
    }
    catch (const odb::database_exception &e) {
        std::cout << "ODB database error: " << e.what() << std::endl;
    }
    return 0;
}

当然我用odb.exe --database mssql overview_record.h对overview_record.h进行了odb编译(否则就不会成为.hxx)。但是我通过行db->query<overview_record>();得到了以下编译器错误,尽管实例化默认构造结果有效:

  

错误3错误C2504:&#39; odb :: result_base&#39; :基类未定义c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 76 1 odb_playground

     

错误4错误C2027:使用未定义类型&#39; odb :: result_base&#39; c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 82 1 odb_playground

     

错误5错误C2146:语法错误:缺少&#39 ;;&#39;在标识符&#39; value_type&#39;之前c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 82 1 odb_playground

     

错误6错误C4430:缺少类型说明符 - 假定为int。注意:C ++不支持default-int c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 82 1 odb_playground

     

错误7错误C2602:&#39; odb :: result :: value_type&#39;不是&#39; odb :: result&#39;的基类的成员。 c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 82 1 odb_playground

     

错误8错误C2868:&#39; odb :: result :: value_type&#39; :using声明的非法语法;预期的限定名称c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 82 1 odb_playground

     

错误9错误C2027:使用未定义类型&#39; odb :: result_base&#39; c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 93 1 odb_playground

     

错误10错误C2146:语法错误:缺少&#39;;&#39;在标识符&#39; result_impl_type&#39;之前c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 93 1 odb_playground

     

错误11错误C4430:缺少类型说明符 - 假定为int。注意:C ++不支持default-int c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 93 1 odb_playground

     

错误12错误C2602:&#39; odb :: result :: result_impl_type&#39;不是&#39; odb :: result&#39;的基类的成员。 c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 93 1 odb_playground

     

错误13错误C2868:&#39; odb :: result :: result_impl_type&#39; :using声明的非法语法;期望的限定名称c:\ users \ klm \ downloads \ libodb-2.4.0 \ odb \ result.hxx 93 1 odb_playground

1 个答案:

答案 0 :(得分:1)

问题是odb编译器的缺失标志,在这种情况下是Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { finish(); } }, s * 1000); ,例如-q标志。否则odb不会将所需的代码添加到生成的文件中。

因此正确的调用将是--generate-query