- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# sql_buffer.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004 /***********************************************************************
    00005  Copyright (c) 2007-2008 by Educational Technology Resources, Inc. and
    00006  (c) 2007 by Jonathan Wakely.  Others may also hold copyrights on
    00007  code in this file.  See the CREDITS.txt file in the top directory
    00008  of the distribution for details.
    00009
    00010  This file is part of MySQL++.
    00011
    00012  MySQL++ is free software; you can redistribute it and/or modify it
    00013  under the terms of the GNU Lesser General Public License as published
    00014  by the Free Software Foundation; either version 2.1 of the License, or
    00015  (at your option) any later version.
    00016
    00017  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00018  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00019  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00020  License for more details.
    00021
    00022  You should have received a copy of the GNU Lesser General Public
    00023  License along with MySQL++; if not, write to the Free Software
    00024  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00025  USA
    00026 ***********************************************************************/
    00027
    00028 #if !defined(MYSQLPP_SQL_BUFFER_H)
    00029 #define MYSQLPP_SQL_BUFFER_H
    00030
    00031 #include "refcounted.h"
    00032 #include "type_info.h"
    00033
    00034 #include <string>
    00035
    00036 namespace mysqlpp {
    00037
    00040
    00041 class SQLBuffer
    00042 {
    00043 public:
    00045         typedef size_t size_type;
    00046
    00054         SQLBuffer(const char* data, size_type length, mysql_type_info type,
    00055                         bool is_null) : data_(), length_(), type_(type),
    00056                         is_null_(is_null)
    00057                         { replace_buffer(data, length); }
    00058
    00060         SQLBuffer(const std::string& s, mysql_type_info type, bool is_null) :
    00061                         data_(), length_(), type_(type), is_null_(is_null)
    00062         {
    00063                 replace_buffer(s.data(), static_cast<size_type>(s.length()));
    00064         }
    00065
    00067         ~SQLBuffer() { delete[] data_; }
    00068
    00070         SQLBuffer& assign(const char* data, size_type length,
    00071                         mysql_type_info type = mysql_type_info::string_type,
    00072                         bool is_null = false);
    00073
    00075         SQLBuffer& assign(const std::string& s,
    00076                         mysql_type_info type = mysql_type_info::string_type,
    00077                         bool is_null = false);
    00078
    00080         const char* data() const { return data_; }
    00081
    00084         bool escape_q() const { return type_.escape_q(); }
    00085
    00092         size_type length() const { return length_; }
    00093
    00095         bool is_string() { return type_ == mysql_type_info::string_type; }
    00096
    00103         bool is_null() const { return is_null_; }
    00104
    00107         bool quote_q() const;
    00108
    00110         void set_null() { is_null_ = true; }
    00111
    00113         const mysql_type_info& type() const { return type_; }
    00114
    00115 private:
    00116         SQLBuffer(const SQLBuffer&);
    00117         SQLBuffer& operator=(const SQLBuffer&);
    00118
    00120         void init(const char* pd, size_type len, mysql_type_info type,
    00121                         bool is_null);
    00123         void replace_buffer(const char* pd, size_type length);
    00124
    00125         const char* data_;
    00126         size_type length_;
    00127         mysql_type_info type_;
    00128         bool is_null_;
    00129 };
    00130
    00131
    00136 typedef RefCountedPointer<SQLBuffer> RefCountedBuffer;
    00137
    00138 } // end namespace mysqlpp
    00139
    00140 #endif // !defined(MYSQLPP_SQL_BUFFER_H)
    00141