MySQL++ Reference Manual

MySQL++: sql_buffer.h Source File

MySQL++ 3.3.0

sql_buffer.h
Go to the documentation of this file.
1
4 /***********************************************************************
5 Copyright (c) 2007-2008 by Educational Technology Resources, Inc. and
6 (c) 2007 by Jonathan Wakely. Others may also hold copyrights on
7 code in this file. See the CREDITS.txt file in the top directory
8 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_BUFFER_H)
29 #define MYSQLPP_SQL_BUFFER_H
30
31 #include "refcounted.h"
32 #include "type_info.h"
33
34 #include <string>
35
36 namespace mysqlpp {
37
40
41 class SQLBuffer
42 {
43 public:
45 typedef size_t size_type;
46
54 SQLBuffer(const char* data, size_type length, mysql_type_info type,
55 bool is_null) : data_(), length_(), type_(type),
56 is_null_(is_null)
57 { replace_buffer(data, length); }
58
60 SQLBuffer(const std::string& s, mysql_type_info type, bool is_null) :
61 data_(), length_(), type_(type), is_null_(is_null)
62 {
63 replace_buffer(s.data(), static_cast<size_type>(s.length()));
64 }
65
67 ~SQLBuffer() { delete[] data_; }
68
70 SQLBuffer& assign(const char* data, size_type length,
71 mysql_type_info type = mysql_type_info::string_type,
72 bool is_null = false);
73
75 SQLBuffer& assign(const std::string& s,
76 mysql_type_info type = mysql_type_info::string_type,
77 bool is_null = false);
78
80 const char* data() const { return data_; }
81
84 bool escape_q() const { return type_.escape_q(); }
85
92 size_type length() const { return length_; }
93
95 bool is_string() { return type_ == mysql_type_info::string_type; }
96
103 bool is_null() const { return is_null_; }
104
107 bool quote_q() const;
108
110 void set_null() { is_null_ = true; }
111
113 const mysql_type_info& type() const { return type_; }
114
115 private:
116 SQLBuffer(const SQLBuffer&);
117 SQLBuffer& operator=(const SQLBuffer&);
118
120 void init(const char* pd, size_type len, mysql_type_info type,
121 bool is_null);
123 void replace_buffer(const char* pd, size_type length);
124
125 const char* data_;
126 size_type length_;
127 mysql_type_info type_;
128 bool is_null_;
129 };
130
131
136 typedef RefCountedPointer<SQLBuffer> RefCountedBuffer;
137
138 } // end namespace mysqlpp
139
140 #endif // !defined(MYSQLPP_SQL_BUFFER_H)
141
mysqlpp::RefCountedPointer< SQLBuffer >
mysqlpp::SQLBuffer
Holds SQL data in string form plus type information for use in converting the string to compatible C+...
Definition: sql_buffer.h:42
mysqlpp::SQLBuffer::set_null
void set_null()
Sets the internal SQL null flag.
Definition: sql_buffer.h:110
mysqlpp::SQLBuffer::~SQLBuffer
~SQLBuffer()
Destructor.
Definition: sql_buffer.h:67
mysqlpp::SQLBuffer::SQLBuffer
SQLBuffer(const char *data, size_type length, mysql_type_info type, bool is_null)
Initialize object as a copy of a raw data buffer.
Definition: sql_buffer.h:54
mysqlpp::SQLBuffer::length
size_type length() const
Return number of bytes in data buffer.
Definition: sql_buffer.h:92
mysqlpp::SQLBuffer::size_type
size_t size_type
Type of length values.
Definition: sql_buffer.h:45
mysqlpp::SQLBuffer::is_null
bool is_null() const
Return true if buffer's contents represent a SQL null.
Definition: sql_buffer.h:103
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:56
mysqlpp::SQLBuffer::is_string
bool is_string()
Returns true if type of buffer's contents is string.
Definition: sql_buffer.h:95
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:84
mysqlpp::SQLBuffer::data
const char * data() const
Return pointer to raw data buffer.
Definition: sql_buffer.h:80
mysqlpp::SQLBuffer::assign
SQLBuffer & assign(const char *data, size_type length, mysql_type_info type=mysql_type_info::string_type, bool is_null=false)
Replace contents of buffer with copy of given C string.
Definition: sql_buffer.cpp:37
mysqlpp::SQLBuffer::type
const mysql_type_info & type() const
Return the SQL type of the data held in the buffer.
Definition: sql_buffer.h:113
mysqlpp::SQLBuffer::SQLBuffer
SQLBuffer(const std::string &s, mysql_type_info type, bool is_null)
Initialize object as a copy of a C++ string object.
Definition: sql_buffer.h:60
mysqlpp::mysql_type_info
SQL field type information.
Definition: type_info.h:159
mysqlpp::mysql_type_info::escape_q
bool escape_q() const
Returns true if the SQL type is of a type that needs to be escaped.
Definition: type_info.cpp:287
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:280
refcounted.h
Declares the RefCountedPointer template.
type_info.h
Declares classes that provide an interface between the SQL and C++ type systems.