MySQL++  3.3.0
stadapter.h
Go to the documentation of this file.
1 
4 /***********************************************************************
5  Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB, and
6  © 2004-2009, 2018 by Educational Technology Resources, Inc. Others may
7  also hold copyrights on code in this file. See the CREDITS.txt file
8  in the top directory of the distribution for details.
9 
10  This file is part of MySQL++.
11 
12  MySQL++ is free software; you can redistribute it and/or modify it
13  under the terms of the GNU Lesser General Public License as published
14  by the Free Software Foundation; either version 2.1 of the License, or
15  (at your option) any later version.
16 
17  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public
23  License along with MySQL++; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25  USA
26 ***********************************************************************/
27 
28 #if !defined(MYSQLPP_SQL_TYPE_ADAPTER_H)
29 #define MYSQLPP_SQL_TYPE_ADAPTER_H
30 
31 #include "common.h"
32 
33 #include "datetime.h"
34 #include "null.h"
35 #include "sql_buffer.h"
36 #include "tiny_int.h"
37 
38 #include <stdexcept>
39 #include <string>
40 
41 namespace mysqlpp {
42 
43 #if !defined(DOXYGEN_IGNORE)
44 class MYSQLPP_EXPORT String;
45 #endif
46 
72 
73 class MYSQLPP_EXPORT SQLTypeAdapter
74 {
75 public:
76  typedef size_t size_type;
77 
80 
88  SQLTypeAdapter(const SQLTypeAdapter& other);
89 
96  SQLTypeAdapter(const String& str, bool processed = false);
97 
99  SQLTypeAdapter(const std::string& str, bool processed = false);
100 
102  SQLTypeAdapter(const char* str, bool processed = false);
103 
105  SQLTypeAdapter(const char* str, int len, bool processed = false);
106 
113  SQLTypeAdapter(char c);
114 
117 
121 
123  SQLTypeAdapter(short i);
124 
127  SQLTypeAdapter(unsigned short i);
128 
130  SQLTypeAdapter(int i);
131 
134  SQLTypeAdapter(unsigned i);
135 
137  SQLTypeAdapter(long i);
138 
141  SQLTypeAdapter(unsigned long i);
142 
144  SQLTypeAdapter(longlong i);
145 
148  SQLTypeAdapter(ulonglong i);
149 
151  SQLTypeAdapter(float i);
152 
154  SQLTypeAdapter(double i);
155 
157  SQLTypeAdapter(const Date& d);
158 
160  SQLTypeAdapter(const DateTime& dt);
161 
163  SQLTypeAdapter(const Time& t);
164 
166  SQLTypeAdapter(const null_type& i);
167 
171  SQLTypeAdapter& operator =(const SQLTypeAdapter& rhs);
172 
176  SQLTypeAdapter& operator =(const null_type& n);
177 
179  operator const char*() const { return data(); }
180 
192  SQLTypeAdapter& assign(const SQLTypeAdapter& sta);
193 
205  SQLTypeAdapter& assign(const char* pc, int len = -1);
206 
212  SQLTypeAdapter& assign(const null_type& n);
213 
225 #if !defined(DOXYGEN_IGNORE) && __cplusplus >= 201103L
226  // Can't use MAY_THROW() here: it confuses Doxygen 1.8.14.
227  char at(size_type i) const noexcept(false);
228 #else
229  char at(size_type i) const throw(std::out_of_range);
230 #endif
231 
235  int compare(const SQLTypeAdapter& other) const;
236 
240  int compare(const std::string& other) const;
241 
246  int compare(size_type pos, size_type num, std::string& other) const;
247 
251  int compare(const char* other) const;
252 
257  int compare(size_type pos, size_type num, const char* other) const;
258 
260  const char* data() const;
261 
264  bool escape_q() const;
265 
272  bool is_null() const { return buffer_->is_null(); }
273 
278  bool is_processed() const { return is_processed_; }
279 
281  size_type length() const;
282  size_type size() const { return length(); }
283 
286  bool quote_q() const;
287 
293  int type_id() const;
294 
299  void set_processed() { is_processed_ = true; }
300 
301 #if !defined(DOXYGEN_IGNORE)
302  // Parallel interface for Null<>-wrapped versions of types we
303  // support above. No need for parallel documentation.
304  SQLTypeAdapter(const Null<std::string>& str, bool processed = false);
305  SQLTypeAdapter(const Null<String>& str, bool processed = false);
319  SQLTypeAdapter(const Null<Date>& d);
320  SQLTypeAdapter(const Null<DateTime>& dt);
321  SQLTypeAdapter(const Null<Time>& t);
322  SQLTypeAdapter& operator =(const Null<std::string>& str);
323 #endif // !defined(DOXYGEN_IGNORE)
324 
325 private:
327  RefCountedBuffer buffer_;
328 
339  bool is_processed_;
340 };
341 
342 } // end namespace mysqlpp
343 
344 #endif // !defined(MYSQLPP_SQL_TYPE_ADAPTER_H)
C++ form of SQL's DATETIME type.
Definition: datetime.h:49
C++ form of SQL's DATE type.
Definition: datetime.h:226
Class for holding data from a SQL column with the NULL attribute.
Definition: null.h:171
Converts many different data types to strings suitable for use in SQL queries.
Definition: stadapter.h:74
size_type size() const
alias for length()
Definition: stadapter.h:282
void set_processed()
Turns on the internal 'is_processed_' flag.
Definition: stadapter.h:299
bool is_null() const
Return true if buffer's contents represent a SQL null.
Definition: stadapter.h:272
bool is_processed() const
Returns true if the internal 'processed' flag is set.
Definition: stadapter.h:278
size_t size_type
size of length values
Definition: stadapter.h:76
A std::string work-alike that can convert itself from SQL text data formats to C++ data types.
Definition: mystring.h:140
C++ form of SQL's TIME type.
Definition: datetime.h:348
The type of the global mysqlpp::null object.
Definition: null.h:50
Class for holding an SQL TINYINT value.
Definition: tiny_int.h:56
This file includes top-level definitions for use both internal to the library, and outside it....
Declares classes to add SQL-compatible date and time types to C++'s type system.
Declares classes that implement SQL "null" semantics within C++'s type system.
Declares the SQLBuffer class.
Declares class for holding a SQL TINYINT.