aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-11-08 13:31:00 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-11-08 14:46:33 +0200
commit7046b291be1af32b37a148abfb8a60c83f6ff68c (patch)
tree0490d78934bda44860e5c02ed6f07d8a169808bd
parent85b6295e978746479e33a0033fbcf285da335594 (diff)
Improve INTERVAL and TIMESTAMP descriptor type manipulation
-rw-r--r--odb/oracle/oracle-types.cxx190
-rw-r--r--odb/oracle/oracle-types.hxx143
-rw-r--r--odb/oracle/statement.cxx24
3 files changed, 218 insertions, 139 deletions
diff --git a/odb/oracle/oracle-types.cxx b/odb/oracle/oracle-types.cxx
index 17ae479..fad085f 100644
--- a/odb/oracle/oracle-types.cxx
+++ b/odb/oracle/oracle-types.cxx
@@ -1,4 +1,4 @@
-// file : odb/oracle/oracle-types.hxx
+// file : odb/oracle/oracle-types.cxx
// author : Constantin Michael <constantin@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license : ODB NCUEL; see accompanying LICENSE file
@@ -15,121 +15,199 @@ namespace odb
namespace oracle
{
void datetime::
- get () const
+ get (sb2& y, ub1& m, ub1& d, ub1& h, ub1& minute, ub1& s, ub4& ns) const
{
assert (descriptor.get () != 0);
- sword r (OCIDateTimeGetDate (descriptor.environment,
- descriptor.error,
+ sword r (OCIDateTimeGetDate (environment,
+ error,
descriptor,
- &fields.year,
- &fields.month,
- &fields.day));
+ &y,
+ &m,
+ &d));
if (r != OCI_SUCCESS)
- translate_error (descriptor.error, r);
+ translate_error (error, r);
- r = OCIDateTimeGetTime (descriptor.environment,
- descriptor.error,
+ r = OCIDateTimeGetTime (environment,
+ error,
descriptor,
- &fields.hour,
- &fields.minute,
- &fields.second,
- &fields.nanosecond);
+ &h,
+ &minute,
+ &s,
+ &ns);
if (r != OCI_SUCCESS)
- translate_error (descriptor.error, r);
+ translate_error (error, r);
}
void datetime::
- set ()
+ set (sb2 y, ub1 m, ub1 d, ub1 h, ub1 minute, ub1 s, ub4 ns)
{
if (descriptor.get () != 0)
{
- sword r (OCIDateTimeConstruct (descriptor.environment,
- descriptor.error,
+ sword r (OCIDateTimeConstruct (environment,
+ error,
descriptor,
- fields.year,
- fields.month,
- fields.day,
- fields.hour,
- fields.minute,
- fields.second,
- fields.nanosecond,
+ y,
+ m,
+ d,
+ h,
+ minute,
+ s,
+ ns,
0,
0));
if (r != OCI_SUCCESS)
- translate_error (descriptor.error, r);
+ translate_error (error, r);
+ }
+ else
+ {
+ year_ = y;
+ month_ = m;
+ day_ = d;
+ hour_ = h;
+ minute_ = minute;
+ second_ = s;
+ nanosecond_ = ns;
}
}
+ void datetime::
+ set ()
+ {
+ assert (descriptor.get () != 0);
+
+ sword r (OCIDateTimeConstruct (environment,
+ error,
+ descriptor,
+ year_,
+ month_,
+ day_,
+ hour_,
+ minute_,
+ second_,
+ nanosecond_,
+ 0,
+ 0));
+
+ if (r != OCI_SUCCESS)
+ translate_error (error, r);
+ }
+
void interval_ym::
- get () const
+ get (sb4& y, sb4& m) const
{
assert (descriptor.get () != 0);
- sword r (OCIIntervalGetYearMonth (descriptor.environment,
- descriptor.error,
- &fields.year,
- &fields.month,
+ sword r (OCIIntervalGetYearMonth (environment,
+ error,
+ &y,
+ &m,
descriptor));
if (r != OCI_SUCCESS)
- translate_error (descriptor.error, r);
+ translate_error (error, r);
}
void interval_ym::
- set ()
+ set (sb4 y, sb4 m)
{
if (descriptor.get () != 0)
{
- sword r (OCIIntervalSetYearMonth (descriptor.environment,
- descriptor.error,
- fields.year,
- fields.month,
+ sword r (OCIIntervalSetYearMonth (environment,
+ error,
+ y,
+ m,
descriptor));
if (r != OCI_SUCCESS)
- translate_error (descriptor.error, r);
+ translate_error (error, r);
+ }
+ else
+ {
+ year_ = y;
+ month_ = m;
}
}
+ void interval_ym::
+ set ()
+ {
+ assert (descriptor.get () != 0);
+
+ sword r (OCIIntervalSetYearMonth (environment,
+ error,
+ year_,
+ month_,
+ descriptor));
+
+ if (r != OCI_SUCCESS)
+ translate_error (error, r);
+ }
+
void interval_ds::
- get () const
+ get (sb4& d, sb4& h, sb4& m, sb4& s, sb4& ns) const
{
assert (descriptor.get () != 0);
- sword r (OCIIntervalGetDaySecond (descriptor.environment,
- descriptor.error,
- &fields.day,
- &fields.hour,
- &fields.minute,
- &fields.second,
- &fields.nanosecond,
+ sword r (OCIIntervalGetDaySecond (environment,
+ error,
+ &d,
+ &h,
+ &m,
+ &s,
+ &ns,
descriptor));
if (r != OCI_SUCCESS)
- translate_error (descriptor.error, r);
+ translate_error (error, r);
}
void interval_ds::
- set ()
+ set (sb4 d, sb4 h, sb4 m, sb4 s, sb4 ns)
{
if (descriptor.get () != 0)
{
- sword r (OCIIntervalSetDaySecond (descriptor.environment,
- descriptor.error,
- fields.day,
- fields.hour,
- fields.minute,
- fields.second,
- fields.nanosecond,
+ sword r (OCIIntervalSetDaySecond (environment,
+ error,
+ d,
+ h,
+ m,
+ s,
+ ns,
descriptor));
if (r != OCI_SUCCESS)
- translate_error (descriptor.error, r);
+ translate_error (error, r);
}
+ else
+ {
+ day_ = d;
+ hour_ = h;
+ minute_ = m;
+ second_ = s;
+ nanosecond_ = ns;
+ }
+ }
+
+ void interval_ds::
+ set ()
+ {
+ assert (descriptor.get () != 0);
+
+ sword r (OCIIntervalSetDaySecond (environment,
+ error,
+ day_,
+ hour_,
+ minute_,
+ second_,
+ nanosecond_,
+ descriptor));
+
+ if (r != OCI_SUCCESS)
+ translate_error (error, r);
}
}
}
diff --git a/odb/oracle/oracle-types.hxx b/odb/oracle/oracle-types.hxx
index f12caeb..cebb413 100644
--- a/odb/oracle/oracle-types.hxx
+++ b/odb/oracle/oracle-types.hxx
@@ -178,16 +178,12 @@ namespace odb
public:
datetime_auto_descriptor (OCIDateTime* d = 0):
- base (d),
- environment (0),
- error (0)
+ base (d)
{
}
datetime_auto_descriptor (datetime_auto_descriptor& x):
- base (x.d_),
- environment (x.environment),
- error (x.error)
+ base (x.d_)
{
x.d_ = 0;
}
@@ -199,14 +195,8 @@ namespace odb
x.d_ = 0;
reset (l);
- environment = x.environment;
- error = x.error;
-
return *this;
}
-
- OCIEnv* environment;
- OCIError* error;
};
class LIBODB_ORACLE_EXPORT interval_ym_auto_descriptor:
@@ -216,16 +206,12 @@ namespace odb
public:
interval_ym_auto_descriptor (OCIInterval* d = 0):
- base (d),
- environment (0),
- error (0)
+ base (d)
{
}
interval_ym_auto_descriptor (interval_ym_auto_descriptor& x):
- base (x.d_),
- environment (x.environment),
- error (x.error)
+ base (x.d_)
{
x.d_ = 0;
}
@@ -237,14 +223,8 @@ namespace odb
x.d_ = 0;
reset (l);
- environment = x.environment;
- error = x.error;
-
return *this;
}
-
- OCIEnv* environment;
- OCIError* error;
};
class LIBODB_ORACLE_EXPORT interval_ds_auto_descriptor:
@@ -254,16 +234,12 @@ namespace odb
public:
interval_ds_auto_descriptor (OCIInterval* d = 0):
- base (d),
- environment (0),
- error (0)
+ base (d)
{
}
interval_ds_auto_descriptor (interval_ds_auto_descriptor& x):
- base (x.d_),
- environment (x.environment),
- error (x.error)
+ base (x.d_)
{
x.d_ = 0;
}
@@ -275,14 +251,8 @@ namespace odb
x.d_ = 0;
reset (l);
- environment = x.environment;
- error = x.error;
-
return *this;
}
-
- OCIEnv* environment;
- OCIError* error;
};
//
@@ -299,65 +269,96 @@ namespace odb
struct LIBODB_ORACLE_EXPORT datetime
{
- struct fields_type
- {
- sb2 year;
- ub1 month;
- ub1 day;
- ub1 hour;
- ub1 minute;
- ub1 second;
- ub4 nanosecond;
- };
-
- mutable fields_type fields;
- datetime_auto_descriptor descriptor;
+ void
+ get (sb2& year,
+ ub1& month,
+ ub1& day,
+ ub1& hour,
+ ub1& minute,
+ ub1& second,
+ ub4& nanosecond) const;
void
- get () const;
+ set (sb2 year,
+ ub1 month,
+ ub1 day,
+ ub1 hour,
+ ub1 minute,
+ ub1 second,
+ ub4 nanosecond);
void
set ();
+ public:
+ OCIEnv* environment;
+ OCIError* error;
+
+ datetime_auto_descriptor descriptor;
+
+ private:
+ sb2 year_;
+ ub1 month_;
+ ub1 day_;
+ ub1 hour_;
+ ub1 minute_;
+ ub1 second_;
+ ub4 nanosecond_;
};
struct LIBODB_ORACLE_EXPORT interval_ym
{
- struct fields_type
- {
- sb4 year;
- sb4 month;
- };
-
- mutable fields_type fields;
- interval_ym_auto_descriptor descriptor;
+ void
+ get (sb4& year, sb4& month) const;
void
- get () const;
+ set (sb4 year, sb4 month);
void
set ();
+
+ public:
+ OCIEnv* environment;
+ OCIError* error;
+
+ interval_ym_auto_descriptor descriptor;
+
+ private:
+ sb4 year_;
+ sb4 month_;
};
struct LIBODB_ORACLE_EXPORT interval_ds
{
- struct fields_type
- {
- sb4 day;
- sb4 hour;
- sb4 minute;
- sb4 second;
- sb4 nanosecond;
- };
-
- mutable fields_type fields;
- interval_ds_auto_descriptor descriptor;
+ void
+ get (sb4& day,
+ sb4& hour,
+ sb4& minute,
+ sb4& second,
+ sb4& nanosecond) const;
void
- get () const;
+ set (sb4 day,
+ sb4 hour,
+ sb4 minute,
+ sb4 second,
+ sb4 nanosecond);
void
set ();
+
+ public:
+ OCIEnv* environment;
+ OCIError* error;
+
+ interval_ds_auto_descriptor descriptor;
+
+ private:
+ sb4 day_;
+ sb4 hour_;
+ sb4 minute_;
+ sb4 second_;
+ sb4 nanosecond_;
};
}
}
diff --git a/odb/oracle/statement.cxx b/odb/oracle/statement.cxx
index 7c16ab2..b789959 100644
--- a/odb/oracle/statement.cxx
+++ b/odb/oracle/statement.cxx
@@ -191,8 +191,8 @@ namespace odb
throw invalid_oci_handle ();
dt->descriptor.reset (static_cast<OCIDateTime*> (d));
- dt->descriptor.environment = env;
- dt->descriptor.error = err;
+ dt->environment = env;
+ dt->error = err;
dt->set ();
}
@@ -216,8 +216,8 @@ namespace odb
throw invalid_oci_handle ();
iym->descriptor.reset (static_cast<OCIInterval*> (d));
- iym->descriptor.environment = env;
- iym->descriptor.error = err;
+ iym->environment = env;
+ iym->error = err;
iym->set ();
}
@@ -241,8 +241,8 @@ namespace odb
throw invalid_oci_handle ();
ids->descriptor.reset (static_cast<OCIInterval*> (d));
- ids->descriptor.environment = env;
- ids->descriptor.error = err;
+ ids->environment = env;
+ ids->error = err;
ids->set ();
}
@@ -358,8 +358,8 @@ namespace odb
throw invalid_oci_handle ();
dt->descriptor.reset (static_cast<OCIDateTime*> (d));
- dt->descriptor.environment = env;
- dt->descriptor.error = err;
+ dt->environment = env;
+ dt->error = err;
}
value = &dt->descriptor.get ();
@@ -382,8 +382,8 @@ namespace odb
throw invalid_oci_handle ();
iym->descriptor.reset (static_cast<OCIInterval*> (d));
- iym->descriptor.environment = env;
- iym->descriptor.error = err;
+ iym->environment = env;
+ iym->error = err;
}
value = &iym->descriptor.get ();
@@ -406,8 +406,8 @@ namespace odb
throw invalid_oci_handle ();
ids->descriptor.reset (static_cast<OCIInterval*> (d));
- ids->descriptor.environment = env;
- ids->descriptor.error = err;
+ ids->environment = env;
+ ids->error = err;
}
value = &ids->descriptor.get ();