mysql/common.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #ifndef SOCI_MYSQL_COMMON_H_INCLUDED
9 #define SOCI_MYSQL_COMMON_H_INCLUDED
10 
11 #include "soci-mysql.h"
12 // std
13 #include <cstddef>
14 #include <ctime>
15 #include <sstream>
16 #include <vector>
17 
18 namespace soci
19 {
20 
21 namespace details
22 {
23 
24 namespace mysql
25 {
26 
27 // helper function for parsing datetime values
28 void parse_std_tm(char const *buf, std::tm &t);
29 
30 // The idea is that infinity - infinity gives NaN, and NaN != NaN is true.
31 //
32 // This should work on any IEEE-754-compliant implementation, which is
33 // another way of saying that it does not always work (in particular,
34 // according to stackoverflow, it won't work with gcc with the --fast-math
35 // option), but I know of no better way of testing this portably in C++ prior
36 // to C++11. When soci moves to C++11 this should be replaced
37 // with std::isfinite().
38 template <typename T>
40 {
41  T y = x - x;
42  return (y != y);
43 }
44 
45 template <typename T>
46 void parse_num(char const *buf, T &x)
47 {
48  std::istringstream iss(buf);
49  iss >> x;
50  if (iss.fail() || (iss.eof() == false))
51  {
52  throw soci_error("Cannot convert data.");
53  }
54  if (is_infinity_or_nan(x)) {
55  throw soci_error("Cannot convert data.");
56  }
57 }
58 
59 // helper for escaping strings
60 char * quote(MYSQL * conn, const char *s, int len);
61 
62 // helper for vector operations
63 template <typename T>
64 std::size_t get_vector_size(void *p)
65 {
66  std::vector<T> *v = static_cast<std::vector<T> *>(p);
67  return v->size();
68 }
69 
70 } // namespace mysql
71 
72 } // namespace details
73 
74 } // namespace soci
75 
76 #endif // SOCI_MYSQL_COMMON_H_INCLUDED
bool is_infinity_or_nan(T x)
Definition: mysql/common.h:39
void parse_std_tm(char const *buf, std::tm &t)
std::size_t get_vector_size(void *p)
Definition: mysql/common.h:64
void parse_num(char const *buf, T &x)
Definition: mysql/common.h:46
SOCI_MYSQL_DECL mysql_backend_factory const mysql
char * quote(MYSQL *conn, const char *s, int len)


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:40