浏览代码

修改bug

lichanglin 3 年之前
父节点
当前提交
96b2ca6053
共有 2 个文件被更改,包括 67 次插入3 次删除
  1. 5 3
      AutoGenetateModelServiceUI/TableHelper.cpp
  2. 62 0
      DataManage/utils/Singleton.h

+ 5 - 3
AutoGenetateModelServiceUI/TableHelper.cpp

@@ -12,7 +12,10 @@ QString TableHelper::createTable(const QString &tablename, const QList<QPair<QSt
     QStringList fields;
     QStringList fields;
     foreach(auto &item, fieldAndTypes)
     foreach(auto &item, fieldAndTypes)
     {
     {
-        fields << item.first +" " +  item.second;
+        if(item.second == "DATETIME")
+            fields << item.first +" DATE" ;
+        else
+            fields << item.first +" " +  item.second;
     }
     }
     return QString("create table %1 ( \n %2 \n ); \n").arg(tablename).arg(fields.join(", \n"));
     return QString("create table %1 ( \n %2 \n ); \n").arg(tablename).arg(fields.join(", \n"));
 }
 }
@@ -34,8 +37,7 @@ QString TableHelper::createPrimaryAlter(const QString &tablename)
 
 
 QString TableHelper::createSeq(const QString &tablename)
 QString TableHelper::createSeq(const QString &tablename)
 {
 {
-    return QString("drop sequence SEQ_%1; \n\
-                    CREATE SEQUENCE SEQ_%1 \n\
+    return QString("CREATE SEQUENCE SEQ_%1 \n\
                     START WITH 1 \n\
                     START WITH 1 \n\
                     MAXVALUE 99999999999999 \n\
                     MAXVALUE 99999999999999 \n\
                     MINVALUE 1 \n\
                     MINVALUE 1 \n\

+ 62 - 0
DataManage/utils/Singleton.h

@@ -0,0 +1,62 @@
+#ifndef SINGLETON_H
+#define SINGLETON_H
+
+#include <QString>
+#include <QMutex>
+#include <QCoreApplication>
+
+/**
+ * 如果T的构造函数为私有,需要在T的类声明内部将 Singleton<T> 设为友元类
+ */
+template <class T>
+class Singleton
+{
+private:
+
+   static T *     m_pSingleton;        //!< Singleton -> only 1 instance allowed
+   static QMutex  m_oMutexSingleton;   //!< Mutex -> 'Singleton' is thread-safe
+
+protected:
+
+   Singleton() {  }
+   virtual ~Singleton() { }
+
+public:
+
+   static T * getSingleton();
+   static void deleteSingleton();
+
+protected:
+
+   static bool isSingletonNull() { return (m_pSingleton == NULL); }
+
+//   void deleteInstance() { Singleton<T>::deleteSingleton(); }
+
+};
+
+template <class T> T * Singleton<T>::m_pSingleton = NULL;
+template <class T> QMutex Singleton<T>::m_oMutexSingleton;
+
+template <class T>
+T * Singleton<T>::getSingleton()
+{
+   if (m_pSingleton)
+      return m_pSingleton;
+
+   QMutexLocker locker(QCoreApplication::instance() ? (& m_oMutexSingleton) : NULL);
+   if (! m_pSingleton) { m_pSingleton = new T(); }
+
+   return m_pSingleton;
+}
+
+template <class T>
+void Singleton<T>::deleteSingleton()
+{
+   QMutexLocker locker(QCoreApplication::instance() ? (& m_oMutexSingleton) : NULL);
+   if (! m_pSingleton) { return; }
+
+   delete m_pSingleton;
+   m_pSingleton = NULL;
+}
+
+#endif // SINGLETON_H