| QxOrm 1.3.2 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 #ifdef _QX_CPP_11_SMART_PTR
    00062 #ifndef BOOST_NO_CXX11_SMART_PTR
    00063 #include <memory>
    00064 #endif // BOOST_NO_CXX11_SMART_PTR
    00065 #endif // _QX_CPP_11_SMART_PTR
    00066
    00067 #ifdef _QX_CPP_11_TUPLE
    00068 #ifndef BOOST_NO_CXX11_HDR_TUPLE
    00069 #include <tuple>
    00070 #endif // BOOST_NO_CXX11_HDR_TUPLE
    00071 #endif // _QX_CPP_11_TUPLE
    00072
    00073 #include <QxTraits/is_qx_registered.h>
    00074 #include <QxTraits/get_primary_key.h>
    00075 #include <QxTraits/remove_attr.h>
    00076 #include <QxTraits/get_class_name_primitive.h>
    00077
    00078 #include <QxDao/QxDaoPointer.h>
    00079 #include <QxDao/QxDateNeutral.h>
    00080 #include <QxDao/QxTimeNeutral.h>
    00081 #include <QxDao/QxDateTimeNeutral.h>
    00082
    00083 #include <QxCommon/QxBool.h>
    00084
    00085 namespace qx {
    00086 namespace trait {
    00087 namespace detail {
    00088
    00089 template <typename T>
    00090 struct get_sql_type_helper
    00091 {
    00092
    00093 private:
    00094
    00095    typedef typename qx::trait::remove_attr<T>::type type_1;
    00096    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;
    00097    typedef typename boost::mpl::if_c< boost::is_enum<type_2>::value, long, type_2 >::type type_3;
    00098
    00099 public:
    00100
    00101    typedef typename qx::trait::detail::get_sql_type_helper<T>::type_3 type;
    00102
    00103 };
    00104
    00105 template <typename T>
    00106 struct get_sql_type
    00107 { static inline const char * get() { return ""; } };
    00108
    00109 /* Implemented into './src/QxRegister/QxClassX.cpp' file */
    00110 QX_DLL_EXPORT const char * get_sql_type_by_class_name(const char * sClassName, const char * sDefaultValue);
    00111
    00112 } // namespace detail
    00113
    00118 template <typename T>
    00119 struct get_sql_type
    00120 {
    00121    typedef typename qx::trait::detail::get_sql_type_helper<T>::type type_sql;
    00122    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()); }
    00123 };
    00124
    00125 template <typename T>
    00126 struct get_sql_type< boost::optional<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< boost::scoped_ptr<T> >
    00131 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00132
    00133 template <typename T>
    00134 struct get_sql_type< boost::shared_ptr<T> >
    00135 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00136
    00137 template <typename T>
    00138 struct get_sql_type< boost::intrusive_ptr<T> >
    00139 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00140
    00141 template <typename T>
    00142 struct get_sql_type< QSharedPointer<T> >
    00143 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00144
    00145 #if (QT_VERSION >= 0x040600)
    00146 template <typename T>
    00147 struct get_sql_type< QScopedPointer<T> >
    00148 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00149 #endif // (QT_VERSION >= 0x040600)
    00150
    00151 #ifdef _QX_CPP_11_SMART_PTR
    00152 #ifndef BOOST_NO_CXX11_SMART_PTR
    00153
    00154 template <typename T>
    00155 struct get_sql_type< std::unique_ptr<T> >
    00156 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00157
    00158 template <typename T>
    00159 struct get_sql_type< std::shared_ptr<T> >
    00160 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00161
    00162 #endif // BOOST_NO_CXX11_SMART_PTR
    00163 #endif // _QX_CPP_11_SMART_PTR
    00164
    00165 template <typename T>
    00166 struct get_sql_type< qx::dao::ptr<T> >
    00167 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
    00168
    00169 template <typename T1, typename T2>
    00170 struct get_sql_type< std::pair<T1, T2> >
    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())); return s.c_str(); } };
    00172
    00173 template <typename T1, typename T2>
    00174 struct get_sql_type< QPair<T1, T2> >
    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())); return s.c_str(); } };
    00176
    00177 template <typename T1, typename T2>
    00178 struct get_sql_type< boost::tuple<T1, T2> >
    00179 { 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(); } };
    00180
    00181 template <typename T1, typename T2, typename T3>
    00182 struct get_sql_type< boost::tuple<T1, T2, T3> >
    00183 { 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(); } };
    00184
    00185 template <typename T1, typename T2, typename T3, typename T4>
    00186 struct get_sql_type< boost::tuple<T1, T2, T3, T4> >
    00187 { 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(); } };
    00188
    00189 template <typename T1, typename T2, typename T3, typename T4, typename T5>
    00190 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5> >
    00191 { 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(); } };
    00192
    00193 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
    00194 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6> >
    00195 { 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(); } };
    00196
    00197 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
    00198 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7> >
    00199 { 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(); } };
    00200
    00201 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
    00202 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
    00203 { 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(); } };
    00204
    00205 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
    00206 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
    00207 { 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(); } };
    00208
    00209 #ifdef _QX_CPP_11_TUPLE
    00210 #ifndef BOOST_NO_CXX11_HDR_TUPLE
    00211
    00212 template <typename T1, typename T2>
    00213 struct get_sql_type< std::tuple<T1, T2> >
    00214 { 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(); } };
    00215
    00216 template <typename T1, typename T2, typename T3>
    00217 struct get_sql_type< std::tuple<T1, T2, T3> >
    00218 { 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(); } };
    00219
    00220 template <typename T1, typename T2, typename T3, typename T4>
    00221 struct get_sql_type< std::tuple<T1, T2, T3, T4> >
    00222 { 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(); } };
    00223
    00224 template <typename T1, typename T2, typename T3, typename T4, typename T5>
    00225 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5> >
    00226 { 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(); } };
    00227
    00228 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
    00229 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6> >
    00230 { 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(); } };
    00231
    00232 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
    00233 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7> >
    00234 { 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(); } };
    00235
    00236 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
    00237 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
    00238 { 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(); } };
    00239
    00240 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
    00241 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
    00242 { 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(); } };
    00243
    00244 #endif // BOOST_NO_CXX11_HDR_TUPLE
    00245 #endif // _QX_CPP_11_TUPLE
    00246
    00247 } // namespace trait
    00248 } // namespace qx
    00249
    00250 #define QX_REGISTER_TRAIT_GET_SQL_TYPE(className, sqlType) \
    00251 namespace qx { namespace trait { namespace detail { \
    00252 template <> \
    00253 struct get_sql_type< className > \
    00254 { static inline const char * get() { return get_sql_type_by_class_name(#className, sqlType); } }; }}}
    00255
    00256 QX_REGISTER_TRAIT_GET_SQL_TYPE(bool, "SMALLINT")
    00257 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx_bool, "SMALLINT")
    00258 QX_REGISTER_TRAIT_GET_SQL_TYPE(char, "SMALLINT")
    00259 QX_REGISTER_TRAIT_GET_SQL_TYPE(short, "SMALLINT")
    00260 QX_REGISTER_TRAIT_GET_SQL_TYPE(int, "INTEGER")
    00261 QX_REGISTER_TRAIT_GET_SQL_TYPE(long, "INTEGER")
    00262 QX_REGISTER_TRAIT_GET_SQL_TYPE(long long, "INTEGER")
    00263 QX_REGISTER_TRAIT_GET_SQL_TYPE(float, "FLOAT")
    00264 QX_REGISTER_TRAIT_GET_SQL_TYPE(double, "FLOAT")
    00265 QX_REGISTER_TRAIT_GET_SQL_TYPE(long double, "FLOAT")
    00266 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned short, "SMALLINT")
    00267 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned int, "INTEGER")
    00268 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long, "INTEGER")
    00269 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long long, "INTEGER")
    00270 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::string, "TEXT")
    00271 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::wstring, "TEXT")
    00272 QX_REGISTER_TRAIT_GET_SQL_TYPE(QString, "TEXT")
    00273 QX_REGISTER_TRAIT_GET_SQL_TYPE(QVariant, "TEXT")
    00274 QX_REGISTER_TRAIT_GET_SQL_TYPE(QUuid, "TEXT")
    00275 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDate, "DATE")
    00276 QX_REGISTER_TRAIT_GET_SQL_TYPE(QTime, "TIME")
    00277 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDateTime, "TIMESTAMP")
    00278 QX_REGISTER_TRAIT_GET_SQL_TYPE(QByteArray, "BLOB")
    00279 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateNeutral, "TEXT")
    00280 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxTimeNeutral, "TEXT")
    00281 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateTimeNeutral, "TEXT")
    00282
    00283 #endif // _QX_GET_SQL_TYPE_H_