[odb-users] AW: ODB compiler crash

Boris Kolpackov boris at codesynthesis.com
Fri Sep 19 09:13:09 EDT 2014


Hi Marcel,

Marcel Nehring <mne at qosmotec.com> writes:

> Ad 2)
> I saw the --schema-version-table <name> option but it looked a bit too
> complicated for what I was trying to do. So I think I will stick to the
> default name. But just for curiosity, what is the rationale to force
> case-sensitive table names etc. in Oracle DDLs? Some tools seem to have
> problems with case-sensitive names.

The main reason is to avoid conflicts. There could be data members named
'Name' and 'name' which we need to map to columns somehow. But, if you
want case-insensitive, there is an easy way to achieve this with the
--sql-name-case option.


> 4) When I persist a map ODB will generate a separate table for this
> mapping. But if the surrounding class is solely a wrapper around the
> map for insertion, deletion etc. and also a singleton I do not need
> a separate table. Is it somehow possible to avoid ending up with
> three different tables here? Two should suffice from a database
> point of view I think.

A class with a map will be mapped to two tables. What is the third
table that you are getting?

If the class is just a wrapper around a map and is a singleton, then
one way to get rid of the useless object table would be to emulate the
map yourself, for example:

#pragma db object
struct map_entry
{
  #pragma db id
  std::string key;
  int value;
};

Or, if you want it to seamlessly integrate with std::map, you can do
something like this:

typedef std::pair<std::string, int> map_entry;
#pragma db object(map_entry)
#pragma db member(map_entry::first) id column("key")
#pragma db member(map_entry::second) column("value")


> 5) I have problems persisting nested containers. For example a map of
> maps. A member like std::map<int, std::map<std::string, double>> results
> in an ODB error message similar to: unable to map C++ type 
> '::MyClass::MyMapTypeDef::mapped_type' used in data member 'm_member'
> to a Oracle database type

Nested containers are not supported since there is no natural mapping
for them in a relational database. Some database systems support
container-like column types, so it is possible, with a bit of effort,
to implement two-level nesting in such databases. In Oracle, for
example, there is VARRAY which you can store in a single column.
There is a test in odb-tests package in oracle/custom/ that shows
how to map VARRAY to std::vector. Perhaps there is also a similar
type that can be used to represent a map. Maybe a table type?

The general ODB mechanism that is used to work with such extended types
is described here:

http://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/


> 6) Additionally it looks like I did not yet fully understand the whole
> template class workaround you proposed a few messages earlier. Let's suppose
> I have two template classes. OuterTemplate<T> and
> InnerTemplate<T>. Furthermore I want OuterTemplate<T> to have a member of
> type std::shared_ptr<InnerTemplate<T>>. I have added typedefs for all
> template instantiations for both classes and each typedef has the
> corresponding pragmas. When running the ODB compiler for OuterTemplate.h I
> get the error: unable to map C++ type '::std::shared_ptr< ::InnerTemplate<
> int > >' used in data member 'm_member' to a Oracle database type. How can I
> tell ODB how to persist this class?

Let's say [T=int] then the pragmas that you will need would look like this:

typedef InnerTemplate<int> Inner;
#pragma db object(Inner) pointer(std::shared_ptr)
#pragma db member(Inner::m_id) id

typedef OuterTemplate<int> Outer;
#pragma db object(Outer)
#pragma db member(Outer::m_id) id

The order is not really important but ODB must "see" the pragmas for
Inner (so that it knows Inner is an object) when compiling Outer.


> 7)  The source code attached below produces several compile errors in 
> Visual Studio when I try to compile the code generated by ODB.

Fixed (another name conflict). I've uploaded the binary to the
usual place:

http://codesynthesis.com/~boris/tmp/odb/pre-release/odb-2.4.0.a3-i686-windows.zip

Boris



More information about the odb-users mailing list