-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is not enabled because Qt sql driver doesn't support EXPLAIN queries.
- Loading branch information
Showing
3 changed files
with
78 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
#ifndef ORM_CONCERNS_EXPLAINQUERIES_HPP | ||
#define ORM_CONCERNS_EXPLAINQUERIES_HPP | ||
|
||
#include "orm/macros/systemheader.hpp" | ||
TINY_SYSTEM_HEADER | ||
|
||
#include <QtSql/QSqlQuery> | ||
|
||
#include "orm/macros/commonnamespace.hpp" | ||
#include "orm/macros/export.hpp" | ||
|
||
TINYORM_BEGIN_COMMON_NAMESPACE | ||
|
||
namespace Orm | ||
{ | ||
namespace Query | ||
{ | ||
class Builder; | ||
} | ||
using QueryBuilder = Query::Builder; | ||
|
||
namespace Concerns | ||
{ | ||
|
||
/*! Counts the number of executed queries and the elapsed time of queries. */ | ||
class SHAREDLIB_EXPORT ExplainQueries | ||
{ | ||
public: | ||
/*! Default constructor. */ | ||
inline ExplainQueries() = default; | ||
/*! Virtual destructor. */ | ||
inline virtual ~ExplainQueries() = default; | ||
|
||
/*! Explains the query. */ | ||
QSqlQuery explain(); | ||
|
||
private: | ||
/*! Dynamic cast *this to the QueryBuilder & derived type. */ | ||
QueryBuilder &builder(); | ||
}; | ||
|
||
} // namespace Concerns | ||
} // namespace Orm | ||
|
||
TINYORM_END_COMMON_NAMESPACE | ||
|
||
#endif // ORM_CONCERNS_EXPLAINQUERIES_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "orm/concerns/explainqueries.hpp" | ||
|
||
#include "orm/databaseconnection.hpp" | ||
#include "orm/query/querybuilder.hpp" | ||
|
||
TINYORM_BEGIN_COMMON_NAMESPACE | ||
|
||
namespace Orm::Concerns | ||
{ | ||
|
||
/* public */ | ||
|
||
// BUG Qt sql driver does not support to call EXPLAIN as a prepared statement, look at enum StatementType and QSqlDriver::sqlStatement in qsqldriver.h/cpp, also don't forget to add proxies when Qt will support EXPLAIN queries silverqx | ||
QSqlQuery ExplainQueries::explain() | ||
{ | ||
return builder().getConnection().select( | ||
QStringLiteral("EXPLAIN %1").arg(builder().toSql()), | ||
builder().getBindings()); | ||
} | ||
|
||
/* private */ | ||
|
||
QueryBuilder &ExplainQueries::builder() | ||
{ | ||
return dynamic_cast<QueryBuilder &>(*this); | ||
} | ||
|
||
} // namespace Orm::Concerns | ||
|
||
TINYORM_END_COMMON_NAMESPACE |