0

私は最初の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;
}

もちろん、overview_record.h を ODB コンパイルしましたodb.exe --database mssql overview_record.h(そうしないと、.hxx はありません)。db->query<overview_record>();しかし、デフォルトで構築された結果をインスタンス化することはできますが、行によって次のコンパイラ エラーが発生します。

エラー 3 エラー C2504: 'odb::result_base': ベース クラスが定義されていません c:\users\klm\downloads\libodb-2.4.0\odb\result.hxx 76 1 odb_playground

エラー 4 エラー C2027: 未定義の型 'odb::result_base' の使用 c:\users\klm\downloads\libodb-2.4.0\odb\result.hxx 82 1 odb_playground

エラー 5 エラー C2146: 構文エラー: ';' がありません 識別子「value_type」の前 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: 'odb::result::value_type' は 'odb::result' の基本クラスのメンバーではありません c:\users\klm\downloads\libodb-2.4.0\odb\result.hxx 82 1 odb_遊び場

エラー 8 エラー C2868: 'odb::result::value_type': using-declaration の構文が正しくありません。予想される修飾名 c:\users\klm\downloads\libodb-2.4.0\odb\result.hxx 82 1 odb_playground

エラー 9 エラー C2027: 未定義の型 'odb::result_base' の使用 c:\users\klm\downloads\libodb-2.4.0\odb\result.hxx 93 1 odb_playground

エラー 10 エラー C2146: 構文エラー: ';' がありません 識別子「result_impl_type」の前 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: 'odb::result::result_impl_type' は 'odb::result' の基本クラスのメンバーではありません c:\users\klm\downloads\libodb-2.4.0\odb\result.hxx 93 1 odb_遊び場

エラー 13 エラー C2868: 'odb::result::result_impl_type': using-declaration の構文が正しくありません。予想される修飾名 c:\users\klm\downloads\libodb-2.4.0\odb\result.hxx 93 1 odb_playground

4

1 に答える 1

1

問題は、odb コンパイラのフラグの欠落でした。この場合は、-qeg--generate-queryフラグです。そうしないと、odb は生成されたファイルに必要なコードを追加しません。

したがって、正しい呼び出しは次のようになりますodb.exe -q --database mssql overview_record.h

于 2015-08-24T14:21:29.900 に答える