aboutsummaryrefslogtreecommitdiff
path: root/odb/context.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-07-19 13:42:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-07-19 13:42:18 +0200
commit73c98a67ef4ed605cf69e0d212934c4dc1f3eb8e (patch)
tree8645cd8d06f218ff5d945b1b3b94a58a127753c4 /odb/context.cxx
parent12d0d9bbd0f5b7295c50fd5b223e538afe1abbf7 (diff)
New design for NULL semantics
Now, instead of being specified as part of the SQL type with the type pragma, there are separate null and not_null pragmas. The not_null pragma was used to control NULL-ness of object pointers. Now the two pragmas are used consistently for object pointers and simple values (and in the future will work for composite values and containers).
Diffstat (limited to 'odb/context.cxx')
-rw-r--r--odb/context.cxx64
1 files changed, 49 insertions, 15 deletions
diff --git a/odb/context.cxx b/odb/context.cxx
index 04761f8..520caea 100644
--- a/odb/context.cxx
+++ b/odb/context.cxx
@@ -145,6 +145,47 @@ context ()
context* context::current_;
+bool context::
+null (semantics::data_member& m)
+{
+ semantics::type& t (m.type ());
+
+ // By default pointers can be null.
+ //
+ if (object_pointer (t))
+ return m.count ("null") ||
+ (!m.count ("not-null") &&
+ (t.count ("null") || !t.count ("not-null")));
+ else
+ // Everything else by default is not null.
+ //
+ return m.count ("null") ||
+ (!m.count ("not-null") && t.count ("null"));
+}
+
+bool context::
+null (semantics::data_member& m, string const& kp)
+{
+ if (kp.empty ())
+ return null (m);
+
+ semantics::type& c (m.type ());
+ semantics::type& t (member_type (m, kp));
+
+ if (object_pointer (t))
+ return m.count (kp + "-null") ||
+ (!m.count (kp + "-not-null") &&
+ (c.count (kp + "-null") ||
+ (!c.count (kp + "-not-null") &&
+ (t.count ("null") || !t.count ("not-null")))));
+ else
+ return m.count (kp + "-null") ||
+ (!m.count (kp + "-not-null") &&
+ (c.count (kp + "-null") ||
+ (!c.count (kp + "-not-null") &&
+ t.count ("null"))));
+}
+
string context::
upcase (string const& s)
{
@@ -192,7 +233,7 @@ comp_value_ (semantics::class_& c)
{
bool r (true);
- //@@ This is bad. Did I add new value pragmas and forgot to
+ //@@ This is bad. Did we add new value pragmas and forgot to
// account for them here?
//
r = r && c.count ("value");
@@ -206,7 +247,10 @@ comp_value_ (semantics::class_& c)
r = r && !c.count ("index-column");
r = r && !c.count ("key-column");
r = r && !c.count ("id-column");
+ r = r && !c.count ("null");
r = r && !c.count ("not-null");
+ r = r && !c.count ("value-null");
+ r = r && !c.count ("value-not-null");
r = r && !c.count ("unordered");
c.set ("composite-value", r);
@@ -269,10 +313,7 @@ column_type (semantics::data_member& m, string const& kp)
}
string context::
-database_type_impl (semantics::type& t,
- semantics::names* hint,
- semantics::context& ctx,
- column_type_flags f)
+database_type_impl (semantics::type& t, semantics::names* hint, bool id)
{
type_map_type::const_iterator end (data_->type_map_.end ()), i (end);
@@ -293,16 +334,9 @@ database_type_impl (semantics::type& t,
i = data_->type_map_.find (t.fq_name ());
if (i != end)
- {
- string r (ctx.count ("id") ? i->second.id_type : i->second.type);
-
- if ((f & ctf_default_null) == 0)
- r += " NOT NULL";
-
- return r;
- }
-
- return string ();
+ return id ? i->second.id_type : i->second.type;
+ else
+ return string ();
}
static string