| QxOrm 1.2.1 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxSoftDelete.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://www.qxorm.com/
    00004 ** http://sourceforge.net/projects/qxorm/
    00005 ** Original file by Lionel Marty
    00006 **
    00007 ** This file is part of the QxOrm library
    00008 **
    00009 ** This software is provided 'as-is', without any express or implied
    00010 ** warranty. In no event will the authors be held liable for any
    00011 ** damages arising from the use of this software.
    00012 **
    00013 ** GNU Lesser General Public License Usage
    00014 ** This file must be used under the terms of the GNU Lesser
    00015 ** General Public License version 2.1 as published by the Free Software
    00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
    00017 ** packaging of this file.  Please review the following information to
    00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00020 **
    00021 ** If you have questions regarding the use of this file, please contact :
    00022 ** contact@qxorm.com
    00023 **
    00024 ****************************************************************************/
    00025
    00026 #ifndef _QX_SOFT_DELETE_H_
    00027 #define _QX_SOFT_DELETE_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #define QX_DAO_SOFT_DELETE_QDATETIME_FORMAT "yyyyMMddhhmmsszzz"
    00041
    00042 namespace qx {
    00043
    00090 class QxSoftDelete
    00091 {
    00092
    00093 public:
    00094
    00095    enum mode { mode_flag, mode_date_time };
    00096
    00097 private:
    00098
    00099    QString m_sTable;
    00100    QString m_sColumn;
    00101    QString m_sSqlQueryToFetch;
    00102    QString m_sSqlQueryToUpdate;
    00103    QString m_sSqlQueryToCreateTable;
    00104    mode m_eMode;
    00105
    00106 public:
    00107
    00108    QxSoftDelete() : m_eMode(mode_date_time) { ; }
    00109    QxSoftDelete(const QString & sColumn) : m_sColumn(sColumn), m_eMode(mode_date_time) { ; }
    00110    QxSoftDelete(const QString & sColumn, mode eMode) : m_sColumn(sColumn), m_eMode(eMode) { ; }
    00111    ~QxSoftDelete() { ; }
    00112
    00113    QString getTableName() const              { return m_sTable; }
    00114    QString getColumnName() const             { return m_sColumn; }
    00115    QString getSqlQueryToFetch() const        { return m_sSqlQueryToFetch; }
    00116    QString getSqlQueryToUpdate() const       { return m_sSqlQueryToUpdate; }
    00117    QString getSqlQueryToCreateTable() const  { return m_sSqlQueryToCreateTable; }
    00118    mode getMode() const                      { return m_eMode; }
    00119
    00120    void setTableName(const QString & sTable)          { m_sTable = sTable; }
    00121    void setColumnName(const QString & sColumn)        { m_sColumn = sColumn; }
    00122    void setSqlQueryToFetch(const QString & s)         { m_sSqlQueryToFetch = s; }
    00123    void setSqlQueryToUpdate(const QString & s)        { m_sSqlQueryToUpdate = s; }
    00124    void setSqlQueryToCreateTable(const QString & s)   { m_sSqlQueryToCreateTable = s; }
    00125    void setMode(mode eMode)                           { m_eMode = eMode; }
    00126
    00127    bool isEmpty() const { return (m_sTable.isEmpty() || m_sColumn.isEmpty()); }
    00128
    00129    QString buildSqlTablePointName(const QString & sTable = QString()) const
    00130    {
    00131       if (this->isEmpty()) { return ""; }
    00132       return ((sTable.isEmpty() ? m_sTable : sTable) + "." + m_sColumn);
    00133    }
    00134
    00135    QString buildSqlQueryToFetch(const QString & sTable = QString()) const
    00136    {
    00137       QString sCurrTable = (sTable.isEmpty() ? m_sTable : sTable);
    00138       if (this->isEmpty()) { return ""; }
    00139       else if (! m_sSqlQueryToFetch.isEmpty()) { return m_sSqlQueryToFetch; }
    00140       else if (m_eMode == mode_flag) { return ("(" + sCurrTable + "." + m_sColumn + " IS NULL" + " OR " + sCurrTable + "." + m_sColumn + " = ''" + " OR " + sCurrTable + "." + m_sColumn + " = '0'" + ")"); }
    00141       else if (m_eMode == mode_date_time) { return ("(" + sCurrTable + "." + m_sColumn + " IS NULL" + " OR " + sCurrTable + "." + m_sColumn + " = ''" + ")"); }
    00142       qAssert(false); return "";
    00143    }
    00144
    00145    QString buildSqlQueryToUpdate() const
    00146    {
    00147       if (this->isEmpty()) { return ""; }
    00148       else if (! m_sSqlQueryToUpdate.isEmpty()) { return m_sSqlQueryToUpdate; }
    00149       else if (m_eMode == mode_flag) { return (m_sColumn + " = '1'"); }
    00150       else if (m_eMode == mode_date_time) { return (m_sColumn + " = '" + QDateTime::currentDateTime().toString(QX_DAO_SOFT_DELETE_QDATETIME_FORMAT) + "'"); }
    00151       qAssert(false); return "";
    00152    }
    00153
    00154    QString buildSqlQueryToCreateTable() const
    00155    {
    00156       if (this->isEmpty()) { return ""; }
    00157       else if (! m_sSqlQueryToCreateTable.isEmpty()) { return m_sSqlQueryToCreateTable; }
    00158       else if (m_eMode == mode_flag) { return (m_sColumn + " " + "TEXT"); }
    00159       else if (m_eMode == mode_date_time) { return (m_sColumn + " " + "TEXT"); }
    00160       qAssert(false); return "";
    00161    }
    00162
    00163 };
    00164
    00165 } // namespace qx
    00166
    00167 #endif // _QX_SOFT_DELETE_H_

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines