QxOrm 1.1.6
C++ Object Relational Mapping library
get_sql_type.h
Go to the documentation of this file.
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 <QxDao/QxDaoPointer.h>
00055 
00056 #include <QxTraits/is_qx_registered.h>
00057 #include <QxTraits/get_primary_key.h>
00058 #include <QxTraits/remove_attr.h>
00059 #include <QxTraits/get_class_name_primitive.h>
00060 
00061 #include <QxCommon/QxBool.h>
00062 
00063 namespace qx {
00064 namespace trait {
00065 namespace detail {
00066 
00067 template <typename T>
00068 struct get_sql_type_helper
00069 {
00070 
00071 private:
00072 
00073    typedef typename qx::trait::remove_attr<T>::type type_1;
00074    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;
00075    typedef typename boost::mpl::if_c< boost::is_enum<type_2>::value, long, type_2 >::type type_3;
00076 
00077 public:
00078 
00079    typedef typename qx::trait::detail::get_sql_type_helper<T>::type_3 type;
00080 
00081 };
00082 
00083 template <typename T>
00084 struct get_sql_type
00085 { static inline const char * get() { return ""; } };
00086 
00087 } // namespace detail
00088 
00093 template <typename T>
00094 struct get_sql_type
00095 {
00096    typedef typename qx::trait::detail::get_sql_type_helper<T>::type type_sql;
00097    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()); }
00098 };
00099 
00100 template <typename T>
00101 struct get_sql_type< boost::scoped_ptr<T> >
00102 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00103 
00104 template <typename T>
00105 struct get_sql_type< boost::shared_ptr<T> >
00106 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00107 
00108 template <typename T>
00109 struct get_sql_type< boost::intrusive_ptr<T> >
00110 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00111 
00112 template <typename T>
00113 struct get_sql_type< QSharedPointer<T> >
00114 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00115 
00116 #if (QT_VERSION >= 0x040600)
00117 template <typename T>
00118 struct get_sql_type< QScopedPointer<T> >
00119 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00120 #endif // (QT_VERSION >= 0x040600)
00121 
00122 template <typename T>
00123 struct get_sql_type< qx::dao::ptr<T> >
00124 { static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
00125 
00126 template <typename T1, typename T2>
00127 struct get_sql_type< std::pair<T1, T2> >
00128 { 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(); } };
00129 
00130 template <typename T1, typename T2>
00131 struct get_sql_type< QPair<T1, T2> >
00132 { 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(); } };
00133 
00134 template <typename T1, typename T2>
00135 struct get_sql_type< boost::tuple<T1, T2> >
00136 { 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(); } };
00137 
00138 template <typename T1, typename T2, typename T3>
00139 struct get_sql_type< boost::tuple<T1, T2, T3> >
00140 { 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(); } };
00141 
00142 template <typename T1, typename T2, typename T3, typename T4>
00143 struct get_sql_type< boost::tuple<T1, T2, T3, T4> >
00144 { 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(); } };
00145 
00146 template <typename T1, typename T2, typename T3, typename T4, typename T5>
00147 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5> >
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()) + "|" + 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(); } };
00149 
00150 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00151 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6> >
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()) + "|" + 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(); } };
00153 
00154 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00155 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7> >
00156 { 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(); } };
00157 
00158 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00159 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >
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()) + "|" + 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(); } };
00161 
00162 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00163 struct get_sql_type< boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> >
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()) + "|" + 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(); } };
00165 
00166 namespace detail {
00167 
00168 template <>
00169 struct get_sql_type< bool >
00170 { static inline const char * get() { return "SMALLINT"; } };
00171 
00172 template <>
00173 struct get_sql_type< qx_bool >
00174 { static inline const char * get() { return "SMALLINT"; } };
00175 
00176 template <>
00177 struct get_sql_type< short >
00178 { static inline const char * get() { return "SMALLINT"; } };
00179 
00180 template <>
00181 struct get_sql_type< int >
00182 { static inline const char * get() { return "INTEGER"; } };
00183 
00184 template <>
00185 struct get_sql_type< long >
00186 { static inline const char * get() { return "INTEGER"; } };
00187 
00188 template <>
00189 struct get_sql_type< long long >
00190 { static inline const char * get() { return "INTEGER"; } };
00191 
00192 template <>
00193 struct get_sql_type< float >
00194 { static inline const char * get() { return "FLOAT"; } };
00195 
00196 template <>
00197 struct get_sql_type< double >
00198 { static inline const char * get() { return "FLOAT"; } };
00199 
00200 template <>
00201 struct get_sql_type< long double >
00202 { static inline const char * get() { return "FLOAT"; } };
00203 
00204 template <>
00205 struct get_sql_type< unsigned short >
00206 { static inline const char * get() { return "SMALLINT"; } };
00207 
00208 template <>
00209 struct get_sql_type< unsigned int >
00210 { static inline const char * get() { return "INTEGER"; } };
00211 
00212 template <>
00213 struct get_sql_type< unsigned long >
00214 { static inline const char * get() { return "INTEGER"; } };
00215 
00216 template <>
00217 struct get_sql_type< unsigned long long >
00218 { static inline const char * get() { return "INTEGER"; } };
00219 
00220 template <>
00221 struct get_sql_type< std::string >
00222 { static inline const char * get() { return "TEXT"; } };
00223 
00224 template <>
00225 struct get_sql_type< std::wstring >
00226 { static inline const char * get() { return "TEXT"; } };
00227 
00228 template <>
00229 struct get_sql_type< QString >
00230 { static inline const char * get() { return "TEXT"; } };
00231 
00232 template <>
00233 struct get_sql_type< QDate >
00234 { static inline const char * get() { return "DATE"; } };
00235 
00236 template <>
00237 struct get_sql_type< QTime >
00238 { static inline const char * get() { return "TIME"; } };
00239 
00240 template <>
00241 struct get_sql_type< QDateTime >
00242 { static inline const char * get() { return "TIMESTAMP"; } };
00243 
00244 template <>
00245 struct get_sql_type< QByteArray >
00246 { static inline const char * get() { return "BLOB"; } };
00247 
00248 } // namespace detail
00249 } // namespace trait
00250 } // namespace qx
00251 
00252 #endif // _QX_GET_SQL_TYPE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines