![]() |
QxOrm 1.1.8
C++ Object Relational Mapping library
|
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/type_traits/is_enum.hpp> 00046 #include <boost/type_traits/is_same.hpp> 00047 00048 #include <QtCore/qsharedpointer.h> 00049 00050 #if (QT_VERSION >= 0x040600) 00051 #include <QtCore/qscopedpointer.h> 00052 #endif // (QT_VERSION >= 0x040600) 00053 00054 #include <QxTraits/is_qx_registered.h> 00055 #include <QxTraits/get_primary_key.h> 00056 #include <QxTraits/remove_attr.h> 00057 #include <QxTraits/get_class_name_primitive.h> 00058 00059 #include <QxDao/QxDaoPointer.h> 00060 #include <QxDao/QxDateNeutral.h> 00061 #include <QxDao/QxTimeNeutral.h> 00062 #include <QxDao/QxDateTimeNeutral.h> 00063 00064 #include <QxCommon/QxBool.h> 00065 00066 namespace qx { 00067 namespace trait { 00068 namespace detail { 00069 00070 template <typename T> 00071 struct get_sql_type_helper 00072 { 00073 00074 private: 00075 00076 typedef typename qx::trait::remove_attr<T>::type type_1; 00077 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; 00078 typedef typename boost::mpl::if_c< boost::is_enum<type_2>::value, long, type_2 >::type type_3; 00079 00080 public: 00081 00082 typedef typename qx::trait::detail::get_sql_type_helper<T>::type_3 type; 00083 00084 }; 00085 00086 template <typename T> 00087 struct get_sql_type 00088 { static inline const char * get() { return ""; } }; 00089 00090 } // namespace detail 00091 00096 template <typename T> 00097 struct get_sql_type 00098 { 00099 typedef typename qx::trait::detail::get_sql_type_helper<T>::type type_sql; 00100 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()); } 00101 }; 00102 00103 template <typename T> 00104 struct get_sql_type< boost::scoped_ptr<T> > 00105 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } }; 00106 00107 template <typename T> 00108 struct get_sql_type< boost::shared_ptr<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::intrusive_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< QSharedPointer<T> > 00117 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } }; 00118 00119 #if (QT_VERSION >= 0x040600) 00120 template <typename T> 00121 struct get_sql_type< QScopedPointer<T> > 00122 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } }; 00123 #endif // (QT_VERSION >= 0x040600) 00124 00125 template <typename T> 00126 struct get_sql_type< qx::dao::ptr<T> > 00127 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } }; 00128 00129 template <typename T1, typename T2> 00130 struct get_sql_type< std::pair<T1, T2> > 00131 { 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(); } }; 00132 00133 template <typename T1, typename T2> 00134 struct get_sql_type< QPair<T1, T2> > 00135 { 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(); } }; 00136 00137 template <typename T1, typename T2> 00138 struct get_sql_type< boost::tuple<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, typename T3> 00142 struct get_sql_type< boost::tuple<T1, T2, T3> > 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()) + "|" + std::string(qx::trait::get_sql_type<T3>::get())); return s.c_str(); } }; 00144 00145 template <typename T1, typename T2, typename T3, typename T4> 00146 struct get_sql_type< boost::tuple<T1, T2, T3, T4> > 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()) + "|" + std::string(qx::trait::get_sql_type<T3>::get()) + "|" + std::string(qx::trait::get_sql_type<T4>::get())); return s.c_str(); } }; 00148 00149 template <typename T1, typename T2, typename T3, typename T4, typename T5> 00150 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5> > 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()) + "|" + std::string(qx::trait::get_sql_type<T4>::get()) + "|" + std::string(qx::trait::get_sql_type<T5>::get())); return s.c_str(); } }; 00152 00153 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> 00154 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6> > 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()) + "|" + std::string(qx::trait::get_sql_type<T5>::get()) + "|" + std::string(qx::trait::get_sql_type<T6>::get())); return s.c_str(); } }; 00156 00157 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> 00158 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7> > 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()) + "|" + std::string(qx::trait::get_sql_type<T6>::get()) + "|" + std::string(qx::trait::get_sql_type<T7>::get())); return s.c_str(); } }; 00160 00161 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> 00162 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> > 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()) + "|" + std::string(qx::trait::get_sql_type<T7>::get()) + "|" + std::string(qx::trait::get_sql_type<T8>::get())); return s.c_str(); } }; 00164 00165 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> 00166 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> > 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()) + "|" + std::string(qx::trait::get_sql_type<T8>::get()) + "|" + std::string(qx::trait::get_sql_type<T9>::get())); return s.c_str(); } }; 00168 00169 namespace detail { 00170 00171 template <> 00172 struct get_sql_type< bool > 00173 { static inline const char * get() { return "SMALLINT"; } }; 00174 00175 template <> 00176 struct get_sql_type< qx_bool > 00177 { static inline const char * get() { return "SMALLINT"; } }; 00178 00179 template <> 00180 struct get_sql_type< short > 00181 { static inline const char * get() { return "SMALLINT"; } }; 00182 00183 template <> 00184 struct get_sql_type< int > 00185 { static inline const char * get() { return "INTEGER"; } }; 00186 00187 template <> 00188 struct get_sql_type< long > 00189 { static inline const char * get() { return "INTEGER"; } }; 00190 00191 template <> 00192 struct get_sql_type< long long > 00193 { static inline const char * get() { return "INTEGER"; } }; 00194 00195 template <> 00196 struct get_sql_type< float > 00197 { static inline const char * get() { return "FLOAT"; } }; 00198 00199 template <> 00200 struct get_sql_type< double > 00201 { static inline const char * get() { return "FLOAT"; } }; 00202 00203 template <> 00204 struct get_sql_type< long double > 00205 { static inline const char * get() { return "FLOAT"; } }; 00206 00207 template <> 00208 struct get_sql_type< unsigned short > 00209 { static inline const char * get() { return "SMALLINT"; } }; 00210 00211 template <> 00212 struct get_sql_type< unsigned int > 00213 { static inline const char * get() { return "INTEGER"; } }; 00214 00215 template <> 00216 struct get_sql_type< unsigned long > 00217 { static inline const char * get() { return "INTEGER"; } }; 00218 00219 template <> 00220 struct get_sql_type< unsigned long long > 00221 { static inline const char * get() { return "INTEGER"; } }; 00222 00223 template <> 00224 struct get_sql_type< std::string > 00225 { static inline const char * get() { return "TEXT"; } }; 00226 00227 template <> 00228 struct get_sql_type< std::wstring > 00229 { static inline const char * get() { return "TEXT"; } }; 00230 00231 template <> 00232 struct get_sql_type< QString > 00233 { static inline const char * get() { return "TEXT"; } }; 00234 00235 template <> 00236 struct get_sql_type< QVariant > 00237 { static inline const char * get() { return "TEXT"; } }; 00238 00239 template <> 00240 struct get_sql_type< QUuid > 00241 { static inline const char * get() { return "TEXT"; } }; 00242 00243 template <> 00244 struct get_sql_type< QDate > 00245 { static inline const char * get() { return "DATE"; } }; 00246 00247 template <> 00248 struct get_sql_type< QTime > 00249 { static inline const char * get() { return "TIME"; } }; 00250 00251 template <> 00252 struct get_sql_type< QDateTime > 00253 { static inline const char * get() { return "TIMESTAMP"; } }; 00254 00255 template <> 00256 struct get_sql_type< QByteArray > 00257 { static inline const char * get() { return "BLOB"; } }; 00258 00259 template <> 00260 struct get_sql_type< qx::QxDateNeutral > 00261 { static inline const char * get() { return "TEXT"; } }; 00262 00263 template <> 00264 struct get_sql_type< qx::QxTimeNeutral > 00265 { static inline const char * get() { return "TEXT"; } }; 00266 00267 template <> 00268 struct get_sql_type< qx::QxDateTimeNeutral > 00269 { static inline const char * get() { return "TEXT"; } }; 00270 00271 } // namespace detail 00272 } // namespace trait 00273 } // namespace qx 00274 00275 #endif // _QX_GET_SQL_TYPE_H_