How to make a complicated query between 2 tables

Forum for posting problems using QxOrm library

Re: How to make a complicated query between 2 tables

Postby alecn2002 » Wed Apr 24, 2013 10:46 am

Moreover.

Due to the nature of DB I'm trying to use QxOrm with, I need to enclose all SQL names into double quotation marks ("), so I've modified my code like the following (BTW I've fixed missed relation to ObjectType):


Code: Select all
    QSqlError ProcessDAO::read_by_type_and_objtype_with_relations(Process_list& proc, const QString& ptype, const QString& objtype)
    {
    const QStringList ProcessDAO::relations(
            QStringList()
                        << "process_type_id"
                        << "owner_id"
                        << "so_id"
                        << "Object_list->Document_list->File_list"
                        << "Object_list->object_type_id"
                        << "Document_list->File_list");

        qx::QxSqlQuery query;
        query.where("\"ProcessType\".\"short_name\"").isEqualTo(ptype)
                .and_("\"ObjectType\".\"short_name\"").isEqualTo(objtype);
        return qx::dao::fetch_by_query_with_relation(relations, query, proc);
    }


and got this generated SQL:

Code: Select all
FROM "Process"
LEFT OUTER JOIN "ProcessType" "ProcessType_1" ON "ProcessType_1"."id" = "Process"."process_type_id"
LEFT OUTER JOIN "Company" "Company_2" ON "Company_2"."id" = "Process"."owner_id"
LEFT OUTER JOIN "Company" "Company_3" ON "Company_3"."id" = "Process"."so_id"
LEFT OUTER JOIN "ProcessObject" "ProcessObject_4" ON "Process"."id" = "ProcessObject_4"."process_id"
LEFT OUTER JOIN "Object" "Object_4" ON "ProcessObject_4"."object_id" = "Object_4"."id"
LEFT OUTER JOIN "ObjectType" "ObjectType_5" ON "ObjectType_5"."id" = "Object_4"."object_type_id"
LEFT OUTER JOIN "Document" "Document_9" ON "Document_9"."process_id" = "Process"."id"
LEFT OUTER JOIN "File" "File_13" ON "File_13"."document_id" = "Document_9"."id"
WHERE "ProcessType_1"."short_name" = :"ProcessType_1"_"short_name"_1_0
AND "ObjectType"."short_name" = :"ObjectType"_"short_name"_3_0
alecn2002
 
Posts: 6
Joined: Wed Apr 24, 2013 8:59 am

Re: How to make a complicated query between 2 tables

Postby qxorm » Thu Apr 25, 2013 6:50 am

Sorry, I don't understand : please, could you provide more details :
* what is your database engine ?
* could you provide your classes regsitered into QxOrm context (*.h and *.cpp) ?
* what is exactly your problem (what SQL query are you waiting for) ?

And this subject is quite old, please next time create a new topic on this forum...
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Previous

Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 18 guests

cron