aboutsummaryrefslogtreecommitdiff
path: root/odb/relational
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-09-16 08:20:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-09-16 08:20:00 +0200
commitf6eda10b4014ea75af1be88ab3498618e390ea47 (patch)
tree5c91266323a1aeedeb7dc4ab1b0cf2c5c771e66c /odb/relational
parent5a5bf7fc225ac225dbc03df55f6be7c56cb419aa (diff)
Diagnose (potentially) empty UPDATE statements with ROWVERSION
Diffstat (limited to 'odb/relational')
-rw-r--r--odb/relational/mssql/source.cxx33
1 files changed, 31 insertions, 2 deletions
diff --git a/odb/relational/mssql/source.cxx b/odb/relational/mssql/source.cxx
index 8274b50..83096ab 100644
--- a/odb/relational/mssql/source.cxx
+++ b/odb/relational/mssql/source.cxx
@@ -35,7 +35,8 @@ namespace relational
//
struct object_columns: relational::object_columns, context
{
- object_columns (base const& x): base (x) {}
+ object_columns (base const& x)
+ : base (x), rowversion_ (false), column_count_ (0) {}
virtual bool
column (semantics::data_member& m,
@@ -55,11 +56,39 @@ namespace relational
{
sql_type t (parse_sql_type (column_type (), m));
if (t.type == sql_type::ROWVERSION)
+ {
+ rowversion_ = true;
return false;
+ }
}
- return base::column (m, table, column);
+ bool r (base::column (m, table, column));
+
+ // Count the number of columns in the UPDATE statement, but
+ // excluding soft-deleted.
+ //
+ if (sk_ == statement_update && r && !deleted (member_path_))
+ column_count_++;
+
+ return r;
+ }
+
+ virtual void
+ traverse_post (semantics::nameable& n)
+ {
+ if (rowversion_ && column_count_ == 0)
+ {
+ location l (n.location ());
+ error (l) << "ROWVERSION in an object without any readwrite "
+ "data members" << endl;
+ error (l) << "UPDATE statement will be empty" << endl;
+ throw operation_failed ();
+ }
}
+
+ private:
+ bool rowversion_;
+ size_t column_count_;
};
entry<object_columns> object_columns_;