[odb-users] how to generate two db files with different schemas and embedded into an application

Boris Kolpackov boris at codesynthesis.com
Fri Aug 19 01:23:09 EDT 2022

Jed Wu <jed.wu at ringcentral.com> writes:

> Hi, per my test, if I  define and use more then one schema(default or
> custom), it will throw out an exception like "unknown database schema 
> ‘myschema’”.

This usually means that the *-odb.cxx file that contains myschema
is not linked to your application. In particular, this can happen
inadvertently when *-odb.cxx comes from a static library.

> Do you have an example that can work well with multiple schema names?

Overall, your usage should look along these lines

odb ... --generate-schema --input-name contact --schema-name contact ... 
odb ... --generate-schema --input-name phonenumber --schema-name phonenumber ...

c++ ... myapp.cxx contact-odb.cxx phonenumber-odb.cxx

Then, in myapp.cxx, you should be able to do:

odb::schema_catalog::create_schema (db1, "contact");
odb::schema_catalog::create_schema (db2, "phonenumber");

More information about the odb-users mailing list