diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-28 11:18:54 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-28 11:18:54 +0200 |
commit | 1e5d1211d09c1f50921aa45d8c776be3758a6d89 (patch) | |
tree | e2f11fe227a17a0badc2f24523804b66c3481d0a /odb | |
parent | 8d82c02a90cd7cc3f161828624db5b973585c34c (diff) |
Implement returning of auto id using RETURNING clause in PostgreSQL
Before we used a separate SELECT lastval() query which was both inefficient
and error-prone in cases where INSERT may cause triggers to override the
last value.
Diffstat (limited to 'odb')
-rw-r--r-- | odb/relational/pgsql/source.cxx | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/odb/relational/pgsql/source.cxx b/odb/relational/pgsql/source.cxx index c17edc6..6bfa3d9 100644 --- a/odb/relational/pgsql/source.cxx +++ b/odb/relational/pgsql/source.cxx @@ -983,6 +983,18 @@ namespace relational } virtual void + persist_stmt_extra (type& c, relational::query_parameters&) + { + semantics::data_member* id (id_member (c)); + + if (id != 0 && id->count ("auto")) + { + os << endl + << strlit (" RETURNING " + column_qname (*id)); + } + } + + virtual void object_extra (type& c) { if (abstract (c)) |