QxOrm  1.5.0
C++ Object Relational Mapping library
get_sql_type.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://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 <QtCore/qsharedpointer.h>
00047 
00048 #if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
00049 #include <QtCore/qscopedpointer.h>
00050 #endif // (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
00051 
00052 #include <QxTraits/is_qx_registered.h>
00053 #include <QxTraits/get_primary_key.h>
00054 #include <QxTraits/remove_attr.h>
00055 #include <QxTraits/get_class_name_primitive.h>
00056 
00057 #include <QxDao/QxDaoPointer.h>
00058 #include <QxDao/QxDateNeutral.h>
00059 #include <QxDao/QxTimeNeutral.h>
00060 #include <QxDao/QxDateTimeNeutral.h>
00061 
00062 #include <QxCommon/QxBool.h>
00063 
00064 namespace qx {
00065 namespace trait {
00066 namespace detail {
00067 
00068 template <typename T>
00069 struct get_sql_type_helper
00070 {
00071 
00072 private:
00073 
00074    typedef typename qx::trait::remove_attr<T>::type type_1;
00075    typedef typename std::conditional< qx::trait::is_qx_registered<type_1>::value, typename qx::trait::get_primary_key<type_1>::type, type_1 >::type type_2;
00076    typedef typename std::conditional< std::is_enum<type_2>::value, long, type_2 >::type type_3;
00077 
00078 public:
00079 
00080    typedef typename qx::trait::detail::get_sql_type_helper<T>::type_3 type;
00081 
00082 };
00083 
00084 template <typename T>
00085 struct get_sql_type
00086 { static inline const char * get() { return ""; } };
00087 
00088 /* Implemented into './src/QxRegister/QxClassX.cpp' file */
00089 QX_DLL_EXPORT const char * get_sql_type_by_class_name(const char * sClassName, const char * sDefaultValue);
00090 
00091 } // namespace detail
00092 
00097 template <typename T>
00098 struct get_sql_type
00099 {
00100    typedef typename qx::trait::detail::get_sql_type_helper<T>::type type_sql;
00101    static inline const char * get() { return (std::is_same<T, type_sql>::value ? qx::trait::detail::get_sql_type<type_sql>::get() : qx::trait::get_sql_type<type_sql>::get()); }
00102 };
00103 
00104 #ifdef _QX_ENABLE_BOOST
00105 
00106 template <typename T>
00107 struct get_sql_type< boost::optional<T> >
00108 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00109 
00110 template <typename T>
00111 struct get_sql_type< boost::scoped_ptr<T> >
00112 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00113 
00114 template <typename T>
00115 struct get_sql_type< boost::shared_ptr<T> >
00116 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00117 
00118 template <typename T>
00119 struct get_sql_type< boost::intrusive_ptr<T> >
00120 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00121 
00122 #endif // _QX_ENABLE_BOOST
00123 
00124 template <typename T>
00125 struct get_sql_type< QSharedPointer<T> >
00126 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00127 
00128 #if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
00129 template <typename T>
00130 struct get_sql_type< QScopedPointer<T> >
00131 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00132 #endif // (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
00133 
00134 template <typename T>
00135 struct get_sql_type< std::unique_ptr<T> >
00136 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00137 
00138 template <typename T>
00139 struct get_sql_type< std::shared_ptr<T> >
00140 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00141 
00142 template <typename T>
00143 struct get_sql_type< qx::dao::ptr<T> >
00144 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00145 
00146 template <typename T1, typename T2>
00147 struct get_sql_type< std::pair<T1, T2> >
00148 { 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(); } };
00149 
00150 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
00151 template <typename T1, typename T2>
00152 struct get_sql_type< QPair<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 #endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
00155 
00156 #ifdef _QX_ENABLE_BOOST
00157 
00158 template <typename T1, typename T2>
00159 struct get_sql_type< boost::tuple<T1, T2> >
00160 { 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(); } };
00161 
00162 template <typename T1, typename T2, typename T3>
00163 struct get_sql_type< boost::tuple<T1, T2, T3> >
00164 { 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(); } };
00165 
00166 template <typename T1, typename T2, typename T3, typename T4>
00167 struct get_sql_type< boost::tuple<T1, T2, T3, T4> >
00168 { 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(); } };
00169 
00170 template <typename T1, typename T2, typename T3, typename T4, typename T5>
00171 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5> >
00172 { 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(); } };
00173 
00174 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00175 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6> >
00176 { 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(); } };
00177 
00178 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00179 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7> >
00180 { 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(); } };
00181 
00182 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00183 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
00184 { 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(); } };
00185 
00186 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00187 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
00188 { 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(); } };
00189 
00190 #endif // _QX_ENABLE_BOOST
00191 
00192 template <typename T1, typename T2>
00193 struct get_sql_type< std::tuple<T1, T2> >
00194 { 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(); } };
00195 
00196 template <typename T1, typename T2, typename T3>
00197 struct get_sql_type< std::tuple<T1, T2, T3> >
00198 { 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(); } };
00199 
00200 template <typename T1, typename T2, typename T3, typename T4>
00201 struct get_sql_type< std::tuple<T1, T2, T3, T4> >
00202 { 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(); } };
00203 
00204 template <typename T1, typename T2, typename T3, typename T4, typename T5>
00205 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5> >
00206 { 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(); } };
00207 
00208 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00209 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6> >
00210 { 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(); } };
00211 
00212 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00213 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7> >
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()) + "|" + 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(); } };
00215 
00216 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00217 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
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()) + "|" + 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(); } };
00219 
00220 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00221 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
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()) + "|" + 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(); } };
00223 
00224 } // namespace trait
00225 } // namespace qx
00226 
00227 #define QX_REGISTER_TRAIT_GET_SQL_TYPE(className, sqlType) \
00228 namespace qx { namespace trait { namespace detail { \
00229 template <> \
00230 struct get_sql_type< className > \
00231 { static inline const char * get() { return get_sql_type_by_class_name(#className, sqlType); } }; }}}
00232 
00233 QX_REGISTER_TRAIT_GET_SQL_TYPE(bool, "SMALLINT")
00234 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx_bool, "TEXT")
00235 QX_REGISTER_TRAIT_GET_SQL_TYPE(char, "SMALLINT")
00236 QX_REGISTER_TRAIT_GET_SQL_TYPE(short, "SMALLINT")
00237 QX_REGISTER_TRAIT_GET_SQL_TYPE(int, "INTEGER")
00238 QX_REGISTER_TRAIT_GET_SQL_TYPE(long, "INTEGER")
00239 QX_REGISTER_TRAIT_GET_SQL_TYPE(long long, "INTEGER")
00240 QX_REGISTER_TRAIT_GET_SQL_TYPE(float, "FLOAT")
00241 QX_REGISTER_TRAIT_GET_SQL_TYPE(double, "FLOAT")
00242 QX_REGISTER_TRAIT_GET_SQL_TYPE(long double, "FLOAT")
00243 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned short, "SMALLINT")
00244 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned int, "INTEGER")
00245 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long, "INTEGER")
00246 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long long, "INTEGER")
00247 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::string, "TEXT")
00248 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::wstring, "TEXT")
00249 QX_REGISTER_TRAIT_GET_SQL_TYPE(QString, "TEXT")
00250 QX_REGISTER_TRAIT_GET_SQL_TYPE(QVariant, "TEXT")
00251 QX_REGISTER_TRAIT_GET_SQL_TYPE(QUuid, "TEXT")
00252 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDate, "DATE")
00253 QX_REGISTER_TRAIT_GET_SQL_TYPE(QTime, "TIME")
00254 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDateTime, "TIMESTAMP")
00255 QX_REGISTER_TRAIT_GET_SQL_TYPE(QByteArray, "BLOB")
00256 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateNeutral, "TEXT")
00257 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxTimeNeutral, "TEXT")
00258 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateTimeNeutral, "TEXT")
00259 
00260 #endif // _QX_GET_SQL_TYPE_H_