aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/oracle/context.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-07-10 15:17:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-07-10 15:17:16 +0200
commitb8554760aa3a5c5697c77d11e507a2bb46dbf8e4 (patch)
tree3f2bcb28a59eb0d4cce4586acec4a8c639cde7e6 /odb/relational/oracle/context.hxx
parent1b64460a2b2c5411b6052cd4c4d8e8b0d46a4086 (diff)
Add support for custom database type mapping
New pragma qualifier, map, and specifiers: as, to, from. New tests: <database>/custom.
Diffstat (limited to 'odb/relational/oracle/context.hxx')
-rw-r--r--odb/relational/oracle/context.hxx49
1 files changed, 45 insertions, 4 deletions
diff --git a/odb/relational/oracle/context.hxx b/odb/relational/oracle/context.hxx
index 6b7e968..6b07a5f 100644
--- a/odb/relational/oracle/context.hxx
+++ b/odb/relational/oracle/context.hxx
@@ -69,14 +69,20 @@ namespace relational
short scale_value; // Oracle min value is -84. Max value is 127.
bool byte_semantics;
+
+ // Conversion expressions for custom database types.
+ //
+ std::string to;
+ std::string from;
};
class context: public virtual relational::context
{
public:
sql_type const&
- parse_sql_type (string const&, semantics::data_member&);
-
+ parse_sql_type (string const&,
+ semantics::data_member&,
+ bool custom = true);
public:
struct invalid_sql_type
{
@@ -89,14 +95,21 @@ namespace relational
string message_;
};
+ // If custom_db_types is NULL, then this function returns
+ // invalid type instead of throwing in case an unknown type
+ // is encountered.
+ //
static sql_type
- parse_sql_type (string const&);
+ parse_sql_type (string, custom_db_types const* = 0);
public:
static bool
unsigned_integer (semantics::type&);
protected:
+ virtual string const&
+ convert_expr (string const&, semantics::data_member&, bool);
+
virtual string
quote_id_impl (qname const&) const;
@@ -129,7 +142,35 @@ namespace relational
{
data (std::ostream& os): base_context::data (os) {}
- typedef std::map<string, sql_type> sql_type_cache;
+ struct sql_type_cache_entry
+ {
+ sql_type_cache_entry ()
+ : custom_cached (false), straight_cached (false) {}
+
+ sql_type const&
+ cache_custom (sql_type const& t)
+ {
+ custom = t;
+ custom_cached = true;
+ return custom;
+ }
+
+ sql_type const&
+ cache_straight (sql_type const& t)
+ {
+ straight = t;
+ straight_cached = true;
+ return straight;
+ }
+
+ sql_type custom; // With custom mapping.
+ sql_type straight; // Without custom mapping.
+
+ bool custom_cached;
+ bool straight_cached;
+ };
+
+ typedef std::map<string, sql_type_cache_entry> sql_type_cache;
sql_type_cache sql_type_cache_;
};
data* data_;