MySQL++: sql_buffer.h Source File
sql_buffer.h
Go to the documentation of this file.
/***********************************************************************
Copyright (c) 2007-2008 by Educational Technology Resources, Inc. and
(c) 2007 by Jonathan Wakely. Others may also hold copyrights on
code in this file. See the CREDITS.txt file in the top directory
of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_SQL_BUFFER_H)
#define MYSQLPP_SQL_BUFFER_H
#include "refcounted.h"
#include "type_info.h"
#include <string>
namespace mysqlpp {
class SQLBuffer
{
public:
typedef size_t size_type;
SQLBuffer(const char* data, size_type length, mysql_type_info type,
bool is_null) : data_(), length_(), type_(type),
is_null_(is_null)
{ replace_buffer(data, length); }
SQLBuffer(const std::string& s, mysql_type_info type, bool is_null) :
data_(), length_(), type_(type), is_null_(is_null)
{
replace_buffer(s.data(), static_cast<size_type>(s.length()));
}
~SQLBuffer() { delete[] data_; }
SQLBuffer& assign(const char* data, size_type length,
mysql_type_info type = mysql_type_info::string_type,
bool is_null = false);
SQLBuffer& assign(const std::string& s,
mysql_type_info type = mysql_type_info::string_type,
bool is_null = false);
const char* data() const { return data_; }
bool escape_q() const { return type_.escape_q(); }
size_type length() const { return length_; }
bool is_string() { return type_ == mysql_type_info::string_type; }
bool is_null() const { return is_null_; }
bool quote_q() const;
void set_null() { is_null_ = true; }
const mysql_type_info& type() const { return type_; }
private:
SQLBuffer(const SQLBuffer&);
SQLBuffer& operator=(const SQLBuffer&);
void init(const char* pd, size_type len, mysql_type_info type,
bool is_null);
void replace_buffer(const char* pd, size_type length);
const char* data_;
size_type length_;
mysql_type_info type_;
bool is_null_;
};
typedef RefCountedPointer<SQLBuffer> RefCountedBuffer;
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_SQL_BUFFER_H)
mysqlpp::SQLBuffer::is_string
bool is_string()
Returns true if type of buffer's contents is string.
Definition: sql_buffer.h:95
mysqlpp::SQLBuffer::is_null
bool is_null() const
Return true if buffer's contents represent a SQL null.
Definition: sql_buffer.h:103
refcounted.h
Declares the RefCountedPointer template.
mysqlpp::SQLBuffer
Holds SQL data in string form plus type information for use in converting the string to compatible C+...
Definition: sql_buffer.h:41
mysqlpp::mysql_type_info
SQL field type information.
Definition: type_info.h:148
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:270
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::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::SQLBuffer::data
const char * data() const
Return pointer to raw data buffer.
Definition: sql_buffer.h:80
type_info.h
Declares classes that provide an interface between the SQL and C++ type systems.
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:283
mysqlpp::SQLBuffer::size_type
size_t size_type
Type of length values.
Definition: sql_buffer.h:45
mysqlpp::RefCountedPointer< SQLBuffer >
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()
Destructor.
Definition: sql_buffer.h:67
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::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::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::set_null
void set_null()
Sets the internal SQL null flag.
Definition: sql_buffer.h:110