| QxOrm 1.2.4 C++ Object Relational Mapping library

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

- File List
- File Members

get_sql_type.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_GET_SQL_TYPE_H_
    00027 #define _QX_GET_SQL_TYPE_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <boost/mpl/if.hpp>
    00041 #include <boost/mpl/logical.hpp>
    00042 #include <boost/scoped_ptr.hpp>
    00043 #include <boost/shared_ptr.hpp>
    00044 #include <boost/intrusive_ptr.hpp>
    00045 #include <boost/optional.hpp>
    00046 #include <boost/type_traits/is_enum.hpp>
    00047 #include <boost/type_traits/is_same.hpp>
    00048
    00049 #include <QtCore/qsharedpointer.h>
    00050
    00051 #if (QT_VERSION >= 0x040600)
    00052 #include <QtCore/qscopedpointer.h>
    00053 #endif // (QT_VERSION >= 0x040600)
    00054
    00055 #include <QxTraits/is_qx_registered.h>
    00056 #include <QxTraits/get_primary_key.h>
    00057 #include <QxTraits/remove_attr.h>
    00058 #include <QxTraits/get_class_name_primitive.h>
    00059
    00060 #include <QxDao/QxDaoPointer.h>
    00061 #include <QxDao/QxDateNeutral.h>
    00062 #include <QxDao/QxTimeNeutral.h>
    00063 #include <QxDao/QxDateTimeNeutral.h>
    00064
    00065 #include <QxCommon/QxBool.h>
    00066
    00067 namespace qx {
    00068 namespace trait {
    00069 namespace detail {
    00070
    00071 template <typename T>
    00072 struct get_sql_type_helper
    00073 {
    00074
    00075 private:
    00076
    00077    typedef typename qx::trait::remove_attr<T>::type type_1;
    00078    typedef typename boost::mpl::if_c< qx::trait::is_qx_registered<type_1>::value, typename qx::trait::get_primary_key<type_1>::type, type_1 >::type type_2;
    00079    typedef typename boost::mpl::if_c< boost::is_enum<type_2>::value, long, type_2 >::type type_3;
    00080
    00081 public:
    00082
    00083    typedef typename qx::trait::detail::get_sql_type_helper<T>::type_3 type;
    00084
    00085 };
    00086
    00087 template <typename T>
    00088 struct get_sql_type
    00089 { static inline const char * get() { return ""; } };
    00090
    00091 /* Implemented into './src/QxRegister/QxClassX.cpp' file */
    00092 QX_DLL_EXPORT const char * get_sql_type_by_class_name(const char * sClassName, const char * sDefaultValue);
    00093
    00094 } // namespace detail
    00095
    00100 template <typename T>
    00101 struct get_sql_type
    00102 {
    00103    typedef typename qx::trait::detail::get_sql_type_helper<T>::type type_sql;
    00104    static inline const char * get() { return (boost::is_same<T, type_sql>::value ? qx::trait::detail::get_sql_type<type_sql>::get() : qx::trait::get_sql_type<type_sql>::get()); }
    00105 };
    00106
    00107 template <typename T>
    00108 struct get_sql_type< boost::optional<T> >
    00109 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00110
    00111 template <typename T>
    00112 struct get_sql_type< boost::scoped_ptr<T> >
    00113 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00114
    00115 template <typename T>
    00116 struct get_sql_type< boost::shared_ptr<T> >
    00117 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00118
    00119 template <typename T>
    00120 struct get_sql_type< boost::intrusive_ptr<T> >
    00121 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00122
    00123 template <typename T>
    00124 struct get_sql_type< QSharedPointer<T> >
    00125 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00126
    00127 #if (QT_VERSION >= 0x040600)
    00128 template <typename T>
    00129 struct get_sql_type< QScopedPointer<T> >
    00130 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00131 #endif // (QT_VERSION >= 0x040600)
    00132
    00133 template <typename T>
    00134 struct get_sql_type< qx::dao::ptr<T> >
    00135 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00136
    00137 template <typename T1, typename T2>
    00138 struct get_sql_type< std::pair<T1, T2> >
    00139 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get())); return s.c_str(); } };
    00140
    00141 template <typename T1, typename T2>
    00142 struct get_sql_type< QPair<T1, T2> >
    00143 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get())); return s.c_str(); } };
    00144
    00145 template <typename T1, typename T2>
    00146 struct get_sql_type< boost::tuple<T1, T2> >
    00147 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get())); return s.c_str(); } };
    00148
    00149 template <typename T1, typename T2, typename T3>
    00150 struct get_sql_type< boost::tuple<T1, T2, T3> >
    00151 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get()) + "|" + std::string(qx::trait::get_sql_type<T3>::get())); return s.c_str(); } };
    00152
    00153 template <typename T1, typename T2, typename T3, typename T4>
    00154 struct get_sql_type< boost::tuple<T1, T2, T3, T4> >
    00155 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get()) + "|" + std::string(qx::trait::get_sql_type<T3>::get()) + "|" + std::string(qx::trait::get_sql_type<T4>::get())); return s.c_str(); } };
    00156
    00157 template <typename T1, typename T2, typename T3, typename T4, typename T5>
    00158 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5> >
    00159 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get()) + "|" + std::string(qx::trait::get_sql_type<T3>::get()) + "|" + std::string(qx::trait::get_sql_type<T4>::get()) + "|" + std::string(qx::trait::get_sql_type<T5>::get())); return s.c_str(); } };
    00160
    00161 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
    00162 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6> >
    00163 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get()) + "|" + std::string(qx::trait::get_sql_type<T3>::get()) + "|" + std::string(qx::trait::get_sql_type<T4>::get()) + "|" + std::string(qx::trait::get_sql_type<T5>::get()) + "|" + std::string(qx::trait::get_sql_type<T6>::get())); return s.c_str(); } };
    00164
    00165 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
    00166 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7> >
    00167 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get()) + "|" + std::string(qx::trait::get_sql_type<T3>::get()) + "|" + std::string(qx::trait::get_sql_type<T4>::get()) + "|" + std::string(qx::trait::get_sql_type<T5>::get()) + "|" + std::string(qx::trait::get_sql_type<T6>::get()) + "|" + std::string(qx::trait::get_sql_type<T7>::get())); return s.c_str(); } };
    00168
    00169 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
    00170 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
    00171 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get()) + "|" + std::string(qx::trait::get_sql_type<T3>::get()) + "|" + std::string(qx::trait::get_sql_type<T4>::get()) + "|" + std::string(qx::trait::get_sql_type<T5>::get()) + "|" + std::string(qx::trait::get_sql_type<T6>::get()) + "|" + std::string(qx::trait::get_sql_type<T7>::get()) + "|" + std::string(qx::trait::get_sql_type<T8>::get())); return s.c_str(); } };
    00172
    00173 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
    00174 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
    00175 { static inline const char * get() { static std::string s; s = (std::string(qx::trait::get_sql_type<T1>::get()) + "|" + std::string(qx::trait::get_sql_type<T2>::get()) + "|" + std::string(qx::trait::get_sql_type<T3>::get()) + "|" + std::string(qx::trait::get_sql_type<T4>::get()) + "|" + std::string(qx::trait::get_sql_type<T5>::get()) + "|" + std::string(qx::trait::get_sql_type<T6>::get()) + "|" + std::string(qx::trait::get_sql_type<T7>::get()) + "|" + std::string(qx::trait::get_sql_type<T8>::get()) + "|" + std::string(qx::trait::get_sql_type<T9>::get())); return s.c_str(); } };
    00176
    00177 } // namespace trait
    00178 } // namespace qx
    00179
    00180 #define QX_REGISTER_TRAIT_GET_SQL_TYPE(className, sqlType) \
    00181 namespace qx { namespace trait { namespace detail { \
    00182 template <> \
    00183 struct get_sql_type< className > \
    00184 { static inline const char * get() { return get_sql_type_by_class_name(#className, sqlType); } }; }}}
    00185
    00186 QX_REGISTER_TRAIT_GET_SQL_TYPE(bool, "SMALLINT")
    00187 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx_bool, "SMALLINT")
    00188 QX_REGISTER_TRAIT_GET_SQL_TYPE(short, "SMALLINT")
    00189 QX_REGISTER_TRAIT_GET_SQL_TYPE(int, "INTEGER")
    00190 QX_REGISTER_TRAIT_GET_SQL_TYPE(long, "INTEGER")
    00191 QX_REGISTER_TRAIT_GET_SQL_TYPE(long long, "INTEGER")
    00192 QX_REGISTER_TRAIT_GET_SQL_TYPE(float, "FLOAT")
    00193 QX_REGISTER_TRAIT_GET_SQL_TYPE(double, "FLOAT")
    00194 QX_REGISTER_TRAIT_GET_SQL_TYPE(long double, "FLOAT")
    00195 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned short, "SMALLINT")
    00196 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned int, "INTEGER")
    00197 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long, "INTEGER")
    00198 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long long, "INTEGER")
    00199 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::string, "TEXT")
    00200 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::wstring, "TEXT")
    00201 QX_REGISTER_TRAIT_GET_SQL_TYPE(QString, "TEXT")
    00202 QX_REGISTER_TRAIT_GET_SQL_TYPE(QVariant, "TEXT")
    00203 QX_REGISTER_TRAIT_GET_SQL_TYPE(QUuid, "TEXT")
    00204 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDate, "DATE")
    00205 QX_REGISTER_TRAIT_GET_SQL_TYPE(QTime, "TIME")
    00206 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDateTime, "TIMESTAMP")
    00207 QX_REGISTER_TRAIT_GET_SQL_TYPE(QByteArray, "BLOB")
    00208 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateNeutral, "TEXT")
    00209 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxTimeNeutral, "TEXT")
    00210 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateTimeNeutral, "TEXT")
    00211
    00212 #endif // _QX_GET_SQL_TYPE_H_