[odb-users] Couldn't find method odb::database::id

Andy S gatekeeper.mail at gmail.com
Wed Jan 26 16:06:50 EST 2022


OS: Debian Bullseye
Compiler: g++-9
ODB version: 2.4.0

I have a model class:

-- InvType.h: --
#include <string>
#include <cstdint>
#include <odb/core.hxx>

#pragma db model version(1, 1)

#pragma db object table("invTypes")

class InvType {
public:
    InvType() = default;;

    uint16_t typeID() const {
        return typeID_;
    };
    void typeID(const uint16_t id_) {
        typeID_ = id_;
    };
    float basePrice() const {
        return basePrice_;
    };
    void basePrice(const float basePrice_v) {
        basePrice_ = basePrice_v;
    };

private:
    friend class odb::access;

#pragma db id
#pragma db not_null
#pragma db access(typeID)
#pragma db column("typeID")
    uint16_t typeID_;

#pragma db not_null
#pragma db default(0)
#pragma db access(basePrice)
#pragma db column("basePrice")
    float basePrice_;
};
-- end of InvType.h --

which is compiled as:
/usr/bin/odb --multi-database dynamic -d common --generate-query
--generate-session --generate-schema --generate-prepared --std c++11
--output-dir ./odb_gen --hxx-suffix .hxx --ixx-suffix .ixx --cxx-suffix
.cpp --odb-file-suffix common:_odb -I/usr/include ./model/invType/InvType.h

The code invoking a query looks like this:
-- main.cpp: --
#include <iostream>

#include <odb/core.hxx>
#include <odb/mysql/database.hxx>
#include <odb/pgsql/database.hxx>

#include "model/invType/InvType.h"
#include "odb_gen/InvType_odb.hxx"

using std::auto_ptr;

int main() {
    auto_ptr<odb::database> db(
        new odb::mysql::database(
            "user",
            "pass",
            "mydb",
            "127.0.0.1",
            3306
        )
    );

    using std::vector;
    vector<uint16_t> ids({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
    {
        odb::transaction t(db->begin());
        db->execute("SELECT 1", 8);
        typedef odb::query<InvType> qry_t;
        typedef odb::result<InvType> res_t;
        qry_t q(qry_t::typeID.in_range(ids.begin(), ids.end()));
        res_t r(
            db->query<InvType>(q)
        );
        for ( const auto it: r ) {
            std::cout << it.typeID() << ":" << it.basePrice() << std::endl;
        }
    }

    return 0;
}
-- end of main.cpp --

The code is compiled and linked without errors. When I run this code I
receive SIGSEGV
Program received signal SIGSEGV, Segmentation fault.
odb::access::object_traits_impl<InvType, (odb::database_id)5>::query
(db=..., q=...) at ./odb_gen/InvType_odb.ixx:94
94    return function_table[db.id ()]->query (db, q);
(gdb) bt
#0  odb::access::object_traits_impl<InvType, (odb::database_id)5>::query
(db=..., q=...) at ./odb_gen/InvType_odb.ixx:94
#1  0x00005558f78fcd7e in odb::database::query_<InvType,
(odb::database_id)5, (odb::class_kind)0>::call<odb::query<InvType,
odb::query_base> > (db=..., q=...) at
/usr/local/include/odb/database.txx:478
#2  0x00005558f78fc52b in odb::database::query<InvType>
(this=0x5558f833e460, q=..., cache=true) at
/usr/local/include/odb/database.txx:19
#3  0x00005558f78fb554 in main () at ./main.cpp:35
#4  0x00007fdafc3dad0a in __libc_start_main (main=0x5558f78fb325 <main()>,
argc=1, argv=0x7ffc0c662778, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7ffc0c662768) at
../csu/libc-start.c:308
#5  0x00005558f78fb26a in _start ()
(gdb) p db
$1 = (odb::database &) @0x5558f833e460: <incomplete type>
(gdb) p db.id()
Couldn't find method odb::database::id
(gdb) p db.id_
There is no member named id_.

The driver and connection itself works correctly since the transaction has
successfully started and `SELECT 1` was executed successfully. The problem
is with only ORM models compiled with ODB.

Could someone point me on where to dig the problem?


More information about the odb-users mailing list