[odb-users] ODB Postgresql default values

Mikhail V. Tomilov mvtomilov at gmail.com
Fri Jul 19 01:09:13 EDT 2013


Hello!

I'm using ODB with postgresql 9.1. I have some questions.

I have the C++ entity:

struct Contractor
{
     boost::uuids::uuid       contractor_uuid;
     bool                     hidden;
     int64                    version;
     boost::posix_time::ptime created_at;
     std::string              name;
};

Corresponding DB table:

      Column      |           Type           |
 Modifiers                           | Storage  | Description
-----------------+--------------------------+--------------------------------------------------------------+----------+-------------
 contractor_uuid | uuid                     | not null default
uuid_generate_v4()                          | plain    |
 name            | character varying(512)   | not null
                                | extended |
 typeid          | character varying(64)    | not null
                                | extended |
 version         | bigint                   | not null default
nextval('contractor_version_seq'::regclass) | plain    |
 hidden          | boolean                  | not null default false
                                | plain    |
 created_at      | timestamp with time zone | not null default now()
                                | plain    |

1. DB has default values for version, hidden, created_at columns. How can I
insert new row via ODB so that DB calculated default values. Sure I can put
values for hidden and created_at columns in my C++ code, but setting
version column in C++ is problematic.

2. The same Contractor entity. When I update row, DB trigger increases
version field using contractor_version_seq sequence. How can I force ODB to
update this field at my C++ struct after update? Sure I can call
database.reload() method, but it's a bit heavy. Postgresql can provide
changed values using RETURNING SQL-clause.

-- 
Regards, Mikhail


More information about the odb-users mailing list