| QxOrm 1.3.1 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 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
    00005 **
    00006 ** This file is part of the QxOrm library
    00007 **
    00008 ** This software is provided 'as-is', without any express or implied
    00009 ** warranty. In no event will the authors be held liable for any
    00010 ** damages arising from the use of this software
    00011 **
    00012 ** Commercial Usage
    00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
    00014 ** accordance with the commercial license agreement provided with the
    00015 ** Software or, alternatively, in accordance with the terms contained in
    00016 ** a written agreement between you and Lionel Marty
    00017 **
    00018 ** GNU General Public License Usage
    00019 ** Alternatively, this file may be used under the terms of the GNU
    00020 ** General Public License version 3.0 as published by the Free Software
    00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
    00022 ** packaging of this file. Please review the following information to
    00023 ** ensure the GNU General Public License version 3.0 requirements will be
    00024 ** met : http://www.gnu.org/copyleft/gpl.html
    00025 **
    00026 ** If you are unsure which license is appropriate for your use, or
    00027 ** if you have questions regarding the use of this file, please contact :
    00028 ** contact@qxorm.com
    00029 **
    00030 ****************************************************************************/
    00031
    00032 #ifndef _QX_GET_SQL_TYPE_H_
    00033 #define _QX_GET_SQL_TYPE_H_
    00034
    00035 #ifdef _MSC_VER
    00036 #pragma once
    00037 #endif
    00038
    00046 #include <boost/mpl/if.hpp>
    00047 #include <boost/mpl/logical.hpp>
    00048 #include <boost/scoped_ptr.hpp>
    00049 #include <boost/shared_ptr.hpp>
    00050 #include <boost/intrusive_ptr.hpp>
    00051 #include <boost/optional.hpp>
    00052 #include <boost/type_traits/is_enum.hpp>
    00053 #include <boost/type_traits/is_same.hpp>
    00054
    00055 #include <QtCore/qsharedpointer.h>
    00056
    00057 #if (QT_VERSION >= 0x040600)
    00058 #include <QtCore/qscopedpointer.h>
    00059 #endif // (QT_VERSION >= 0x040600)
    00060
    00061 #include <QxTraits/is_qx_registered.h>
    00062 #include <QxTraits/get_primary_key.h>
    00063 #include <QxTraits/remove_attr.h>
    00064 #include <QxTraits/get_class_name_primitive.h>
    00065
    00066 #include <QxDao/QxDaoPointer.h>
    00067 #include <QxDao/QxDateNeutral.h>
    00068 #include <QxDao/QxTimeNeutral.h>
    00069 #include <QxDao/QxDateTimeNeutral.h>
    00070
    00071 #include <QxCommon/QxBool.h>
    00072
    00073 namespace qx {
    00074 namespace trait {
    00075 namespace detail {
    00076
    00077 template <typename T>
    00078 struct get_sql_type_helper
    00079 {
    00080
    00081 private:
    00082
    00083    typedef typename qx::trait::remove_attr<T>::type type_1;
    00084    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;
    00085    typedef typename boost::mpl::if_c< boost::is_enum<type_2>::value, long, type_2 >::type type_3;
    00086
    00087 public:
    00088
    00089    typedef typename qx::trait::detail::get_sql_type_helper<T>::type_3 type;
    00090
    00091 };
    00092
    00093 template <typename T>
    00094 struct get_sql_type
    00095 { static inline const char * get() { return ""; } };
    00096
    00097 /* Implemented into './src/QxRegister/QxClassX.cpp' file */
    00098 QX_DLL_EXPORT const char * get_sql_type_by_class_name(const char * sClassName, const char * sDefaultValue);
    00099
    00100 } // namespace detail
    00101
    00106 template <typename T>
    00107 struct get_sql_type
    00108 {
    00109    typedef typename qx::trait::detail::get_sql_type_helper<T>::type type_sql;
    00110    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()); }
    00111 };
    00112
    00113 template <typename T>
    00114 struct get_sql_type< boost::optional<T> >
    00115 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00116
    00117 template <typename T>
    00118 struct get_sql_type< boost::scoped_ptr<T> >
    00119 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00120
    00121 template <typename T>
    00122 struct get_sql_type< boost::shared_ptr<T> >
    00123 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00124
    00125 template <typename T>
    00126 struct get_sql_type< boost::intrusive_ptr<T> >
    00127 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00128
    00129 template <typename T>
    00130 struct get_sql_type< QSharedPointer<T> >
    00131 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00132
    00133 #if (QT_VERSION >= 0x040600)
    00134 template <typename T>
    00135 struct get_sql_type< QScopedPointer<T> >
    00136 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00137 #endif // (QT_VERSION >= 0x040600)
    00138
    00139 template <typename T>
    00140 struct get_sql_type< qx::dao::ptr<T> >
    00141 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00142
    00143 template <typename T1, typename T2>
    00144 struct get_sql_type< std::pair<T1, T2> >
    00145 { 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(); } };
    00146
    00147 template <typename T1, typename T2>
    00148 struct get_sql_type< QPair<T1, T2> >
    00149 { 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(); } };
    00150
    00151 template <typename T1, typename T2>
    00152 struct get_sql_type< boost::tuple<T1, T2> >
    00153 { 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(); } };
    00154
    00155 template <typename T1, typename T2, typename T3>
    00156 struct get_sql_type< boost::tuple<T1, T2, T3> >
    00157 { 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(); } };
    00158
    00159 template <typename T1, typename T2, typename T3, typename T4>
    00160 struct get_sql_type< boost::tuple<T1, T2, T3, T4> >
    00161 { 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(); } };
    00162
    00163 template <typename T1, typename T2, typename T3, typename T4, typename T5>
    00164 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5> >
    00165 { 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(); } };
    00166
    00167 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
    00168 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6> >
    00169 { 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(); } };
    00170
    00171 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
    00172 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7> >
    00173 { 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(); } };
    00174
    00175 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
    00176 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
    00177 { 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(); } };
    00178
    00179 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
    00180 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
    00181 { 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(); } };
    00182
    00183 } // namespace trait
    00184 } // namespace qx
    00185
    00186 #define QX_REGISTER_TRAIT_GET_SQL_TYPE(className, sqlType) \
    00187 namespace qx { namespace trait { namespace detail { \
    00188 template <> \
    00189 struct get_sql_type< className > \
    00190 { static inline const char * get() { return get_sql_type_by_class_name(#className, sqlType); } }; }}}
    00191
    00192 QX_REGISTER_TRAIT_GET_SQL_TYPE(bool, "SMALLINT")
    00193 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx_bool, "SMALLINT")
    00194 QX_REGISTER_TRAIT_GET_SQL_TYPE(short, "SMALLINT")
    00195 QX_REGISTER_TRAIT_GET_SQL_TYPE(int, "INTEGER")
    00196 QX_REGISTER_TRAIT_GET_SQL_TYPE(long, "INTEGER")
    00197 QX_REGISTER_TRAIT_GET_SQL_TYPE(long long, "INTEGER")
    00198 QX_REGISTER_TRAIT_GET_SQL_TYPE(float, "FLOAT")
    00199 QX_REGISTER_TRAIT_GET_SQL_TYPE(double, "FLOAT")
    00200 QX_REGISTER_TRAIT_GET_SQL_TYPE(long double, "FLOAT")
    00201 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned short, "SMALLINT")
    00202 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned int, "INTEGER")
    00203 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long, "INTEGER")
    00204 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long long, "INTEGER")
    00205 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::string, "TEXT")
    00206 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::wstring, "TEXT")
    00207 QX_REGISTER_TRAIT_GET_SQL_TYPE(QString, "TEXT")
    00208 QX_REGISTER_TRAIT_GET_SQL_TYPE(QVariant, "TEXT")
    00209 QX_REGISTER_TRAIT_GET_SQL_TYPE(QUuid, "TEXT")
    00210 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDate, "DATE")
    00211 QX_REGISTER_TRAIT_GET_SQL_TYPE(QTime, "TIME")
    00212 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDateTime, "TIMESTAMP")
    00213 QX_REGISTER_TRAIT_GET_SQL_TYPE(QByteArray, "BLOB")
    00214 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateNeutral, "TEXT")
    00215 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxTimeNeutral, "TEXT")
    00216 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateTimeNeutral, "TEXT")
    00217
    00218 #endif // _QX_GET_SQL_TYPE_H_