diff --git a/bin/xyylMCWEACSystem.exe b/bin/xyylMCWEACSystem.exe index 89fee60..9ababc8 100644 Binary files a/bin/xyylMCWEACSystem.exe and b/bin/xyylMCWEACSystem.exe differ diff --git a/xyylMCWEACSystem/SqlGenerate.cpp b/xyylMCWEACSystem/SqlGenerate.cpp new file mode 100644 index 0000000..396bd77 --- /dev/null +++ b/xyylMCWEACSystem/SqlGenerate.cpp @@ -0,0 +1,211 @@ + +#include "SqlGenerate.h" +#include + +SqlGenerate::SqlGenerate() +{ + +} + +SqlGenerate::~SqlGenerate() +{ + +} + +QString SqlGenerate::createTable(QString table, QMap map) +{ + QString content = QString("create table %1 (").arg(table); + QMapIterator i(map); + while (i.hasNext()) + { + i.next(); + content.append(QString("%1 %2 ").arg(i.key()).arg(i.value())); + if (i.hasNext()) + { + content.append(","); + } + } + content.append(")"); + content += QString(";"); + return content; +} + +QString SqlGenerate::insertData(QString table, QVariantMap map) +{ + //insert or replace into + QString content = QString("insert or replace into %1 (").arg(table); + QString values = QString("values("); + QMapIterator i(map); + while (i.hasNext()) + { + i.next(); + content.append(QString("%1").arg(i.key())); + values.append("'" + i.value().toString().replace("'", "''") + "'"); // + if (i.hasNext()) + { + content.append(", "); + values.append(","); + } + } + content.append(") "); + values.append(")"); + content.append(values); + content += QString(";"); + return content; +} + +QString SqlGenerate::selectWhere(QString table, QStringList Name, QString condition) +{ + //QString content = QString("select from %1 ").arg(table); + QString content = QString("select ");// .arg(table); + QListIterator i(Name); + while (i.hasNext()) + { + i.next(); + if (i.hasNext()) + { + content += QString(" %1 ,").arg(i.previous()); + } + else + { + content += QString(" %1 ").arg(i.previous()); + } + i.next(); + + } + /*for(int i = 0; i < Name.size(); i++) + { + if (i + 1 == Name.size()) + { + content += QString("%1 ").arg(Name.at(i)); + } + else + { + content += QString("%1,").arg(Name.at(i)); + } + }*/ + content += QString("from %1").arg(table); + if (!condition.isEmpty()) + { + content += condition;// QString(" where %1").arg(condition); + } + content += QString(";");// + + + + return content; +} + +QString SqlGenerate::selectUnion(QStringList sTables, QStringList Name, QString condition /*= ""*/) +{ + QString s_select_Data; + for (int j = 0; j < sTables.size(); j++) + { + + QString content = QString("select ");// .arg(table); + QListIterator i(Name); + while (i.hasNext()) + { + i.next(); + if (i.hasNext()) + { + content += QString(" %1 ,").arg(i.previous()); + } + else + { + content += QString(" %1 ").arg(i.previous()); + } + i.next(); + + } + content += QString("from %1").arg(sTables.at(j)); + + if (s_select_Data.isEmpty()) + { + s_select_Data = content; + } + else + { + s_select_Data = s_select_Data + " union all " + content; + } + } + if (!condition.isEmpty()) + { + s_select_Data += condition;// QString(" where %1").arg(condition); + } + s_select_Data += QString(";");// + + return s_select_Data; +} + +QString SqlGenerate::createIndex(QString table, QString name) +{ + QString content = QString("create index %1_index on %2 (%3)").arg(name).arg(table).arg(name); + content += QString(";");// + return content; +} + +QString SqlGenerate::updateData(QString table, QVariantMap map, QString condition) +{ + QString content = QString("update %1 set ").arg(table); + QMapIteratori(map); + while (i.hasNext()) + { + i.next(); + if (i.hasNext()) + { + content += QString("%1 = '%2',").arg(i.key()).arg(i.value().toString().replace("'", "''")); + } + else + { + content += QString("%1= '%2' ").arg(i.key()).arg(i.value().toString().replace("'", "''")); + } + + } + content += QString("where %1").arg(condition); + content += QString(";"); + return content; +} + +QString SqlGenerate::deleteData(QString table, QString condition) +{ + QString content = QString("delete %1 ").arg(table); + content += QString("where %1").arg(condition); + content += QString(";"); + return content; +} + +bool SqlGenerate::checkCheckParameterSql(const QString& str) +{ + QStringList keys; + keys << "and"; + keys << "or"; + keys << "*"; + keys << "="; + keys << " "; + keys << "%0a"; + keys << "%0d"; + keys << "%"; + keys << "/"; + keys << "union"; + keys << "|"; + keys << "&"; + keys << "^"; + keys << "#"; + keys << "/*"; + keys << "*/"; + keys << "delete"; + keys << "insert"; + keys << "select"; + keys << "update"; + keys << "drop"; + for (int i = 0; i < keys.size(); i++) + { + if (str.contains(keys[i])) // != string::npos) + { + return false; + } + } + return true; +} + diff --git a/xyylMCWEACSystem/SqlGenerate.h b/xyylMCWEACSystem/SqlGenerate.h new file mode 100644 index 0000000..0144bb6 --- /dev/null +++ b/xyylMCWEACSystem/SqlGenerate.h @@ -0,0 +1,33 @@ +#ifndef _SqlGenerate_H__ +#define _SqlGenerate_H__ +#include +#include +#include + +/* + \author: zym + \brief : 数据库组织校验器 + \version 1.0 + \note +*/ + + class SqlGenerate + { + public: + SqlGenerate(); + virtual ~SqlGenerate(); + QString createTable(QString table, QMap map); + QString insertData(QString table, QVariantMap map); + QString selectWhere(QString table, QStringList Name, QString condition = ""); + QString selectUnion(QStringList table, QStringList Name, QString condition = ""); + QString createIndex(QString table, QString name); + QString updateData(QString table, QVariantMap map, QString condition); + QString deleteData(QString table, QString sWhere); + private: + bool checkCheckParameterSql(const QString& str); + protected: + + private: + }; + +#endif // SqlGenerate_h__ diff --git a/xyylMCWEACSystem/datamanager.cpp b/xyylMCWEACSystem/datamanager.cpp new file mode 100644 index 0000000..40ce24d --- /dev/null +++ b/xyylMCWEACSystem/datamanager.cpp @@ -0,0 +1,24 @@ +#include "datamanager.h" +DataManager::DataManager(QObject * parent ) +{ + +}; +DataManager::~DataManager() +{ + +} + DataManager& DataManager::instance() +{ + static DataManager dataManager; + return dataManager; + +} + +void DataManager::init() +{ + +} +void DataManager::initTable() +{ + +} diff --git a/xyylMCWEACSystem/datamanager.h b/xyylMCWEACSystem/datamanager.h new file mode 100644 index 0000000..410c7bb --- /dev/null +++ b/xyylMCWEACSystem/datamanager.h @@ -0,0 +1,22 @@ +#ifndef DATAMANAGER_H +#define DATAMANAGER_H + +#include +#include "SqlCore.h" +#include "SqlGenerate.h" +class DataManager:public QObject +{ + Q_OBJECT +private: + DataManager(QObject * parent =NULL); + ~DataManager(); +public: + static DataManager& instance(); + void init(); + void initTable(); +private: + SqlCore m_sqlcore; + +}; + +#endif // DATAMANAGER_H diff --git a/xyylMCWEACSystem/xyylMCWEACSystem.pro b/xyylMCWEACSystem/xyylMCWEACSystem.pro index 343e781..18ef17b 100644 --- a/xyylMCWEACSystem/xyylMCWEACSystem.pro +++ b/xyylMCWEACSystem/xyylMCWEACSystem.pro @@ -27,8 +27,10 @@ CONFIG += c++11 SOURCES += \ SqlCore.cpp \ SqlExecute.cpp \ + SqlGenerate.cpp \ btngroupwidget.cpp \ curchatwidget.cpp \ + datamanager.cpp \ dataprocesswidget.cpp \ devconwidget.cpp \ eggwidget.cpp \ @@ -50,8 +52,10 @@ SOURCES += \ HEADERS += \ SqlCore.h \ SqlExecute.h \ + SqlGenerate.h \ btngroupwidget.h \ curchatwidget.h \ + datamanager.h \ dataprocesswidget.h \ devconwidget.h \ eggwidget.h \