aboutsummaryrefslogtreecommitdiff
path: root/common/inheritance/polymorphism/test4.hxx
blob: ea1e4f890f14c7db7e6d8b747ab230d03696850f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// file      : common/inheritance/polymorphism/test4.hxx
// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST4_HXX
#define TEST4_HXX

#include <string>

#include <odb/core.hxx>

// Test views.
//
#pragma db namespace table("t4_")
namespace test4
{
  #pragma db object polymorphic
  struct root1
  {
    virtual ~root1 () {}
    root1 () {}
    root1 (unsigned long i): id (i) {}

    #pragma db id
    unsigned long id;
  };

  #pragma db object
  struct base1: root1
  {
    base1 () {}
    base1 (unsigned long i, unsigned long n): root1 (i), num (n) {}

    unsigned long num;
  };

  #pragma db object polymorphic
  struct root2
  {
    virtual ~root2 () {}
    root2 () {}
    root2 (unsigned long i, unsigned long n): id (i), num (n) {}

    #pragma db id
    unsigned long id;

    unsigned long num;
  };

  #pragma db object
  struct base2: root2
  {
    base2 () {}
    base2 (unsigned long i, unsigned long n, const std::string& s)
        : root2 (i, n), str (s) {}

    std::string str;
  };

  // Test custom join condition.
  //
  #pragma db view object(base2) object(base1: base2::num == base1::num)
  struct view1
  {
    std::string str;
  };

  #pragma db view object(base2)
  struct view2
  {
    #pragma db column("min(" + base2::num + ")")
    unsigned long min_num;
  };

  // Test custom join condition that uses object id. It cannot come
  // from the base since the base table hasn't been join'ed yet.
  //
  #pragma db view object(base1) object(base2: base2::id == base1::id)
  struct view3
  {
    std::string str;
  };
}

#endif // TEST4_HXX