aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-11-19 11:51:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-19 11:51:17 +0200
commitc998d05c355518ba3b7e27f6833e00684d9c5764 (patch)
tree830406b2c330cd41fce8fefdfb1bc775a5e9420d
parented0ccc77c5a115dcf47661517ad3451efd871f32 (diff)
Implement bulk API code generation
-rw-r--r--odb/oracle/statement.cxx37
-rw-r--r--odb/oracle/statement.hxx26
2 files changed, 40 insertions, 23 deletions
diff --git a/odb/oracle/statement.cxx b/odb/oracle/statement.cxx
index c0c0741..023e41f 100644
--- a/odb/oracle/statement.cxx
+++ b/odb/oracle/statement.cxx
@@ -71,6 +71,14 @@ namespace odb
SQLT_CLOB // bind::nclob
};
+ template <typename T>
+ inline T*
+ offset (T* base, size_t count, size_t size)
+ {
+ return reinterpret_cast<T*> (
+ reinterpret_cast<char*> (base) + count * size);
+ }
+
extern "C" sb4
odb_oracle_param_callback_proxy (void* context,
OCIBind*,
@@ -86,19 +94,15 @@ namespace odb
// Offset the data based on the current iteration and skip size (stored
// in capacity).
//
- sb2* ind (reinterpret_cast<sb2*> (
- reinterpret_cast<char*> (b.indicator) + it * b.capacity));
+ sb2* ind (offset (b.indicator, it, b.capacity));
// Only call the callback if the parameter is not NULL.
//
if (*ind != -1)
{
- lob* l (reinterpret_cast<lob*> (
- static_cast<char*> (b.buffer) + it * b.capacity));
-
+ lob* l (static_cast<lob*> (offset (b.buffer, it, b.capacity)));
lob_callback* cb (
- reinterpret_cast<lob_callback*> (
- reinterpret_cast<char*> (b.callback) + it * b.capacity));
+ static_cast<lob_callback*> (offset (b.callback, it, b.capacity)));
chunk_position pos;
if (!(*cb->callback.param) (
@@ -605,8 +609,7 @@ namespace odb
for (size_t i (0); i != batch;)
{
l->buffer = &lob_buffer;
- l = reinterpret_cast<lob*> (
- static_cast<char*> (b->buffer) + ++i * skip);
+ l = static_cast<lob*> (offset (b->buffer, ++i, skip));
}
}
@@ -1816,13 +1819,11 @@ namespace odb
// Offset the data based on the current iteration and skip size.
// The id is always first.
//
- sb2* ind (reinterpret_cast<sb2*> (
- reinterpret_cast<char*> (
- ret.bind[0].indicator) + it * ret.skip));
-
*buffer = 0;
*size = 0;
*piece = OCI_ONE_PIECE;
+
+ sb2* ind (offset (ret.bind[0].indicator, it, ret.skip));
*ind = -1;
*indicator = ind;
@@ -1846,7 +1847,7 @@ namespace odb
// Offset the data based on the current iteration and skip size.
//
- *buffer = static_cast<char*> (b.buffer) + it * skip;
+ *buffer = offset (b.buffer, it, skip);
if (b.type == bind::number)
{
@@ -1870,9 +1871,7 @@ namespace odb
if (st.ret_prev_ != 0)
*st.ret_prev_ = static_cast<ub2> (st.ret_size_);
- st.ret_prev_ = reinterpret_cast<ub2*> (
- reinterpret_cast<char*> (b.size) + it * skip);
-
+ st.ret_prev_ = offset (b.size, it, skip);
*size = &st.ret_size_;
}
@@ -1881,9 +1880,7 @@ namespace odb
//
**size = b.capacity;
- *indicator = reinterpret_cast<sb2*> (
- reinterpret_cast<char*> (b.indicator) + it * skip);
-
+ *indicator = offset (b.indicator, it, skip);
*rcode = 0;
*piece = OCI_ONE_PIECE;
diff --git a/odb/oracle/statement.hxx b/odb/oracle/statement.hxx
index 83ce5f7..6a5d604 100644
--- a/odb/oracle/statement.hxx
+++ b/odb/oracle/statement.hxx
@@ -318,7 +318,10 @@ namespace odb
// Return the number of parameter sets (out of n) that were attempted.
//
std::size_t
- execute (std::size_t n, multiple_exceptions*);
+ execute (std::size_t n, multiple_exceptions& mex)
+ {
+ return execute (n, &mex);
+ }
// Return true if successful and false if this row is a duplicate.
// All other errors are reported via exceptions.
@@ -341,6 +344,9 @@ namespace odb
void
init (binding& param);
+ std::size_t
+ execute (std::size_t, multiple_exceptions*);
+
void
fetch (sword r, sb4 code);
@@ -399,7 +405,10 @@ namespace odb
// Return the number of parameter sets (out of n) that were attempted.
//
std::size_t
- execute (std::size_t n, multiple_exceptions*);
+ execute (std::size_t n, multiple_exceptions& mex)
+ {
+ return execute (n, &mex);
+ }
// Return the number of rows affected (deleted) by the parameter
// set. If this is a batch (n > 1 in execute() call above) and it
@@ -424,6 +433,10 @@ namespace odb
update_statement& operator= (const update_statement&);
private:
+ std::size_t
+ execute (std::size_t, multiple_exceptions*);
+
+ private:
bool unique_;
unsigned long long result_;
};
@@ -470,7 +483,10 @@ namespace odb
// Return the number of parameter sets (out of n) that were attempted.
//
std::size_t
- execute (std::size_t n, multiple_exceptions*);
+ execute (std::size_t n, multiple_exceptions& mex)
+ {
+ return execute (n, &mex);
+ }
// Return the number of rows affected (deleted) by the parameter
// set. If this is a batch (n > 1 in execute() call above) and it
@@ -495,6 +511,10 @@ namespace odb
delete_statement& operator= (const delete_statement&);
private:
+ std::size_t
+ execute (std::size_t, multiple_exceptions*);
+
+ private:
bool unique_;
unsigned long long result_;
};