odb (1) Linux Manual Page
NAME
odb – object-relational mapping (ORM) compiler for C++
SYNOPSIS
odb [ options ] file [ file… ]
DESCRIPTION
Given a set of C++ classes in a header file, odb generates C++ code that allows you to persist, query, and update objects of these classes in a relational database (RDBMS). The relational database that the generated code should target is specified with the required –database option (see below).
For an input file in the form name.hxx (other file extensions can be used instead of .hxx), in the single-database mode (the default), the generated C++ files by default have the following names: name-odb.hxx (header file), name-odb.ixx (inline file), and name-odb.cxx (source file). Additionally, if the –generate-schema option is specified and the sql schema format is requested (see –schema-format), the name.sql database schema file is generated. If the separate schema format is requested, the database creation code is generated into the separate name-schema.cxx file.
In the multi-database mode (see the –multi-database option below), the generated files corresponding to the common database have the same names as in the single-database mode. For other databases, the file names include the database name: name-odb-db.hxx, name-odb-db.ixx, name-odb-db.cxx, name-db.sql, and name-schema-db.cxx (where db is the database name).
OPTIONS
–help- Print usage information and exit.
–version- Print version and exit.
-Idir- Add dir to the beginning of the list of directories to be searched for included header files.
-Dname[=def]- Define macro name with definition def. If definition is omitted, define name to be 1.
-Uname- Cancel any previous definitions of macro name, either built-in or provided with the
-Doption. –database|-ddb- Generate code for the db database. Valid values are
mssql,mysql,oracle,pgsql,sqlite, andcommon(multi-database mode only). –multi-database|-mtype- Enable multi-database support and specify its type. Valid values for this option are
staticanddynamic.In the multi-database mode, options that determine the kind (for example,
–schema-format), names (for example,–odb-file-suffix), or content (for example, prologue and epilogue options) of the output files can be prefixed with the database name followed by a colon, for example,mysql:value. This restricts the value of such an option to only apply to generated files corresponding to this database. –default-databasedb- When static multi-database support is used, specify the database that should be made the default. When dynamic multi-database support is used,
commonis always made the default database. –generate-query|-q- Generate query support code. Without this support you cannot use views and can only load objects via their ids.
–generate-prepared- Generate prepared query execution support code.
–omit-unprepared- Omit un-prepared (once-off) query execution support code.
–generate-session|-e- Generate session support code. With this option session support will be enabled by default for all the persistent classes except those for which it was explicitly disabled using the
db sessionpragma. –generate-schema|-s- Generate the database schema. The database schema contains SQL statements that create database tables necessary to store persistent classes defined in the file being compiled. Note that by applying this schema, all the existing information stored in such tables will be lost.
Depending on the database being used (
–databaseoption), the schema is generated either as a standalone SQL file or embedded into the generated C++ code. By default the SQL file is generated for the MySQL, PostgreSQL, Oracle, and Microsoft SQL Server databases and the schema is embedded into the C++ code for the SQLite database. Use the–schema-formatoption to alter the default schema format.If database schema evolution support is enabled (that is, the object model version is specified), then this option also triggers the generation of database schema migration statements, again either as standalong SQL files or embedded into the generated C++ code. You can suppress the generation of schema migration statements by specifying the
–suppress-migrationoption. –generate-schema-only- Generate only the database schema. Note that this option is only valid when generating schema as a standalone SQL file (see
–schema-formatfor details). –suppress-migration- Suppress the generation of database schema migration statements.
–suppress-schema-version- Suppress the generation of schema version table. If you specify this option then you are also expected to manually specify the database schema version and migration state at runtime using the
odb::database::schema_version()function. –schema-version-tablename- Specify the alternative schema version table name instead of the default
schema_version. If you specify this option then you are also expected to manually specify the schema version table name at runtime using theodb::database::schema_version_table()function. The table name can be qualified. –schema-formatformat- Generate the database schema in the specified format. Pass
sqlas format to generate the database schema as a standalone SQL file or passembeddedto embed the schema into the generated C++ code. Theseparatevalue is similar toembeddedexcept the schema creation code is generated into a separate C++ file (name-schema.cxxby default). This value is primarily useful if you want to place the schema creation functionality into a separate program or library. Repeat this option to generate the same database schema in multiple formats. –omit-drop- Omit
DROPstatements from the generated database schema. –omit-create- Omit
CREATEstatements from the generated database schema. –schema-namename- Use name as the database schema name. Schema names are primarily used to distinguish between multiple embedded schemas in the schema catalog. They are not to be confused with database schemas (database namespaces) which are specified with the
–schemaoption. If this option is not specified, the empty name, which is the default schema name, is used. –fkeys-deferrable-modem- Use constraint checking mode m in foreign keys generated for object relationships. Valid values for this option are
not_deferrable,immediate, anddeferred(default). MySQL and SQL Server do not support deferrable foreign keys and for these databases such keys are generated commented out. Other foreign keys generated by the ODB compiler (such as the ones used to support containers and polymorphic hierarchies) are always generated as not deferrable.Note also that if you use either
not_deferrableorimmediatemode, then the order in which you persist, update, and erase objects within a transaction becomes important. –default-pointerptr- Use ptr as the default pointer for persistent objects and views. Objects and views that do not have a pointer assigned with the
db pointerpragma will use this pointer by default. The value of this option can be*which denotes the raw pointer and is the default, or qualified name of a smart pointer class template, for example,std::auto_ptr. In the latter case, the ODB compiler constructs the object or view pointer by adding a single template argument of the object or view type to the qualified name, for examplestd::auto_ptr<object>. The ODB runtime uses object and view pointers to return, and, in case of objects, pass and cache dynamically allocated instances of object and view types.Except for the raw pointer and the standard smart pointers defined in the
<memory>header file, you are expected to include the definition of the default pointer at the beginning of the generated header file. There are two common ways to achieve this: you can either include the necessary header in the file being compiled or you can use the–hxx-prologueoption to add the necessary#includedirective to the generated code. –session-typetype- Use type as the alternative session type instead of the default
odb::session. This option can be used to specify a custom session implementation to be use by the persistent classes. Note that you will also need to include the definition of the custom session type into the generated header file. This is normally achieved with the–hxx-prologue*options. –profile|-pname- Specify a profile that should be used during compilation. A profile is an options file. The ODB compiler first looks for a database-specific version with the name constructed by appending the
–database.optionssuffix to name, where database is the database name as specified with the–databaseoption. If this file is not found, then the ODB compiler looks for a database-independant version with the name constructed by appending just the.optionssuffix.The profile options files are searched for in the same set of directories as C++ headers included with the
#include <…>directive (built-in paths plus those specified with the-Ioptions). The options file is first searched for in the directory itself and then in itsodb/subdirectory.For the format of the options file refer to the
–options-fileoption below. You can repeat this option to specify more than one profile. –at-once- Generate code for all the input files as well as for all the files that they include at once. The result is a single set of source/schema files that contain all the generated code. If more than one input file is specified together with this option, then the
–input-nameoption must also be specified in order to provide the base name for the output files. In this case, the directory part of such a base name is used as the location of the combined file. This can be important for the#includedirective resolution. –schemaschema- Specify a database schema (database namespace) that should be assigned to the persistent classes in the file being compiled. Database schemas are not to be confused with database schema names (schema catalog names) which are specified with the
–schema-nameoption. –export-symbolsymbol- Insert symbol in places where DLL export/import control statements (
__declspec(dllexport/dllimport)) are necessary. See also the–extern-symboloption below. –extern-symbolsymbol- If symbol is defined, insert it in places where a template instantiation must be declared
extern. This option is normally used together with–export-symbolwhen both multi-database support and queries are enabled. –stdversion- Specify the C++ standard that should be used during compilation. Valid values are
c++98(default) andc++11. –warn-hard-add- Warn about hard-added data members.
–warn-hard-delete- Warn about hard-deleted data members and persistent classes.
–warn-hard- Warn about both hard-added and hard-deleted data members and persistent classes.
–output-dir|-odir- Write the generated files to dir instead of the current directory.
–input-namename- Use name instead of the input file to derive the names of the generated files. If the
–at-onceoption is specified, then the directory part of name is used as the location of the combined file. Refer to the–at-onceoption for details. –changelogfile- Read/write changelog from/to file instead of the default changelog file. The default changelog file name is derived from the input file name and it is placed into the same directory as the input file. Note that the
–output-diroption does not affect the changelog file location. In other words, by default, the changelog file is treated as another input rather than output even though the ODB compiler may modify it. Use the–changelog-inand–changelog-outoptions to specify different input and output chaneglog files. –changelog-infile- Read changelog from file instead of the default changelog file. If this option is specified, then you must also specify the output chanegelog file with
–changelog-out. –changelog-outfile- Write changelog to file instead of the default changelog file. If this option is specified, then you must also specify the input chanegelog file with
–changelog-in. –changelog-dirdir- Use dir instead of the input file directory as the changelog file directory. This directory is also added to changelog files specified with the
–changelog,–changelog-in, and–changelog-inoptions unless they are absolute paths. –init-changelog- Force re-initialization of the changelog even if one exists (all the existing change history will be lost). This option is primarily useful for automated testing.
–odb-file-suffixsuffix- Use suffix to construct the names of the generated C++ files. In the single-database mode the default value for this option is
-odb. In the multi-database mode it is-odbfor the files corresponding to thecommondatabase and-odb-db (where db is the database name) for other databases. –sql-file-suffixsuffix- Use suffix to construct the name of the generated schema SQL file. In the single-database mode by default no suffix is used. In the multi-database mode the default value for this option is
–db (where db is the database name). –schema-file-suffixsuffix- Use suffix to construct the name of the generated schema C++ source file. In the single-database mode the default value for this option is
-schema. In the multi-database mode it is-schema-db (where db is the database name). See the–schema-formatoption for details. –changelog-file-suffixsfx- Use sfx to construct the name of the changelog file. In the single-database mode by default no suffix is used. In the multi-database mode the default value for this option is
–db (where db is the database name). –hxx-suffixsuffix- Use suffix instead of the default
.hxxto construct the name of the generated C++ header file. –ixx-suffixsuffix- Use suffix instead of the default
.ixxto construct the name of the generated C++ inline file. –cxx-suffixsuffix- Use suffix instead of the default
.cxxto construct the name of the generated C++ source file. –sql-suffixsuffix- Use suffix instead of the default
.sqlto construct the name of the generated database schema file. –changelog-suffixsuffix- Use suffix instead of the default
.xmlto construct the name of the changelog file. –hxx-prologuetext- Insert text at the beginning of the generated C++ header file.
–ixx-prologuetext- Insert text at the beginning of the generated C++ inline file.
–cxx-prologuetext- Insert text at the beginning of the generated C++ source file.
–schema-prologuetext- Insert text at the beginning of the generated schema C++ source file.
–sql-prologuetext- Insert text at the beginning of the generated database schema file.
–migration-prologuetext- Insert text at the beginning of the generated database migration file.
–sql-interludetext- Insert text after all the
DROPand before anyCREATEstatements in the generated database schema file. –hxx-epiloguetext- Insert text at the end of the generated C++ header file.
–ixx-epiloguetext- Insert text at the end of the generated C++ inline file.
–cxx-epiloguetext- Insert text at the end of the generated C++ source file.
–schema-epiloguetext- Insert text at the end of the generated schema C++ source file.
–sql-epiloguetext- Insert text at the end of the generated database schema file.
–migration-epiloguetext- Insert text at the end of the generated database migration file.
–hxx-prologue-filefile- Insert the content of file at the beginning of the generated C++ header file.
–ixx-prologue-filefile- Insert the content of file at the beginning of the generated C++ inline file.
–cxx-prologue-filefile- Insert the content of file at the beginning of the generated C++ source file.
–schema-prologue-filefile- Insert the content of file at the beginning of the generated schema C++ source file.
–sql-prologue-filefile- Insert the content of file at the beginning of the generated database schema file.
–migration-prologue-filef- Insert the content of file f at the beginning of the generated database migration file.
–sql-interlude-filefile- Insert the content of file after all the
DROPand before anyCREATEstatements in the generated database schema file. –hxx-epilogue-filefile- Insert the content of file at the end of the generated C++ header file.
–ixx-epilogue-filefile- Insert the content of file at the end of the generated C++ inline file.
–cxx-epilogue-filefile- Insert the content of file at the end of the generated C++ source file.
–schema-epilogue-filefile- Insert the content of file at the end of the generated schema C++ source file.
–sql-epilogue-filefile- Insert the content of file at the end of the generated database schema file.
–migration-epilogue-filef- Insert the content of file f at the end of the generated database migration file.
–odb-prologuetext- Compile text before the input header file. This option allows you to add additional declarations, such as custom traits specializations, to the ODB compilation process.
–odb-prologue-filefile- Compile file contents before the input header file. Prologue files are compiled after all the prologue text fragments (
–odb-prologueoption). –odb-epiloguetext- Compile text after the input header file. This option allows you to add additional declarations, such as custom traits specializations, to the ODB compilation process.
–odb-epilogue-filefile- Compile file contents after the input header file. Epilogue files are compiled after all the epilogue text fragments (
–odb-epilogueoption). –table-prefixprefix- Add prefix to table names and, for databases that have global index and/or foreign key names, to those names as well. The prefix is added to both names that were specified with the
db tableanddb indexpragmas and those that were automatically derived from class and data member names. If you require a separator, such as an underscore, between the prefix and the name, then you should include it into the prefix value. –index-suffixsuffix- Use suffix instead of the default
_ito construct index names. The suffix is only added to names that were automatically derived from data member names. If you require a separator, such as an underscore, between the name and the suffix, then you should include it into the suffix value. –fkey-suffixsuffix- Use suffix instead of the default
_fkto construct foreign key names. If you require a separator, such as an underscore, between the name and the suffix, then you should include it into the suffix value. –sequence-suffixsuffix- Use suffix instead of the default
_seqto construct sequence names. If you require a separator, such as an underscore, between the name and the suffix, then you should include it into the suffix value. –sql-name-casecase- Convert all automatically-derived SQL names to upper or lower case. Valid values for this option are
upperandlower. –table-regexregex- Add regex to the list of regular expressions that is used to transform automatically-derived table names. See the SQL NAME TRANSFORMATIONS section below for details.
–column-regexregex- Add regex to the list of regular expressions that is used to transform automatically-derived column names. See the SQL NAME TRANSFORMATIONS section below for details.
–index-regexregex- Add regex to the list of regular expressions that is used to transform automatically-derived index names. See the SQL NAME TRANSFORMATIONS section below for details.
–fkey-regexregex- Add regex to the list of regular expressions that is used to transform automatically-derived foreign key names. See the SQL NAME TRANSFORMATIONS section below for details.
–sequence-regexregex- Add regex to the list of regular expressions that is used to transform automatically-derived sequence names. See the SQL NAME TRANSFORMATIONS section below for details.
–sql-name-regexregex- Add regex to the list of regular expressions that is used to transform all automatically-derived SQL names. See the SQL NAME TRANSFORMATIONS section below for details.
–sql-name-regex-trace- Trace the process of applying regular expressions specified with the SQL name
–*-regexoptions. Use this option to find out why your regular expressions don’t do what you expected them to do. –accessor-regexregex- Add regex to the list of regular expressions used to transform data member names to function names when searching for a suitable accessor function. The argument to this option is a Perl-like regular expression in the form
/pattern/replacement/. Any character can be used as a delimiter instead of/and the delimiter can be escaped inside pattern and replacement with a backslash (\). You can specify multiple regular expressions by repeating this option.All the regular expressions are tried in the order specified and the first expression that produces a suitable accessor function is used. Each expression is tried twice: first with the actual member name and then with the member’s public name which is obtained by removing the common member name decorations, such as leading and trailing underscores, the
m_prefix, etc. The ODB compiler also includes a number of built-in expressions for commonly used accessor names, such asget_foo,getFoo,getfoo, and justfoo. The built-in expressions are tried last.As an example, the following expression transforms data members with public names in the form
footo accessor names in the formGetFoo:/(.+)/Get
