Page 1 of 1

Table creation fails when using namespace for class

PostPosted: Fri Feb 18, 2011 11:20 am
by max23
Hi everyone,

SQLite quits with "unknown database d" when executing the following code:
Code: Select all
QSqlError daoError = qx::dao::create_table<d::Drug>();

As you can see, class "Drug" resides in the namespace "d". QxOrm (or maybe Qt) seems to translate the fully-qualified class name into "d.Drug" as the name for the table to create, resulting in the above error:
Code: Select all
CREATE TABLE d.Drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT)

Is there a way to get around this? Thx for any help.

Re: Table creation fails when using namespace for class

PostPosted: Fri Feb 18, 2011 1:12 pm
by QxOrm admin
Hi,

In your register method of your class drug, you have to specify a table name like this :

Code: Select all
namespace qx {
template <> void register_class(QxClass<d::Drug> & t)
{
   t.setName("drug");
   //...
}}


Note : be careful with 'qx::dao::create_table<>' function : you can use it for tests, but I recommend to design your database with a tool provided by your SGDB.

Re: Table creation fails when using namespace for class

PostPosted: Mon Feb 21, 2011 9:24 am
by max23
Works like a charm, thanks very much.