[odb-users] Polymorphic code generation problem on PostgreSQL

Tomilov.Mikhail Mikhail.Tomilov at infotecs.ru
Fri Dec 12 03:04:24 EST 2014


Hello!

I use ODB with Postgresql. Here is ODB entities:

    #include <string>

    #include <odb/pre.hxx>
    #include <odb/query.hxx>


    #pragma db object table( "contrator" ) polymorphic
    struct Contrator
    {
    В  virtual ~Contrator() {}

    В  #pragma db id
    В  int id;
    В  std::string name;
    };


    #pragma db object table( "company" )
    struct Company : public Contrator
    {
    В  int size;
    };


    #pragma db object table( "government" )
    struct Government : public Contrator
    {
    В  int code;
    };


    #pragma db object table( "person" )
    struct Person
    {
    В  #pragma db id
    В  int id;
    В  int contractor_id;
    };


    #pragma db object table( "workflow" )
    struct Workflow
    {
    В  #pragma db id
    В  int id;
    };


    #pragma db object table( "transaction" )
    struct Transaction
    {
    В  #pragma db id
    В  int id;
    В  int sender_id;
    В  int recipient_id;
    В  int workflow_id;
    };


    #pragma db view object( Workflow ) \
    В  object( Transaction: Transaction::workflow_id == Workflow::id ) \
    В  object( Person = Sender: Transaction::sender_id == Sender::id ) \
    В  object( Person = Recipient: Transaction::recipient_id ==
    Recipient::id ) \
    В  object( Company = SenderCompany: SenderCompany::id ==
    Sender::contractor_id ) \
    В  object( Government = RecipientGovernment: RecipientGovernment::id
    == Recipient::contractor_id )
    struct WorkflowView
    {
    В  #pragma db column (Workflow::id)
    В  int workflow_id;
    В  #pragma db column (Transaction::id)
    В  int transaction_id;
    В  #pragma db column (Sender::id)
    В  int sender_id;
    В  #pragma db column (Recipient::id)
    В  int recipient_id;
    В  #pragma db column (SenderCompany::name)
    В  std::string sender_name;
    В  #pragma db column (RecipientGovernment::name)
    В  std::string recipient_name;
    };

    #include <odb/post.hxx>

I load data this way:

    odb::pgsql::database conn("host=localhost port=5432 user=user
    password=123456 dbname=test");
    odb::transaction tr(conn.begin());

    typedef odb::query< WorkflowView > Query;
    tr.database().query< WorkflowView >();

I get postgresql error: "missing FROM-clause entry for table 
"SenderCompany_contrator" at character".
Here is PostgreSQL query generated by ODB:

    1:В  SELECT
    2:В В В  "workflow"."id", "transaction"."id", "Sender"."id",
    "Recipient"."id", "SenderCompany_contrator"."name",
    "RecipientGovernment_contrator"."name"
    3:В  FROM "workflow"
    4:В  LEFT JOIN "transaction" ON "transaction"."workflow_id" =
    "workflow"."id"
    5:В  LEFT JOIN "person" AS "Sender" ON "transaction"."sender_id" =
    "Sender"."id"
    6:В  LEFT JOIN "person" AS "Recipient" ON
    "transaction"."recipient_id" = "Recipient"."id"
    7:В  LEFT JOIN "company" AS "SenderCompany_company" ON
    "SenderCompany_contrator"."id" = "Sender"."contractor_id"
    8:В  LEFT JOIN "contrator" AS "SenderCompany_contrator" ON
    "SenderCompany_contrator"."id"="SenderCompany_company"."id"
    9:В  LEFT JOIN "government" AS "RecipientGovernment_government" ON
    "RecipientGovernment_contrator"."id" = "Recipient"."contractor_id"
    10: LEFT JOIN "contrator" AS "RecipientGovernment_contrator" ON
    "RecipientGovernment_contrator"."id"="RecipientGovernment_government"."id"

At 7th line used while it is declared at 8th line.

Is it entities declaration problem or ODB bug?

Thank you!

-- 
Best regards, Mikhail



More information about the odb-users mailing list