From 5d9314f134ddd3dc4c853e398ac90ba247fb2e4f Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Mon, 13 Jun 2016 18:42:42 -0400 Subject: Imported Upstream version 3.1.0 --- SQLiteStudio3/coreSQLiteStudio/querygenerator.h | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 SQLiteStudio3/coreSQLiteStudio/querygenerator.h (limited to 'SQLiteStudio3/coreSQLiteStudio/querygenerator.h') diff --git a/SQLiteStudio3/coreSQLiteStudio/querygenerator.h b/SQLiteStudio3/coreSQLiteStudio/querygenerator.h new file mode 100644 index 0000000..3f7df9c --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/querygenerator.h @@ -0,0 +1,75 @@ +#ifndef QUERYGENERATOR_H +#define QUERYGENERATOR_H + +#include "common/column.h" +#include "dialect.h" +#include "common/bistrhash.h" +#include "schemaresolver.h" +#include "common/strhash.h" +#include +#include + +class Db; + +class API_EXPORT QueryGenerator +{ + public: + QueryGenerator(); + + /** + * @brief Generates select of all column from the \p table having given column values matched. + * @overload + */ + QString generateSelectFromTable(Db* db, const QString& table, const StrHash values = StrHash()); + + /** + * @brief Generates SELECT of all column from the \p table having given column values matched. + * @param db Database where the \p table exists. + * @param database Attach name of the database (such as "main" or "temp", or any other used for ATTACH). + * @param table Table to generate select for. + * @param values Values to comply with. + * @return SELECT statement string. + * + * Generates SELECT for given table, listing all result columns explicitly and adding WHERE clause (if \p values is not empty) with columns included in \p values + * having any of values specified for those columns in that parameter. + * + * If \p values is ommited, then no WHERE clause is added. + */ + QString generateSelectFromTable(Db* db, const QString& database, const QString& table, const StrHash values = StrHash()); + + QString generateInsertToTable(Db* db, const QString& table, const StrHash values = StrHash()); + QString generateInsertToTable(Db* db, const QString& database, const QString& table, StrHash values = StrHash()); + + QString generateUpdateOfTable(Db* db, const QString& table, const StrHash values = StrHash()); + QString generateUpdateOfTable(Db* db, const QString& database, const QString& table, StrHash values = StrHash()); + + QString generateDeleteFromTable(Db* db, const QString& table, const StrHash values = StrHash()); + QString generateDeleteFromTable(Db* db, const QString& database, const QString& table, StrHash values = StrHash()); + + QString generateSelectFromView(Db* db, const QString& view, const StrHash values = StrHash()); + QString generateSelectFromView(Db* db, const QString& database, const QString& view, const StrHash values = StrHash()); + + /** + * @brief Generates SELECT for all columns from the \p initialSelect having values matched. + * @param db Database that will be used to resolve tables used in the \p initialSelect + * @param initialSelect The SELECT statement that will be used as a base for generating new query. + * @param values Map of column names and values for them, so the WHERE clause is generated for them. + * @param dbNameToAttach If the \p initialSelect uses attached databases, they should be provided in this parameter, so their symbolic names can be resolved to real attach name. + * @return Generated SELECT statement string. + * + * Generates SELECT using \p initialSelect as a base. Lists all columns from \p initialSelect result columns explicitly (no star operator). + * If there are \p values given, then the WHERE clause is added for them to match columns. + */ + QString generateSelectFromSelect(Db* db, const QString& initialSelect, const StrHash values = StrHash(), const BiStrHash& dbNameToAttach = BiStrHash()); + + private: + QString generateSelectFromTableOrView(Db* db, const QString& database, const QString& tableOrView, const QStringList& columns, const StrHash values = StrHash()); + QString getAlias(const QString& name, QSet& usedAliases); + QStringList valuesToConditionList(const StrHash& values, Dialect dialect); + QString valuesToConditionStr(const StrHash& values, Dialect dialect); + QString toResultColumnString(const SelectResolver::Column& column, Dialect dialect); + QString toFullObjectName(const QString& database, const QString& object, Dialect dialect); + QStringList toValueSets(const QStringList& columns, const StrHash values, Dialect dialect); +}; + +#endif // QUERYGENERATOR_H -- cgit v1.2.3