aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/query.txx
blob: 31443480ece7b3e20e86641343240f2da8254dc7 (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
// file      : odb/sqlite/query.txx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

namespace odb
{
  namespace sqlite
  {
    // query
    //

    template <database_type_id ID>
    query::
    query (const query_column<bool, ID>& c)
        : clause_ (c.name ()),
          parameters_ (new (details::shared) query_params)
    {
      // Cannot use IS TRUE here since database type can be a non-
      // integral type.
      //
      clause_ += " = ";
      append<bool, ID> (val_bind<bool> (true));
    }

    // query_column
    //
    template <typename T, database_type_id ID>
    query query_column<T, ID>::
    in (const T& v1, const T& v2) const
    {
      query q (name_);
      q += "IN (";
      q.append<T, ID> (val_bind<T> (v1));
      q += ",";
      q.append<T, ID> (val_bind<T> (v2));
      q += ")";
      return q;
    }

    template <typename T, database_type_id ID>
    query query_column<T, ID>::
    in (const T& v1, const T& v2, const T& v3) const
    {
      query q (name_);
      q += "IN (";
      q.append<T, ID> (val_bind<T> (v1));
      q += ",";
      q.append<T, ID> (val_bind<T> (v2));
      q += ",";
      q.append<T, ID> (val_bind<T> (v3));
      q += ")";
      return q;
    }

    template <typename T, database_type_id ID>
    query query_column<T, ID>::
    in (const T& v1, const T& v2, const T& v3, const T& v4) const
    {
      query q (name_);
      q += "IN (";
      q.append<T, ID> (val_bind<T> (v1));
      q += ",";
      q.append<T, ID> (val_bind<T> (v2));
      q += ",";
      q.append<T, ID> (val_bind<T> (v3));
      q += ",";
      q.append<T, ID> (val_bind<T> (v4));
      q += ")";
      return q;
    }

    template <typename T, database_type_id ID>
    query query_column<T, ID>::
    in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) const
    {
      query q (name_);
      q += "IN (";
      q.append<T, ID> (val_bind<T> (v1));
      q += ",";
      q.append<T, ID> (val_bind<T> (v2));
      q += ",";
      q.append<T, ID> (val_bind<T> (v3));
      q += ",";
      q.append<T, ID> (val_bind<T> (v4));
      q += ",";
      q.append<T, ID> (val_bind<T> (v5));
      q += ")";
      return q;
    }

    template <typename T, database_type_id ID>
    template <typename I>
    query query_column<T, ID>::
    in_range (I begin, I end) const
    {
      query q (name_);
      q += "IN (";

      for (I i (begin); i != end; ++i)
      {
        if (i != begin)
          q += ",";

        q.append<T, ID> (val_bind<T> (*i));
      }
      q += ")";
      return q;
    }
  }
}