[odb-users] [Feature request] ODB should support CREATE TABLE IF NOT EXISTS for SQLite (and, preferably, for other drivers)

aongeeno at openmailbox.org aongeeno at openmailbox.org
Wed May 31 05:05:20 EDT 2017


Good day! As I know there is no possibility to generate schema SQL with keywords "IF NOT EXISTS".

This can be useful for embedded. In official examples there is schema/embedded.
   
>     // The following alternative version only creates the schema if it
>     // hasn't already been created. To detect the existence of the schema
>     // this version tries to query the database for a person object. If
>     // the corresponding table does not exist, then an exceptions will be
>     // thrown in which case we proceed to creating the schema.
>     //
>     /*
>     {
>       transaction t (db->begin ());       
>       try
>       {       
>         db->query<person> (false);       
>       }
>       catch (const odb::exception& e)
>       {       
>         schema_catalog::create_schema (*db);       
>       }       
>       t.commit ();     
>     }
>     */

This looks like as dirty hack, because we can catch different odb::exception and need to know that this is not a driver problem. This makes code complicated and not so robust. Much better will be use supported feature CREATE TABLE IF NOT EXISTS.

Any suggestions?


More information about the odb-users mailing list