Assertion on QxSqlRelation.h, line 117 when running query

Forum for posting problems using QxOrm library

Assertion on QxSqlRelation.h, line 117 when running query

Postby manutalcual » Thu Dec 10, 2015 3:27 pm

Hi,

I'm having an assertion on QxSqlRelation.h when runing a query:

ASSERT: "m_pClass && m_pClassOwner && m_pDataMember && m_pDataMemberX && m_pDataMemberId" in file ../../QxOrm/include/QxDao/QxSqlRelation.h, line 117


The code:

Code: Select all
int main (int argc, char ** argv)
{
   QCoreApplication app (argc, argv);
   qx::QxSqlDatabase::getSingleton()->setDriverName ("QSQLITE");
   qx::QxSqlDatabase::getSingleton()->setDatabaseName ("./hulk.db");
   qx::QxSqlDatabase::getSingleton()->setTraceSqlQuery (true);
   qx::QxSqlDatabase::getSingleton()->setTraceSqlRecord (true);
   QSqlDatabase db = qx::QxSqlDatabase::getSingleton()->getDatabaseCloned();
   qx::QxSession session (db, true, true);
   boost::shared_ptr<Calendars> cal_ptr (new Calendars());
   qx::QxSqlQuery query;

   query.where (Calendars::column_Name()).isEqualTo("1");

   list_of_Calendars lst_cal;

   cal_ptr->qxFetchByQuery(query, lst_cal);

   qx::dump (lst_cal);


When qxFetchBy... is called I get that assert. Could someone point me somewhere to know what's happening?

Thank you.
manutalcual
 
Posts: 8
Joined: Thu Dec 10, 2015 3:22 pm

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby qxorm » Thu Dec 10, 2015 7:51 pm

Hello,

ASSERT: "m_pClass && m_pClassOwner && m_pDataMember && m_pDataMemberX && m_pDataMemberId" in file ../../QxOrm/include/QxDao/QxSqlRelation.h, line 117

Do you know which value is NULL : m_pClass ? m_pClassOwner ? m_pDataMember ? m_pDataMemberX ? Or m_pDataMemberId ?

Could someone point me somewhere to know what's happening?

Your main code seems correct.
Could you please provide your Calendars class definition (.h file) and class implementation (.cpp) + your function qx::register_class<Calendars> ?
This way, maybe I could reproduce your issue and explain to you what is wrong.

Note : did you generate your Calendars class with QxEntityEditor application ?
If no, then I would recommend to start with QxEntityEditor : it could help you to understand how to write the qx::register_class<T> function and generates automatically C++ source code.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby manutalcual » Fri Dec 11, 2015 7:34 am

Hi,
Yes I generated the class with Qx editor. In fact it was generated by someone else that uses this all the time but can't help because he don't understands why this is happening. He didn't have a problem since he uses these tools.
I think my problem could come because I'm compiling with autotools, NOT QtCreator. Also I have several Qt versions in my development machine: Qt5.4, 5.3, 5.2, 5.5... and QxOrm in two places.
Anyway I've attached the code.
I use these flags to compile:
Code: Select all
AM_CPPFLAGS = -DG_LOG_DOMAIN=\"sqler\" -I$(top_srcdir) \
   -I$(top_srcdir)/include \
   -I/home/manuel/by/hulk/sql/hulk.data/include \
   -I/home/manuel/by/hulk/QxOrm/include \
   -I/home/manuel/Qt/5.3/gcc_64/include

AM_LDFLAGS = -L/home/manuel/Qt/5.3/gcc_64/lib \
   -L/home/manuel/by/hulk/sql/hulk.data/bin \
   -L/home/manuel/by/hulk/build-QxOrm-Desktop_Qt_5_3_GCC_64bit-Debug/lib

LIBS = -lHulkd -lQt5Core -lQt5Sql -lQxOrmd -licui18n -licuuc -licudata

db_SOURCES = common.hh common.cc \
   db.hh db.cc


The "hulk" directories are the directories for the project the company I work for uses. Also is the name of the library with the Qx generated classes (a lot of them.) Others are standar for their instalations, but in my home dir.
I think it could be a problem with some version library difference. I've had some problems with that but resolved finally with no "unreferences" but now it compiles well and runs without problem but... got an assert!

While waiting a response, I'm going to put all this into a QtCreator project to see if it compiles and run fine. If so, then I'll bet for the libs version mismatch issue. My target is NOT use QtCreator anyway because I need to run compilations and tests nightly.

Thank you for you help,

Manuel Cano
Attachments
code.tar.gz
Controllers class
(3.42 KiB) Downloaded 637 times
manutalcual
 
Posts: 8
Joined: Thu Dec 10, 2015 3:22 pm

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby qxorm » Fri Dec 11, 2015 11:06 am

Your attached source code contains the Controllers class, not Calendars class.
Anyway, if all classes are generated with QxEntityEditor application, they should be correct.

I think the problem is in a qx::register_class<T> function (where you define some relationships).
To confirm that, in your main function, could you please call at the beginning the : qx::QxClassX::registerAllClasses() method ?
Something like that :
Code: Select all
int main (int argc, char ** argv)
{
   QCoreApplication app (argc, argv);
   qx::QxClassX::registerAllClasses();
   // etc...
}

The qx::QxClassX::registerAllClasses() method will call all your qx::register_class<T> functions automatically, and you should have your assert : could you confirm please ?

Then about the ASSERT : do you know which value is NULL (putting a breakpoint for example before the assert) : m_pClass ? m_pClassOwner ? m_pDataMember ? m_pDataMemberX ? Or m_pDataMemberId ?

Other question : which version of QxOrm library are you using ?
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby manutalcual » Fri Dec 11, 2015 11:54 am

Hi,

Sorry about the confusion with the attached code, as you said, it has been generated with QxEntityEditor, so there should be no problem. (I attach Calendas just in case.)
QxOrm Version is 1.4.1.
I think null member is m_pDataMemberId, but I'm not sure. I'm inserting code in that header (a exit(-1)) and it doesn't gets executed. May be there is another library in my system and I'm not linking the correct one.
I've called qx::QxClassX::registerAllClasses() with no difference.

Thanks so much,

Manuel
Attachments
code.tar.gz
(1.86 KiB) Downloaded 604 times
manutalcual
 
Posts: 8
Joined: Thu Dec 10, 2015 3:22 pm

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby manutalcual » Fri Dec 11, 2015 12:05 pm

Hi again,

I keep trying things.
I've reordered the libs and get QxOrm (not QxOrmd, development version) from QxEntityEditor and now I've a problem with SQLite driver:

Code: Select all
[../../src/db.cc:30] int main(int, char**)
[../../src/db.cc:33] Create Qt Application object.
[../../src/db.cc:37] Set driver.
[../../src/db.cc:40] Set file.
[../../src/db.cc:43] Trace queries.
[../../src/db.cc:46] Trace queries (y II).
[../../src/db.cc:49] Get database object.
QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers:
[QxOrm] qx::QxSqlDatabase : 'unable to open connection to database'
Driver not loaded Driver not loaded
[../../src/db.cc:52] Set session.
[QxOrm] qx::QxSession throw 'qx::dao::sql_error' exception : 'Driver not loaded Driver not loaded'
terminate called after throwing an instance of 'qx::dao::sql_error'
  what():  Driver not loaded Driver not loaded
Aborted


I think I have a mess with libraries. With development versions it loads the drive.

Manuel Cano
manutalcual
 
Posts: 8
Joined: Thu Dec 10, 2015 3:22 pm

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby qxorm » Fri Dec 11, 2015 12:11 pm

I think null member is m_pDataMemberId

Working with relationships, the data member id (primary key in your database) is required.
That means that a t.id(...) call is missing in a qx::register_class<T> function.

I've called qx::QxClassX::registerAllClasses() with no difference.

No difference means :
1- Now you have the assert when calling qx::QxClassX::registerAllClasses() ?
2- Or you still have the assert when calling your query with : cal_ptr->qxFetchByQuery(query, lst_cal); ?

Anyway, this assert should be more explicit !
In the next release, I will replace the line 117 : qAssert(m_pClass && m_pClassOwner && m_pDataMember && m_pDataMemberX && m_pDataMemberId); in QxSqlRelation.h file with something like that :
Code: Select all
if (! m_pClass) { QString sAssertMsg = "No class registered"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
if (! m_pClassOwner) { QString sAssertMsg = "No class owner registered (" + m_pClass->getKey()  + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
if (! m_pDataMember) { QString sAssertMsg = "No data member registered (" + m_pClass->getKey()  + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
if (! m_pDataMemberX) { QString sAssertMsg = "No list of data members registered (" + m_pClass->getKey()  + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
if (! m_pDataMemberId) { QString sAssertMsg = "No data member id registered (" + m_pClass->getKey()  + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }


I've reordered the libs and get QxOrm (not QxOrmd, development version)

Do not mix debug and release binaries in your project !
It can't work !
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby manutalcual » Fri Dec 11, 2015 12:31 pm

Hi,

Second case. I have the very same assert: cal_ptr->qxFetchByQuery(query, lst_cal)

When using the editor, shouldn't be the t.id(...) generated automaticaly?

Manuel
manutalcual
 
Posts: 8
Joined: Thu Dec 10, 2015 3:22 pm

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby qxorm » Fri Dec 11, 2015 1:11 pm

When using the editor, shouldn't be the t.id(...) generated automaticaly?

Yes, each class generated by QxEntityEditor has an id, so t.id(...) call should exist in your qx::register_class<T> functions.
There are ways to customize generated files with QxEntityEditor application : do you know if generated files have been customized ?

Could you try to change QxSqlRelation.h file, line 117 (where there is the assert), by :
Code: Select all
    QString sRelationName = (m_pDataMember ? m_pDataMember->getKey() : QString("<unknown>"));
    if (! m_pClass) { QString sAssertMsg = sRelationName + " : no class registered"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
    if (! m_pClassOwner) { QString sAssertMsg = sRelationName + " : no class owner registered (" + m_pClass->getKey()  + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
    if (! m_pDataMember) { QString sAssertMsg = sRelationName + " : no data member registered (" + m_pClass->getKey()  + ", " + m_pClassOwner->getKey() + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
    if (! m_pDataMemberX) { QString sAssertMsg = sRelationName + " : no list of data members registered (" + m_pClass->getKey()  + ", " + m_pClassOwner->getKey() + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
    if (! m_pDataMemberId) { QString sAssertMsg = sRelationName + " : no data member id registered (" + m_pClass->getKey()  + ", " + m_pClassOwner->getKey() + ")"; qAssertMsg(false, "[QxOrm] qx::QxSqlRelation::init()", qPrintable(sAssertMsg)); }
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Assertion on QxSqlRelation.h, line 117 when running quer

Postby manutalcual » Fri Dec 11, 2015 1:28 pm

No, the custom dir is empty. They have been generated with default values just for my understanding.
I'm going to clean up directories and such so I _know_ for sure there is only one lib for Qt, one for Qx and one of myself and if I'm having the same problem I'll post another reply.
manutalcual
 
Posts: 8
Joined: Thu Dec 10, 2015 3:22 pm

Next

Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 10 guests