Herunterladen als
root/src/schema.h @ 49762cb7
c22391b2 | Christian Ehringfeld | /*
|
|
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
|||
*
|
|||
* This program is free software; you can redistribute it and/or modify it
|
|||
* under the terms of the GNU Lesser General Public License as published by
|
|||
* the Free Software Foundation.
|
|||
*
|
|||
* This program is distributed in the hope that it will be useful, but
|
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|||
* for more details.
|
|||
*
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
|||
aa44e7d1 | Christian Ehringfeld | #ifndef SCHEMA_H
|
|
#define SCHEMA_H
|
|||
9cf4747e | Christian Ehringfeld | #include <QStringList>
|
|
b0b8dac3 | Christian Ehringfeld | #include <QHash>
|
|
#include <QSharedPointer>
|
|||
14f9beed | Christian Ehringfeld | #include <QSqlField>
|
|
82442988 | Christian Ehringfeld | #include "tableschema.h"
|
|
b0bf458e | Christian Ehringfeld | #include "querybuilder.h"
|
|
4d58ef6a | Christian Ehringfeld | namespace CuteEntityManager {
|
|
14f9beed | Christian Ehringfeld | class Database;
|
|
4d58ef6a | Christian Ehringfeld | class Schema {
|
|
426974c6 | Christian Ehringfeld | public:
|
|
696666eb | Christian Ehringfeld | Schema(QSharedPointer<Database> database, QSharedPointer<QueryBuilder> builder);
|
|
b0b8dac3 | Christian Ehringfeld | virtual ~Schema();
|
|
24c5480c | Christian Ehringfeld | //http://doc.qt.io/qt-5/sql-types.html
|
|
b0b8dac3 | Christian Ehringfeld | const QString TYPE_PK = "pk";
|
|
const QString TYPE_BIGPK = "bigpk";
|
|||
const QString TYPE_STRING = "string";
|
|||
const QString TYPE_TEXT = "text";
|
|||
const QString TYPE_SMALLINT = "smallint";
|
|||
const QString TYPE_INTEGER = "integer";
|
|||
const QString TYPE_BIGINT = "bigint";
|
|||
const QString TYPE_FLOAT = "float";
|
|||
const QString TYPE_DOUBLE = "double";
|
|||
const QString TYPE_DECIMAL = "decimal";
|
|||
const QString TYPE_DATETIME = "datetime";
|
|||
const QString TYPE_TIMESTAMP = "timestamp";
|
|||
const QString TYPE_TIME = "time";
|
|||
const QString TYPE_DATE = "date";
|
|||
14f9beed | Christian Ehringfeld | const QString TYPE_CHAR = "char";
|
|
b0b8dac3 | Christian Ehringfeld | const QString TYPE_BINARY = "binary";
|
|
const QString TYPE_BOOLEAN = "boolean";
|
|||
const QString TYPE_MONEY = "money";
|
|||
a604a5a2 | Christian Ehringfeld | ||
3b5d8beb | Christian Ehringfeld | QString primaryKey(int length = 0) const;
|
|
QString bigPrimaryKey(int length = 0) const;
|
|||
QString string(int length = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString text(bool notNull = false, QString defaultValue = "",
|
|||
bool unique = false, QString checkConstraint = "") const;
|
|||
QString smallInteger(int length = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString integer(int length = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString bigInteger(int length = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString floatColumn(int precision = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString doubleColumn(int precision = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString decimal(int precision = 0, int scale = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString dateTime(int precision = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString timestamp(int precision = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString time(int precision = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString date( bool notNull = false, QString defaultValue = "") const;
|
|||
QString binary(int length = 0, bool notNull = false, bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
QString boolean(QString defaultValue = "", bool notNull = false) const;
|
|||
QString money(int precision = 0, int scale = 0, bool notNull = false,
|
|||
QString defaultValue = "", bool unique = false,
|
|||
QString checkConstraint = "") const;
|
|||
975a7f96 | Christian Ehringfeld | ||
24425325 | Christian Ehringfeld | virtual QSharedPointer<QHash<QString, QString> >getTypeMap() = 0;
|
|
a604a5a2 | Christian Ehringfeld | virtual QString quoteSimpleTableName(QString name);
|
|
426974c6 | Christian Ehringfeld | virtual QString quoteTableName(QString name);
|
|
virtual QString quoteColumnName(QString name);
|
|||
a604a5a2 | Christian Ehringfeld | virtual QString quoteSimpleColumnName(QString name);
|
|
e0e1ead8 | Christian Ehringfeld | virtual QHash<QString, QSharedPointer<TableSchema>> getTableSchemas(
|
|
QString schema = "",
|
|||
bool refresh = false);
|
|||
virtual QSharedPointer<TableSchema> getTableSchema(QString name,
|
|||
bool refresh = false);
|
|||
caea9141 | Christian Ehringfeld | virtual QStringList getTableNames(QString schema = "");
|
|
9cf4747e | Christian Ehringfeld | virtual QVariant getLastInsertID();
|
|
a604a5a2 | Christian Ehringfeld | virtual void refresh();
|
|
426974c6 | Christian Ehringfeld | virtual QString getRawTable(QString name);
|
|
14f9beed | Christian Ehringfeld | virtual bool containsTable(QString tblname);
|
|
01fe6db3 | Christian Ehringfeld | virtual bool containsColumn(QString tblName, QString colName);
|
|
b0b8dac3 | Christian Ehringfeld | ||
0d155b40 | Christian Ehringfeld | QHash<QString, QSharedPointer<TableSchema> > getTables();
|
|
9cf4747e | Christian Ehringfeld | void setTables(const QHash<QString, QSharedPointer<TableSchema> > &value);
|
|
426974c6 | Christian Ehringfeld | ||
14f9beed | Christian Ehringfeld | QSharedPointer<Database> getDatabase() const;
|
|
void setDatabase(const QSharedPointer<Database> &value);
|
|||
b0bf458e | Christian Ehringfeld | QSharedPointer<QueryBuilder> getQueryBuilder() const;
|
|
24425325 | Christian Ehringfeld | QSharedPointer<QHash<QString, QString> > getAbstractTypeMap() const;
|
|
void setAbstractTypeMap(const QSharedPointer<QHash<QString, QString> > &value);
|
|||
ba800d6d | Christian Ehringfeld | protected:
|
|
3b5d8beb | Christian Ehringfeld | virtual QString buildColumnSchema(QString type, QString length,
|
|
bool notNull = false, QString defaultValue = "",
|
|||
bool unique = false, QString checkConstraint = "") const;
|
|||
12c34ebc | Christian Ehringfeld | virtual QString buildLengthString(QString length) const;
|
|
virtual QString buildNotNullString(bool notNull) const;
|
|||
virtual QString buildUniqueString(bool unique) const;
|
|||
virtual QString buildDefaultString(QString def) const;
|
|||
virtual QString buildCheckString(QString check) const;
|
|||
3b5d8beb | Christian Ehringfeld | virtual QString lengthToString(int length) const;
|
|
fe8705df | Christian Ehringfeld | virtual QString combineScaleAndPrecision(int precision, int scale) const;
|
|
12c34ebc | Christian Ehringfeld | ||
9cf4747e | Christian Ehringfeld | virtual QStringList findTableNames(QString schema = "") = 0;
|
|
e0e1ead8 | Christian Ehringfeld | virtual QHash<QString, QStringList> findUniqueIndexes(const
|
|
QSharedPointer<TableSchema>
|
|||
&table) = 0;
|
|||
14f9beed | Christian Ehringfeld | virtual void findConstraints(const QSharedPointer<TableSchema> &ts) = 0;
|
|
829c3e69 | Christian Ehringfeld | virtual bool findColumns(const QSharedPointer<TableSchema> &ts);
|
|
14f9beed | Christian Ehringfeld | virtual QSharedPointer<TableSchema> loadTableSchema(QString name) = 0;
|
|
696666eb | Christian Ehringfeld | virtual void initAbstractDatabaseTypes();
|
|
14f9beed | Christian Ehringfeld | QSharedPointer<Database> database;
|
|
QSharedPointer<QHash<QString, QString>> typeMap;
|
|||
24425325 | Christian Ehringfeld | QSharedPointer<QHash<QString, QString>> abstractTypeMap;
|
|
9cf4747e | Christian Ehringfeld | QHash<QString, QSharedPointer<TableSchema>> tables;
|
|
b0bf458e | Christian Ehringfeld | QSharedPointer<QueryBuilder> queryBuilder;
|
|
4d58ef6a | Christian Ehringfeld | };
|
|
}
|
|||
aa44e7d1 | Christian Ehringfeld | #endif // SCHEMA_H
|