MySQL++  3.2.5
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 
79  SQLTypeAdapter();
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 
116  SQLTypeAdapter(tiny_int<signed char> i);
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);
306  SQLTypeAdapter(Null<char> c);
307  SQLTypeAdapter(Null< tiny_int<signed char> > i);
308  SQLTypeAdapter(Null< tiny_int<unsigned char> > i);
309  SQLTypeAdapter(Null<short> i);
310  SQLTypeAdapter(Null<unsigned short> i);
311  SQLTypeAdapter(Null<int> i);
312  SQLTypeAdapter(Null<unsigned> i);
313  SQLTypeAdapter(Null<long> i);
314  SQLTypeAdapter(Null<unsigned long> i);
315  SQLTypeAdapter(Null<longlong> i);
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)
mysqlpp::SQLTypeAdapter::operator=
SQLTypeAdapter & operator=(const SQLTypeAdapter &rhs)
Standard assignment operator.
Definition: stadapter.cpp:499
mysqlpp::BadIndex
Exception thrown when an object with operator [] or an at() method gets called with a bad index.
Definition: exceptions.h:202
mysqlpp::SQLBuffer::type
const mysql_type_info & type() const
Return the SQL type of the data held in the buffer.
Definition: sql_buffer.h:157
stream2string.h
Declares an adapter that converts something that can be inserted into a C++ stream into a std::string...
mysqlpp::SQLTypeAdapter::quote_q
bool quote_q() const
Returns true if we were initialized with a data type that must be quoted when used in a SQL query.
Definition: stadapter.cpp:511
mysqlpp::SQLBuffer::data
const char * data() const
Return pointer to raw data buffer.
Definition: sql_buffer.h:124
mysqlpp::SQLTypeAdapter::escape_q
bool escape_q() const
Returns true if we were initialized with a data type that must be escaped when used in a SQL query.
Definition: stadapter.cpp:493
mysqlpp::SQLBuffer::length
size_type length() const
Return number of bytes in data buffer.
Definition: sql_buffer.h:136
mysqlpp::SQLTypeAdapter::at
char at(size_type i) const
Returns the character at a given position within the string buffer.
Definition: stadapter.cpp:419
stadapter.h
Declares the SQLTypeAdapter class.
refcounted.h
Declares the RefCountedPointer template.
mysqlpp::Date
C++ form of SQL's DATE type.
Definition: datetime.h:247
mysqlpp::Null::data
Type data
The object's value, when it is not SQL null.
Definition: null.h:196
mysqlpp::SQLTypeAdapter::length
size_type length() const
Return number of bytes in data buffer.
Definition: stadapter.cpp:487
tiny_int.h
Declares class for holding a SQL TINYINT.
mysqlpp::mysql_type_info::id
int id() const
Returns the ID of the SQL type.
Definition: type_info.h:282
mysqlpp::SQLBuffer
Holds SQL data in string form plus type information for use in converting the string to compatible C+...
Definition: sql_buffer.h:63
mysqlpp::SQLTypeAdapter
Converts many different data types to strings suitable for use in SQL queries.
Definition: stadapter.h:95
mysqlpp::SQLTypeAdapter::SQLTypeAdapter
SQLTypeAdapter()
Default constructor; empty string.
Definition: stadapter.cpp:41
mysqlpp::SQLBuffer::quote_q
bool quote_q() const
Returns true if we were initialized with a data type that must be quoted when used in a SQL query.
Definition: sql_buffer.cpp:79
mysqlpp::null_type
The type of the global mysqlpp::null object.
Definition: null.h:71
mysqlpp::SQLBuffer::escape_q
bool escape_q() const
Returns true if we were initialized with a data type that must be escaped when used in a SQL query.
Definition: sql_buffer.h:128
null.h
Declares classes that implement SQL "null" semantics within C++'s type system.
mysqlpp::RefCountedPointer< SQLBuffer >
mysqlpp::SQLTypeAdapter::assign
SQLTypeAdapter & assign(const SQLTypeAdapter &sta)
Copies another SQLTypeAdapter's data buffer into this object.
Definition: stadapter.cpp:391
mysqlpp::SQLTypeAdapter::compare
int compare(const SQLTypeAdapter &other) const
Compare the internal buffer to the given string.
Definition: stadapter.cpp:436
mysqlpp::Time
C++ form of SQL's TIME type.
Definition: datetime.h:369
mysqlpp::null_str
const std::string null_str
"NULL" string constant
mysqlpp::Null
Class for holding data from a SQL column with the NULL attribute.
Definition: null.h:192
mysqlpp::SQLTypeAdapter::type_id
int type_id() const
Returns the type ID of the buffer's data.
Definition: stadapter.cpp:519
common.h
This file includes top-level definitions for use both internal to the library, and outside it....
mysqlpp::String
A std::string work-alike that can convert itself from SQL text data formats to C++ data types.
Definition: mystring.h:161
mysqlpp::mysql_type_info
SQL field type information.
Definition: type_info.h:170
mysqlpp::DateTime
C++ form of SQL's DATETIME type.
Definition: datetime.h:70
mysqlpp::mysql_type_info::string_type
static const enum_field_types string_type
The internal constant we use for our string type.
Definition: type_info.h:314
mysqlpp::tiny_int
Class for holding an SQL TINYINT value.
Definition: tiny_int.h:77
mysqlpp::SQLTypeAdapter::data
const char * data() const
Return pointer to raw data buffer.
Definition: stadapter.cpp:481
mysqlpp::SQLTypeAdapter::size_type
size_t size_type
size of length values
Definition: stadapter.h:120
mysqlpp::Null::is_null
bool is_null
If set, this object is considered equal to SQL null.
Definition: null.h:201
mystring.h
Declares String class, MySQL++'s generic std::string-like class, used for holding data received from ...
sql_buffer.h
Declares the SQLBuffer class.
datetime.h
Declares classes to add SQL-compatible date and time types to C++'s type system.
mysqlpp::stream2string
std::string stream2string(const T &object)
Converts anything you can insert into a C++ stream to a std::string via std::ostringstream.
Definition: stream2string.h:63