aboutsummaryrefslogtreecommitdiff
path: root/common/schema/namespace/test.hxx
blob: 44d5c60cdd39d62a8d290f6382e5298cd47275dd (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// file      : common/schema/namespace/test.hxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST_HXX
#define TEST_HXX

#include <string>
#include <vector>

#include <odb/core.hxx>

// Table names.
//
#pragma db object table("TABLE_EXPLICIT")
struct table_explicit
{
  #pragma db id
  unsigned long id_;
};

#pragma db object
struct table_implicit
{
  #pragma db id
  unsigned long id_;
};

// Column names.
//
#pragma db object
struct column
{
  #pragma db id
  int m1;

  #pragma db column("foo")
  int m2;

  int m_m3;
  int _m4;
  int m5_;
  int m_;
  int m__;
};

// Column types.
//
#pragma db object
struct type
{
  #pragma db id
  std::string id;

  // Test default C++ to DB type mapping.
  //
  bool b;
  char c;
  signed char sc;
  unsigned char uc;
  short s;
  unsigned short us;
  int i;
  unsigned int ui;
  long l;
  unsigned long ul;
  long long ll;
  unsigned long long ull;
  float f;
  double d;
  std::string str;

  #pragma db type("INTEGER")
  bool m1;

  #pragma db transient
  char* m2;
};

// Test database schema (aka database namespace).
//
#ifdef ODB_COMPILER
#if defined (ODB_DATABASE_MYSQL)
//#  define DB_SCHEMA "odb_test"
#  define DB_SCHEMA ""
#elif defined (ODB_DATABASE_SQLITE)
#  define DB_SCHEMA "main"
#elif defined (ODB_DATABASE_PGSQL)
#  define DB_SCHEMA "public"
#elif defined (ODB_DATABASE_ORACLE)
//#  define DB_SCHEMA "ODB_TEST"
#  define DB_SCHEMA ""
#elif defined(ODB_DATABASE_MSSQL)
#  define DB_SCHEMA "dbo"
#else
#  error unknown database
#endif
#endif

namespace ns {typedef int my_int;} // Original.

#pragma db object table(DB_SCHEMA."object_1")
struct object1
{
  #pragma db id auto
  unsigned long id;

  #pragma db column("str")
  std::string str;
};

inline bool
operator== (const object1& x, const object1& y)
{
  return x.id == y.id && x.str == y.str;
}

#pragma db namespace schema(DB_SCHEMA)
namespace ns // Extension.
{
  #pragma db object
  struct object2
  {
    object2 (): obj1 (0) {}
    ~object2 () {delete obj1;}

    #pragma db id
    std::string id;

    std::vector<unsigned int> nums;
    object1* obj1;
  };

  inline bool
  operator== (const object2& x, const object2& y)
  {
    return x.id == y.id && x.nums == y.nums && *x.obj1 == *y.obj1;
  }
}

#pragma db view object(object1) object(ns::object2)
struct object_view
{
  #pragma db column(ns::object2::id)
  std::string id2;

  std::string str;
};

#pragma db view table(DB_SCHEMA."schema_object_1")
struct table_view
{
  #pragma db column(DB_SCHEMA."schema_object_1"."str")
  std::string str;
};

#endif // TEST_HXX