00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }
00139
00140 #endif // !defined(MYSQLPP_SQL_BUFFER_H)
00141