首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >odb::result<my_type>的不变性,例如odb::query<my_type>失败

odb::result<my_type>的不变性,例如odb::query<my_type>失败
EN

Stack Overflow用户
提问于 2015-08-21 14:47:28
回答 1查看 487关注 0票数 0

我正在编写我的第一个odb代码,虽然只有db连接代码才能工作,但无法完成这个基本工作:

代码语言:javascript
复制
/*! @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

司机代码:

代码语言:javascript
复制
    // 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编译了odb.exe --database mssql overview_record.h(否则不会有.hxx)。但是,我通过行db->query<overview_record>();得到以下编译器错误,尽管实例化默认构造的结果是有效的:

错误3错误C2504:'odb::result_base‘:基类未定义的odb_playground 76 1 odb_playground 错误4错误C2027:未定义类型“odb::result_base”C2027 82 1 odb_playground的使用 错误5错误C2146:语法错误:缺少';‘标识符'value_type’之前的‘value_type’821 odb_playground 错误6错误C4430:缺少类型说明符- int假设。注意: C++不支持默认-int C++ 82 1 odb_playground 错误7错误C2602:'odb::result::value_type‘不是’odb::odb::result::value_type‘的基类的成员 错误8错误C2868:'odb::result::value_type‘:使用-声明的非法语法;预期的限定名C2868 82 1 odb_playground 错误9错误C2027:未定义类型'odb::result_base‘odb::result_base 931 odb_playground的使用 错误10错误C2146:语法错误:缺失;标识符'result_impl_type‘之前的’result_impl_type‘931 odb_playground 错误11错误C4430:缺少类型说明符- int假设。注意: C++不支持默认-int C++ 93 1 odb_playground 错误12错误C2602:'odb::result::result_impl_type‘不是’odb::odb::result::result_impl_type‘odb_playground基类的成员 错误13错误C2868:'odb::result::result_impl_type‘:使用-声明的非法语法;预期限定名为odb::result::result_impl_type 931 odb_playground

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-24 14:21:29

问题是缺少了odb编译器的标志,在本例中是-q (例如--generate-query标志)。否则odb将不会将所需的代码添加到生成的文件中。

所以正确的调用应该是odb.exe -q --database mssql overview_record.h

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32143337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档