/usr/include/Wt/Dbo/StdSqlTraits is in libwtdbo-dev 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WT_DBO_STD_SQL_TRAITS_H_
#define WT_DBO_STD_SQL_TRAITS_H_
#include <string>
#include <vector>
#include <Wt/Dbo/SqlTraits>
#include <Wt/Dbo/SqlStatement>
#include <boost/optional.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_enum.hpp>
namespace Wt {
namespace Dbo {
template<>
struct WTDBO_API sql_value_traits<std::string, void>
{
static const bool specialized = true;
static std::string type(SqlConnection *conn, int size);
static void bind(const std::string& v, SqlStatement *statement, int column,
int size);
static bool read(std::string& v, SqlStatement *statement, int column,
int size);
};
template<>
struct WTDBO_API sql_value_traits<long long, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(long long v, SqlStatement *statement, int column, int size);
static bool read(long long& v, SqlStatement *statement, int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<int, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(int v, SqlStatement *statement, int column, int size);
static bool read(int& v, SqlStatement *statement, int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<long, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(long v, SqlStatement *statement, int column, int size);
static bool read(long& v, SqlStatement *statement, int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<short, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(short v, SqlStatement *statement, int column, int size);
static bool read(short& v, SqlStatement *statement, int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<bool, void>
{
static const bool specialized = true;
static std::string type(SqlConnection *conn, int size);
static void bind(bool v, SqlStatement *statement, int column, int size);
static bool read(bool& v, SqlStatement *statement, int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<float, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(float v, SqlStatement *statement, int column, int size);
static bool read(float& v, SqlStatement *statement, int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<double, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(double v, SqlStatement *statement, int column, int size);
static bool read(double& v, SqlStatement *statement, int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<boost::posix_time::ptime, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(const boost::posix_time::ptime& v, SqlStatement *statement,
int column, int size);
static bool read(boost::posix_time::ptime& v, SqlStatement *statement,
int column, int size);
};
template<>
struct WTDBO_API sql_value_traits<boost::posix_time::time_duration, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(const boost::posix_time::time_duration& v,
SqlStatement *statement, int column, int size);
static bool read(boost::posix_time::time_duration& v,
SqlStatement *statement, int column, int size);
};
template <typename Enum>
struct WTDBO_API sql_value_traits<Enum,
typename boost::enable_if<boost::is_enum<Enum> >::type>
: public sql_value_traits<int>
{
static void bind(Enum v, SqlStatement *statement, int column, int size) {
sql_value_traits<int>::bind(static_cast<int>(v), statement, column, size);
}
static bool read(Enum& v, SqlStatement *statement, int column, int size) {
return sql_value_traits<int>::read(reinterpret_cast<int&>(v), statement,
column, size);
}
};
template<>
struct WTDBO_API sql_value_traits<std::vector<unsigned char>, void>
{
static const bool specialized = true;
static const char *type(SqlConnection *conn, int size);
static void bind(const std::vector<unsigned char>& v,
SqlStatement *statement, int column, int size);
static bool read(std::vector<unsigned char>& v, SqlStatement *statement,
int column, int size);
};
template<typename T>
struct sql_value_traits<boost::optional<T>, void>
{
static const bool specialized = true;
static std::string type(SqlConnection *conn, int size) {
std::string nested = sql_value_traits<T>::type(conn, size);
if (nested.length() > 9
&& nested.substr(nested.length() - 9) == " not null")
return nested.substr(0, nested.length() - 9);
else
return nested;
}
static void bind(const boost::optional<T>& v,
SqlStatement *statement, int column, int size) {
if (v)
sql_value_traits<T>::bind(v.get(), statement, column, size);
else
statement->bindNull(column);
}
static bool read(boost::optional<T>& v, SqlStatement *statement, int column,
int size) {
T result;
if (sql_value_traits<T>::read(result, statement, column, size)) {
v = result;
return true;
} else {
v = boost::optional<T>();
return false;
}
}
};
}
}
#endif // WT_DBO_STD_SQL_TRAITS_H_
|