aboutsummaryrefslogtreecommitdiff
path: root/odb/oracle/statement.ixx
blob: 107f5178fb0150ece9964ebca228e4a729fb1764 (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
// file      : odb/oracle/statement.ixx
// copyright : Copyright (c) 2005-2015 Code Synthesis Tools CC
// license   : ODB NCUEL; see accompanying LICENSE file

using namespace std;

namespace odb
{
  namespace oracle
  {
    // bulk_statement
    //
    inline bulk_statement::
    bulk_statement (connection_type& c,
                    const std::string& text,
                    statement_kind k,
                    const binding* process,
                    bool optimize,
                    std::size_t batch,
                    sb4* status)
        : statement (c, text, k, process, optimize),
          status_ (batch == 1 ? 0 : status)
    {
    }

    inline bulk_statement::
    bulk_statement (connection_type& c,
                    const char* text,
                    statement_kind k,
                    const binding* process,
                    bool optimize,
                    std::size_t batch,
                    sb4* status)
        : statement (c, text, k, process, optimize),
          status_ (batch == 1 ? 0 : status)
    {
    }

    // insert_statement
    //
    inline void insert_statement::
    fetch (sword r, sb4 code)
    {
      result_ = true;

      if (r != 0 /*OCI_SUCCESS*/)
      {
        // An auto-assigned object id should never cause a duplicate primary
        // key.
        //
        if (ret_ == 0)
        {
          // The Oracle error code ORA-00001 indicates unique constraint
          // violation, which covers more than just a duplicate primary key.
          // Unfortunately, there is nothing more precise that we can use.
          //
          if (code == 1)
            result_ = false;
        }
      }
    }

    inline bool insert_statement::
    result (std::size_t i)
    {
      // Get to the next parameter set if necessary.
      //
      if (i != i_)
      {
        mex_->current (++i_); // mex cannot be NULL since this is a batch.
        fetch (status_[i_] == 0 ? 0 /*OCI_SUCCESS*/ : -1 /*OCI_ERROR*/,
               status_[i_]);
      }

      return result_;
    }

    // update_statement
    //
    inline unsigned long long update_statement::
    result (std::size_t i)
    {
      if (i != i_)
        mex_->current (++i_); // mex cannot be NULL since this is a batch.

      return result_;
    }

    // delete_statement
    //
    inline unsigned long long delete_statement::
    result (std::size_t i)
    {
      if (i != i_)
        mex_->current (++i_); // mex cannot be NULL since this is a batch.

      return result_;
    }
  }
}