Fwd: [odb-users] create_schema deletes db tables

Rafal Grasman rjg1094 at gmail.com
Fri Jul 5 16:18:59 EDT 2013


---------- Forwarded message ----------
From: Rafal Grasman <rjg1094 at gmail.com>
Date: 2013/7/5
Subject: Re: [odb-users] create_schema deletes db tables
To: Lidia Kalinovsky <lidia at lemur-soft.com>


I had the same problem and this is how I "solved" it, here you go, if it
helps:

try
{
 odb::transaction t (Database::users->begin ());
typedef odb::query<user> user_query;
for (user& u: Database::users->query<user> (user_query::nickname ==
"server")){}
 t.commit();
}
catch(odb::exception &e)
 {
try
{
if(std::string(e.what()).c_str()[0] == '1')
 {
odb::transaction CreateDB (Database::users->begin ());
odb::schema_catalog::create_schema (*Database::users);
 CreateDB.commit();

odb::transaction t (Database::users->begin ());

 user server("server","X",0,0,0,0,0,0,0,0,0);
user admin("admin","X",0,0,0,0,0,0,0,0,0);
 user administrator("administrator","X",0,0,0,0,0,0,0,0,0);

Database::users->persist (server);
 Database::users->persist (admin);
Database::users->persist (administrator);

 t.commit();
}
else
{
 REPORT_ERROR_IF_ANY(e);
}
}
catch(odb::exception &zz)
 {
REPORT_ERROR_IF_ANY(zz);
}


2013/7/5 Lidia Kalinovsky <lidia at lemur-soft.com>

> OK.
> Thanks to all for help and quick response.
>
>
> On Fri, Jul 5, 2013 at 5:25 PM, Per Edin <info at peredin.com> wrote:
>
> > If you are creating a new database, call create_schema.
> >
> > If you are opening an existing database, do NOT call create_schema.
> >
> >
> >
> > On Fri, Jul 5, 2013 at 4:20 PM, Lidia Kalinovsky <lidia at lemur-soft.com
> >wrote:
> >
> >> May be - thank you.
> >> So, the question is : how do I know if I should call create_schema
> >> function ? To check if sqlite file exists ?
> >>
> >>
> >> On Fri, Jul 5, 2013 at 5:13 PM, Boris Kolpackov <
> boris at codesynthesis.com>wrote:
> >>
> >>> Hi Lidia,
> >>>
> >>> Lidia Kalinovsky <lidia at lemur-soft.com> writes:
> >>>
> >>> > But sometimes ( I haven't realized when exactly ) I get "table .. not
> >>> > exist" exception if create_schema is not called.
> >>>
> >>> The create_schema() function re-creates the database schema, that is,
> >>> drops and then creates all the tables necessary to store your objects.
> >>>
> >>> Perhaps you are getting an exception after adding some new classes
> >>> and trying to persist them in an existing database which only has
> >>> tables for older classes?
> >>>
> >>> Boris
> >>>
> >>
> >>
> >>
> >> --
> >> Software integration and outsourcing services,
> >> Lemur-Soft, Giv'at Nili
> >> Israel, 37825
> >> Phone : (+972) 545748325
> >> Fax : (+972) 775345383
> >> Email : lidia at lemur-soft.com
> >> Web: www.lemur-soft.com
> >>
> >
> >
>
>
> --
> Software integration and outsourcing services,
> Lemur-Soft, Giv'at Nili
> Israel, 37825
> Phone : (+972) 545748325
> Fax : (+972) 775345383
> Email : lidia at lemur-soft.com
> Web: www.lemur-soft.com
>


More information about the odb-users mailing list