QxSqlQueryBuilder.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /****************************************************************************
  2. **
  3. ** https://www.qxorm.com/
  4. ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
  5. **
  6. ** This file is part of the QxOrm library
  7. **
  8. ** This software is provided 'as-is', without any express or implied
  9. ** warranty. In no event will the authors be held liable for any
  10. ** damages arising from the use of this software
  11. **
  12. ** Commercial Usage
  13. ** Licensees holding valid commercial QxOrm licenses may use this file in
  14. ** accordance with the commercial license agreement provided with the
  15. ** Software or, alternatively, in accordance with the terms contained in
  16. ** a written agreement between you and Lionel Marty
  17. **
  18. ** GNU General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU
  20. ** General Public License version 3.0 as published by the Free Software
  21. ** Foundation and appearing in the file 'license.gpl3.txt' included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU General Public License version 3.0 requirements will be
  24. ** met : http://www.gnu.org/copyleft/gpl.html
  25. **
  26. ** If you are unsure which license is appropriate for your use, or
  27. ** if you have questions regarding the use of this file, please contact :
  28. ** contact@qxorm.com
  29. **
  30. ****************************************************************************/
  31. #ifndef _QX_SQL_QUERY_BUILDER_H_
  32. #define _QX_SQL_QUERY_BUILDER_H_
  33. #ifdef _MSC_VER
  34. #pragma once
  35. #endif
  36. /*!
  37. * \file QxSqlQueryBuilder.h
  38. * \author Lionel Marty
  39. * \ingroup QxDao
  40. * \brief Concrete SQL query builder by class with a cache mechanism to backup and restore queries already built by the program
  41. */
  42. #include <QxDao/IxSqlQueryBuilder.h>
  43. #include <QxDao/QxSqlQueryHelper.h>
  44. #include <QxRegister/QxClass.h>
  45. #include <QxTraits/remove_attr.h>
  46. #include <QxTraits/remove_smart_ptr.h>
  47. #include <QxTraits/is_qx_registered.h>
  48. #define QX_SQL_ERR_NO_DATA_MEMBER_REGISTERED "'QxSqlQueryBuilder<T>' error : 'qx::register_class()' not called or no data member registered"
  49. #define QX_SQL_ERR_NO_ID_REGISTERED "'QxSqlQueryBuilder<T>' error : no id registered"
  50. #define QX_SQL_BUILDER_INIT_FCT(oper) \
  51. qx::dao::detail::IxDao_Timer timer(this->getDaoHelper(), qx::dao::detail::IxDao_Helper::timer_build_sql); \
  52. QString joinQueryHash = (this->getDaoHelper() ? this->getDaoHelper()->qxQuery().getJoinQueryHash() : QString()); \
  53. QString ignoreSoftDeleteHash = (this->getDaoHelper() ? this->getDaoHelper()->getIgnoreSoftDeleteHash() : QString()); \
  54. QString key = QxClass<type_sql>::getSingleton()->getKey() + joinQueryHash + ignoreSoftDeleteHash + oper; \
  55. if ((joinQueryHash.isEmpty()) && (this->findSqlQuery(key))) { return (* this); } \
  56. QString sql; Q_UNUSED(sql);
  57. #define QX_SQL_BUILDER_INIT_FCT_WITH_RELATION(oper) \
  58. qx::dao::detail::IxDao_Timer timer(this->getDaoHelper(), qx::dao::detail::IxDao_Helper::timer_build_sql); \
  59. QString joinQueryHash = (this->getDaoHelper() ? this->getDaoHelper()->qxQuery().getJoinQueryHash() : QString()); \
  60. QString ignoreSoftDeleteHash = (this->getDaoHelper() ? this->getDaoHelper()->getIgnoreSoftDeleteHash() : QString()); \
  61. QString key = QxClass<type_sql>::getSingleton()->getKey() + joinQueryHash + this->getHashRelation() + ignoreSoftDeleteHash + oper; \
  62. if ((joinQueryHash.isEmpty()) && (this->findSqlQuery(key))) { this->findSqlAlias(key); return (* this); } \
  63. QString sql; Q_UNUSED(sql);
  64. namespace qx {
  65. /*!
  66. * \ingroup QxDao
  67. * \brief qx::QxSqlQueryBuilder<T> : concrete SQL query builder for class T with a cache mechanism to backup and restore queries already built by the program
  68. */
  69. template <class T>
  70. class QxSqlQueryBuilder : public IxSqlQueryBuilder
  71. {
  72. private:
  73. typedef typename qx::trait::remove_attr<T>::type type_sql_tmp_1;
  74. typedef typename qx::trait::remove_smart_ptr<type_sql_tmp_1>::type type_sql_tmp_2;
  75. public:
  76. typedef typename qx::QxSqlQueryBuilder<T>::type_sql_tmp_2 type_sql;
  77. public:
  78. QxSqlQueryBuilder() : IxSqlQueryBuilder() { ; }
  79. virtual ~QxSqlQueryBuilder() { static_assert(qx::trait::is_qx_registered<type_sql>::value, "qx::trait::is_qx_registered<type_sql>::value"); }
  80. virtual void init()
  81. {
  82. if (isInitDone()) { return; }
  83. setDataMemberX(QxClass<type_sql>::getSingleton()->dataMemberX());
  84. setSoftDelete(QxClass<type_sql>::getSingleton()->getSoftDelete());
  85. IxSqlQueryBuilder::init();
  86. }
  87. };
  88. /*!
  89. * \ingroup QxDao
  90. * \brief qx::QxSqlQueryBuilder_Count<T> : concrete SQL query builder for class T to build a COUNT SQL query
  91. */
  92. template <class T>
  93. class QxSqlQueryBuilder_Count : public QxSqlQueryBuilder<T>
  94. {
  95. public:
  96. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  97. QxSqlQueryBuilder_Count() : QxSqlQueryBuilder<T>() { ; }
  98. virtual ~QxSqlQueryBuilder_Count() { ; }
  99. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  100. {
  101. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  102. QX_SQL_BUILDER_INIT_FCT("Count")
  103. sql = "SELECT COUNT(*) FROM " + qx::IxDataMember::getSqlFromTable(this->table());
  104. if (! this->softDelete().isEmpty()) { sql += " WHERE " + this->softDelete().buildSqlQueryToFetch(); }
  105. this->setSqlQuery(sql, key);
  106. return (* this);
  107. }
  108. };
  109. /*!
  110. * \ingroup QxDao
  111. * \brief qx::QxSqlQueryBuilder_Exist<T> : concrete SQL query builder for class T to build an EXIST SQL query
  112. */
  113. template <class T>
  114. class QxSqlQueryBuilder_Exist : public QxSqlQueryBuilder<T>
  115. {
  116. public:
  117. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  118. QxSqlQueryBuilder_Exist() : QxSqlQueryBuilder<T>() { ; }
  119. virtual ~QxSqlQueryBuilder_Exist() { ; }
  120. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  121. {
  122. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  123. QX_SQL_BUILDER_INIT_FCT("Exist")
  124. if (! this->getDataId()) { qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED); qAssert(false); return (* this); }
  125. qx::dao::detail::QxSqlQueryHelper_Exist<type_sql>::sql(sql, (* this));
  126. this->setSqlQuery(sql, key);
  127. return (* this);
  128. }
  129. };
  130. /*!
  131. * \ingroup QxDao
  132. * \brief qx::QxSqlQueryBuilder_FetchAll<T> : concrete SQL query builder for class T to build a FETCH ALL SQL query
  133. */
  134. template <class T>
  135. class QxSqlQueryBuilder_FetchAll : public QxSqlQueryBuilder<T>
  136. {
  137. public:
  138. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  139. QxSqlQueryBuilder_FetchAll() : QxSqlQueryBuilder<T>() { ; }
  140. virtual ~QxSqlQueryBuilder_FetchAll() { ; }
  141. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  142. {
  143. Q_UNUSED(pRelationX);
  144. if ((columns.count() <= 0) || (columns.at(0) == "*"))
  145. {
  146. QX_SQL_BUILDER_INIT_FCT("FetchAll")
  147. qx::dao::detail::QxSqlQueryHelper_FetchAll<type_sql>::sql(sql, (* this));
  148. this->setSqlQuery(sql, key);
  149. }
  150. else
  151. {
  152. QString sql;
  153. if (! this->verifyColumns(columns)) { return (* this); }
  154. qx::dao::detail::QxSqlQueryHelper_FetchAll<type_sql>::sql(sql, (* this), columns);
  155. this->setSqlQuery(sql);
  156. }
  157. return (* this);
  158. }
  159. };
  160. /*!
  161. * \ingroup QxDao
  162. * \brief qx::QxSqlQueryBuilder_FetchById<T> : concrete SQL query builder for class T to build a FETCH BY ID SQL query
  163. */
  164. template <class T>
  165. class QxSqlQueryBuilder_FetchById : public QxSqlQueryBuilder<T>
  166. {
  167. public:
  168. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  169. QxSqlQueryBuilder_FetchById() : QxSqlQueryBuilder<T>() { ; }
  170. virtual ~QxSqlQueryBuilder_FetchById() { ; }
  171. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  172. {
  173. Q_UNUSED(pRelationX);
  174. if (! this->getDataId()) { qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED); qAssert(false); return (* this); }
  175. QxSqlQueryBuilder_FetchAll<type_sql> builder; builder.clone(* this);
  176. if ((columns.count() <= 0) || (columns.at(0) == "*"))
  177. {
  178. QX_SQL_BUILDER_INIT_FCT("FetchById")
  179. qx::dao::detail::QxSqlQueryHelper_FetchById<type_sql>::sql(sql, builder);
  180. this->setSqlQuery(sql, key);
  181. }
  182. else
  183. {
  184. QString sql;
  185. if (! this->verifyColumns(columns)) { return (* this); }
  186. qx::dao::detail::QxSqlQueryHelper_FetchById<type_sql>::sql(sql, builder, columns);
  187. this->setSqlQuery(sql);
  188. }
  189. return (* this);
  190. }
  191. };
  192. /*!
  193. * \ingroup QxDao
  194. * \brief qx::QxSqlQueryBuilder_Insert<T> : concrete SQL query builder for class T to build an INSERT SQL query
  195. */
  196. template <class T>
  197. class QxSqlQueryBuilder_Insert : public QxSqlQueryBuilder<T>
  198. {
  199. public:
  200. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  201. QxSqlQueryBuilder_Insert() : QxSqlQueryBuilder<T>() { ; }
  202. virtual ~QxSqlQueryBuilder_Insert() { ; }
  203. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  204. {
  205. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  206. QX_SQL_BUILDER_INIT_FCT("Insert")
  207. qx::dao::detail::QxSqlQueryHelper_Insert<type_sql>::sql(sql, (* this));
  208. this->setSqlQuery(sql, key);
  209. return (* this);
  210. }
  211. };
  212. /*!
  213. * \ingroup QxDao
  214. * \brief qx::QxSqlQueryBuilder_Update<T> : concrete SQL query builder for class T to build an UPDATE SQL query
  215. */
  216. template <class T>
  217. class QxSqlQueryBuilder_Update : public QxSqlQueryBuilder<T>
  218. {
  219. public:
  220. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  221. QxSqlQueryBuilder_Update() : QxSqlQueryBuilder<T>() { ; }
  222. virtual ~QxSqlQueryBuilder_Update() { ; }
  223. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  224. {
  225. Q_UNUSED(pRelationX);
  226. if (! this->getDataId()) { qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED); qAssert(false); return (* this); }
  227. if ((columns.count() <= 0) || (columns.at(0) == "*"))
  228. {
  229. QX_SQL_BUILDER_INIT_FCT("Update")
  230. qx::dao::detail::QxSqlQueryHelper_Update<type_sql>::sql(sql, (* this));
  231. this->setSqlQuery(sql, key);
  232. }
  233. else
  234. {
  235. QString sql;
  236. if (! this->verifyColumns(columns)) { return (* this); }
  237. qx::dao::detail::QxSqlQueryHelper_Update<type_sql>::sql(sql, (* this), columns);
  238. this->setSqlQuery(sql);
  239. }
  240. return (* this);
  241. }
  242. };
  243. /*!
  244. * \ingroup QxDao
  245. * \brief qx::QxSqlQueryBuilder_DeleteAll<T> : concrete SQL query builder for class T to build a DELETE ALL SQL query
  246. */
  247. template <class T>
  248. class QxSqlQueryBuilder_DeleteAll : public QxSqlQueryBuilder<T>
  249. {
  250. public:
  251. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  252. QxSqlQueryBuilder_DeleteAll() : QxSqlQueryBuilder<T>() { ; }
  253. virtual ~QxSqlQueryBuilder_DeleteAll() { ; }
  254. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  255. {
  256. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  257. QX_SQL_BUILDER_INIT_FCT("DeleteAll")
  258. sql = "DELETE FROM " + this->table();
  259. this->setSqlQuery(sql, key);
  260. return (* this);
  261. }
  262. };
  263. /*!
  264. * \ingroup QxDao
  265. * \brief qx::QxSqlQueryBuilder_SoftDeleteAll<T> : concrete SQL query builder for class T to build a SOFT DELETE ALL SQL query
  266. */
  267. template <class T>
  268. class QxSqlQueryBuilder_SoftDeleteAll : public QxSqlQueryBuilder<T>
  269. {
  270. public:
  271. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  272. QxSqlQueryBuilder_SoftDeleteAll() : QxSqlQueryBuilder<T>() { ; }
  273. virtual ~QxSqlQueryBuilder_SoftDeleteAll() { ; }
  274. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  275. {
  276. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  277. QX_SQL_BUILDER_INIT_FCT("SoftDeleteAll")
  278. if (! this->softDelete().isEmpty()) { sql = "UPDATE " + this->table() + " SET " + this->softDelete().buildSqlQueryToUpdate(); }
  279. else { qAssert(false); }
  280. this->setSqlQuery(sql, key);
  281. return (* this);
  282. }
  283. };
  284. /*!
  285. * \ingroup QxDao
  286. * \brief qx::QxSqlQueryBuilder_DeleteById<T> : concrete SQL query builder for class T to build a DELETE BY ID SQL query
  287. */
  288. template <class T>
  289. class QxSqlQueryBuilder_DeleteById : public QxSqlQueryBuilder<T>
  290. {
  291. public:
  292. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  293. QxSqlQueryBuilder_DeleteById() : QxSqlQueryBuilder<T>() { ; }
  294. virtual ~QxSqlQueryBuilder_DeleteById() { ; }
  295. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  296. {
  297. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  298. QX_SQL_BUILDER_INIT_FCT("DeleteById")
  299. if (! this->getDataId()) { qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED); qAssert(false); return (* this); }
  300. qx::dao::detail::QxSqlQueryHelper_DeleteById<type_sql>::sql(sql, (* this), false);
  301. this->setSqlQuery(sql, key);
  302. return (* this);
  303. }
  304. };
  305. /*!
  306. * \ingroup QxDao
  307. * \brief qx::QxSqlQueryBuilder_SoftDeleteById<T> : concrete SQL query builder for class T to build a SOFT DELETE BY ID SQL query
  308. */
  309. template <class T>
  310. class QxSqlQueryBuilder_SoftDeleteById : public QxSqlQueryBuilder<T>
  311. {
  312. public:
  313. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  314. QxSqlQueryBuilder_SoftDeleteById() : QxSqlQueryBuilder<T>() { ; }
  315. virtual ~QxSqlQueryBuilder_SoftDeleteById() { ; }
  316. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  317. {
  318. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  319. QX_SQL_BUILDER_INIT_FCT("SoftDeleteById")
  320. if (! this->getDataId()) { qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED); qAssert(false); return (* this); }
  321. if (this->softDelete().isEmpty()) { qAssert(false); return (* this); }
  322. qx::dao::detail::QxSqlQueryHelper_DeleteById<type_sql>::sql(sql, (* this), true);
  323. this->setSqlQuery(sql, key);
  324. return (* this);
  325. }
  326. };
  327. /*!
  328. * \ingroup QxDao
  329. * \brief qx::QxSqlQueryBuilder_CreateTable<T> : concrete SQL query builder for class T to build a CREATE TABLE SQL query
  330. */
  331. template <class T>
  332. class QxSqlQueryBuilder_CreateTable : public QxSqlQueryBuilder<T>
  333. {
  334. public:
  335. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  336. QxSqlQueryBuilder_CreateTable() : QxSqlQueryBuilder<T>() { ; }
  337. virtual ~QxSqlQueryBuilder_CreateTable() { ; }
  338. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  339. {
  340. Q_UNUSED(columns); Q_UNUSED(pRelationX);
  341. QX_SQL_BUILDER_INIT_FCT("CreateTable")
  342. qx::dao::detail::QxSqlQueryHelper_CreateTable<type_sql>::sql(sql, (* this));
  343. this->setSqlQuery(sql, key);
  344. return (* this);
  345. }
  346. };
  347. /*!
  348. * \ingroup QxDao
  349. * \brief qx::QxSqlQueryBuilder_Count_WithRelation<T> : concrete SQL query builder for class T to build a COUNT WITH RELATION SQL query
  350. */
  351. template <class T>
  352. class QxSqlQueryBuilder_Count_WithRelation : public QxSqlQueryBuilder<T>
  353. {
  354. public:
  355. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  356. QxSqlQueryBuilder_Count_WithRelation() : QxSqlQueryBuilder<T>() { ; }
  357. virtual ~QxSqlQueryBuilder_Count_WithRelation() { ; }
  358. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  359. {
  360. Q_UNUSED(columns);
  361. QX_SQL_BUILDER_INIT_FCT_WITH_RELATION("Count_WithRelation")
  362. IxSqlQueryBuilder::sql_Count_WithRelation(pRelationX, sql, (* this));
  363. this->setSqlQuery(sql, key);
  364. this->insertSqlAlias(key);
  365. return (* this);
  366. }
  367. };
  368. /*!
  369. * \ingroup QxDao
  370. * \brief qx::QxSqlQueryBuilder_FetchAll_WithRelation<T> : concrete SQL query builder for class T to build a FETCH ALL WITH RELATION SQL query
  371. */
  372. template <class T>
  373. class QxSqlQueryBuilder_FetchAll_WithRelation : public QxSqlQueryBuilder<T>
  374. {
  375. public:
  376. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  377. QxSqlQueryBuilder_FetchAll_WithRelation() : QxSqlQueryBuilder<T>() { ; }
  378. virtual ~QxSqlQueryBuilder_FetchAll_WithRelation() { ; }
  379. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  380. {
  381. Q_UNUSED(columns);
  382. QX_SQL_BUILDER_INIT_FCT_WITH_RELATION("FetchAll_WithRelation")
  383. qx::dao::detail::QxSqlQueryHelper_FetchAll_WithRelation<type_sql>::sql(pRelationX, sql, (* this));
  384. this->setSqlQuery(sql, key);
  385. this->insertSqlAlias(key);
  386. return (* this);
  387. }
  388. };
  389. /*!
  390. * \ingroup QxDao
  391. * \brief qx::QxSqlQueryBuilder_FetchById_WithRelation<T> : concrete SQL query builder for class T to build a FETCH BY ID WITH RELATION SQL query
  392. */
  393. template <class T>
  394. class QxSqlQueryBuilder_FetchById_WithRelation : public QxSqlQueryBuilder<T>
  395. {
  396. public:
  397. typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
  398. QxSqlQueryBuilder_FetchById_WithRelation() : QxSqlQueryBuilder<T>() { ; }
  399. virtual ~QxSqlQueryBuilder_FetchById_WithRelation() { ; }
  400. virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL)
  401. {
  402. Q_UNUSED(columns);
  403. QX_SQL_BUILDER_INIT_FCT_WITH_RELATION("FetchById_WithRelation")
  404. if (! this->getDataId()) { qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED); qAssert(false); return (* this); }
  405. QxSqlQueryBuilder_FetchAll_WithRelation<type_sql> builder; builder.clone(* this);
  406. qx::dao::detail::QxSqlQueryHelper_FetchById_WithRelation<type_sql>::sql(pRelationX, sql, builder);
  407. this->setSqlQuery(sql, key);
  408. this->insertSqlAlias(key);
  409. return (* this);
  410. }
  411. };
  412. } // namespace qx
  413. #endif // _QX_SQL_QUERY_BUILDER_H_