QxOrm  1.4.5
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 >= 0x040600)
00049 #include <QtCore/qscopedpointer.h>
00050 #endif // (QT_VERSION >= 0x040600)
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 >= 0x040600)
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 >= 0x040600)
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 template <typename T1, typename T2>
00151 struct get_sql_type< QPair<T1, T2> >
00152 { 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(); } };
00153 
00154 #ifdef _QX_ENABLE_BOOST
00155 
00156 template <typename T1, typename T2>
00157 struct get_sql_type< boost::tuple<T1, T2> >
00158 { 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(); } };
00159 
00160 template <typename T1, typename T2, typename T3>
00161 struct get_sql_type< boost::tuple<T1, T2, T3> >
00162 { 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(); } };
00163 
00164 template <typename T1, typename T2, typename T3, typename T4>
00165 struct get_sql_type< boost::tuple<T1, T2, T3, T4> >
00166 { 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(); } };
00167 
00168 template <typename T1, typename T2, typename T3, typename T4, typename T5>
00169 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5> >
00170 { 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(); } };
00171 
00172 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00173 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6> >
00174 { 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(); } };
00175 
00176 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00177 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7> >
00178 { 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(); } };
00179 
00180 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00181 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
00182 { 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(); } };
00183 
00184 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00185 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
00186 { 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(); } };
00187 
00188 #endif // _QX_ENABLE_BOOST
00189 
00190 template <typename T1, typename T2>
00191 struct get_sql_type< std::tuple<T1, T2> >
00192 { 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(); } };
00193 
00194 template <typename T1, typename T2, typename T3>
00195 struct get_sql_type< std::tuple<T1, T2, T3> >
00196 { 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(); } };
00197 
00198 template <typename T1, typename T2, typename T3, typename T4>
00199 struct get_sql_type< std::tuple<T1, T2, T3, T4> >
00200 { 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(); } };
00201 
00202 template <typename T1, typename T2, typename T3, typename T4, typename T5>
00203 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5> >
00204 { 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(); } };
00205 
00206 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00207 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6> >
00208 { 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(); } };
00209 
00210 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00211 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7> >
00212 { 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(); } };
00213 
00214 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00215 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
00216 { 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(); } };
00217 
00218 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00219 struct get_sql_type< std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
00220 { 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(); } };
00221 
00222 } // namespace trait
00223 } // namespace qx
00224 
00225 #define QX_REGISTER_TRAIT_GET_SQL_TYPE(className, sqlType) \
00226 namespace qx { namespace trait { namespace detail { \
00227 template <> \
00228 struct get_sql_type< className > \
00229 { static inline const char * get() { return get_sql_type_by_class_name(#className, sqlType); } }; }}}
00230 
00231 QX_REGISTER_TRAIT_GET_SQL_TYPE(bool, "SMALLINT")
00232 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx_bool, "TEXT")
00233 QX_REGISTER_TRAIT_GET_SQL_TYPE(char, "SMALLINT")
00234 QX_REGISTER_TRAIT_GET_SQL_TYPE(short, "SMALLINT")
00235 QX_REGISTER_TRAIT_GET_SQL_TYPE(int, "INTEGER")
00236 QX_REGISTER_TRAIT_GET_SQL_TYPE(long, "INTEGER")
00237 QX_REGISTER_TRAIT_GET_SQL_TYPE(long long, "INTEGER")
00238 QX_REGISTER_TRAIT_GET_SQL_TYPE(float, "FLOAT")
00239 QX_REGISTER_TRAIT_GET_SQL_TYPE(double, "FLOAT")
00240 QX_REGISTER_TRAIT_GET_SQL_TYPE(long double, "FLOAT")
00241 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned short, "SMALLINT")
00242 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned int, "INTEGER")
00243 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long, "INTEGER")
00244 QX_REGISTER_TRAIT_GET_SQL_TYPE(unsigned long long, "INTEGER")
00245 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::string, "TEXT")
00246 QX_REGISTER_TRAIT_GET_SQL_TYPE(std::wstring, "TEXT")
00247 QX_REGISTER_TRAIT_GET_SQL_TYPE(QString, "TEXT")
00248 QX_REGISTER_TRAIT_GET_SQL_TYPE(QVariant, "TEXT")
00249 QX_REGISTER_TRAIT_GET_SQL_TYPE(QUuid, "TEXT")
00250 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDate, "DATE")
00251 QX_REGISTER_TRAIT_GET_SQL_TYPE(QTime, "TIME")
00252 QX_REGISTER_TRAIT_GET_SQL_TYPE(QDateTime, "TIMESTAMP")
00253 QX_REGISTER_TRAIT_GET_SQL_TYPE(QByteArray, "BLOB")
00254 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateNeutral, "TEXT")
00255 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxTimeNeutral, "TEXT")
00256 QX_REGISTER_TRAIT_GET_SQL_TYPE(qx::QxDateTimeNeutral, "TEXT")
00257 
00258 #endif // _QX_GET_SQL_TYPE_H_