29 #if !defined(MYSQLPP_MYSTRING_H) 
   30 #define MYSQLPP_MYSTRING_H 
   48 #if !defined(DOXYGEN_IGNORE) 
   53         template<typename T, bool is_signed = std::numeric_limits<T>::is_signed>
 
   54         struct conv_promotion;
 
   57         struct conv_promotion<float>
 
   63         struct conv_promotion<double>
 
   68 #       if !defined(NO_LONG_LONGS) 
   70         struct conv_promotion<unsigned long long>
 
   72                 typedef unsigned long long type;
 
   76         struct conv_promotion<long long>
 
   78                 typedef long long type;
 
   84         struct conv_promotion<char>
 
   92         struct conv_promotion<T, true>
 
   98         struct conv_promotion<T, false>
 
  100                 typedef unsigned long type;
 
  104 class MYSQLPP_EXPORT SQLTypeAdapter;
 
  105 #endif // !defined(DOXYGEN_IGNORE) 
  156 #if !defined(DOXYGEN_IGNORE) 
  158         typedef int difference_type;
 
  159         typedef const char* const_pointer;
 
  160         typedef const_pointer pointer;
 
  161 #endif // !defined(DOXYGEN_IGNORE) 
  180         buffer_(other.buffer_)
 
  198                         bool is_null = 
false) :
 
  199         buffer_(new 
SQLBuffer(str, len, type, is_null))
 
  212                         bool is_null = 
false) :
 
  227                         bool is_null = 
false) :
 
  244                         bool is_null = 
false)
 
  246                 buffer_ = 
new SQLBuffer(str, len, type, is_null);
 
  257                         bool is_null = 
false)
 
  260                                 static_cast<size_type>(str.length()), type, is_null);
 
  271                         bool is_null = 
false)
 
  273                 buffer_ = 
new SQLBuffer(str, static_cast<size_type>(strlen(str)),
 
  281         char at(size_type pos) 
const;
 
  288         const char* 
c_str()
 const { 
return data(); }
 
  290 #if defined(MYSQLPP_PLATFORM_VISUAL_CPP) 
  292 #   pragma warning(disable: 4244) 
  297         template <
class Type>
 
  303                 typedef typename detail::conv_promotion<Type>::type conv_type;
 
  304                 return do_conv<conv_type>(
typeid(Type).name());
 
  307 #if defined(MYSQLPP_PLATFORM_VISUAL_CPP) 
  308 #   pragma warning(default: 4244) 
  317         template <
class T, 
class B>
 
  333         int compare(
const String& other) 
const;
 
  340         int compare(
const std::string& other) 
const;
 
  350         int compare(size_type pos, size_type num, std::string& other) 
const;
 
  357         int compare(
const char* other) 
const;
 
  369         int compare(size_type pos, size_type num, 
const char* other) 
const;
 
  373         const char* data() 
const;
 
  376         bool empty()
 const { 
return size() == 0; }
 
  380         const_iterator end() 
const;
 
  384         bool escape_q() 
const;
 
  387         bool is_null() 
const;
 
  400         size_type length() 
const;
 
  411         bool quote_q() 
const;
 
  423                 const char* pc = data();
 
  426                         while (n && (*pc == 
' ')) {
 
  445         void to_string(std::string& s) 
const;
 
  454         String& operator =(
const std::string& rhs)
 
  470                                 static_cast<size_type>(strlen(str)),
 
  483                 buffer_ = other.buffer_;
 
  492         template <
typename T>
 
  493         bool operator ==(
const T& rhs)
 const 
  495                 return compare(rhs) == 0;
 
  510         template <
typename T>
 
  511         bool operator !=(
const T& rhs)
 const 
  513                 return compare(rhs) != 0;
 
  530         char operator [](
size_type pos)
 const { 
return at(pos); }
 
  533         operator const char*() 
const { 
return data(); }
 
  536         operator signed char()
 const 
  537                         { 
return conv(static_cast<signed char>(0)); }
 
  540         operator unsigned char()
 const 
  541                         { 
return conv(static_cast<unsigned char>(0)); }
 
  545                         { 
return conv(static_cast<int>(0)); }
 
  548         operator unsigned int()
 const 
  549                         { 
return conv(static_cast<unsigned int>(0)); }
 
  552         operator short int()
 const 
  553                         { 
return conv(static_cast<short int>(0)); }
 
  557         operator unsigned short int()
 const 
  558                         { 
return conv(static_cast<unsigned short int>(0)); }
 
  561         operator long int()
 const 
  562                         { 
return conv(static_cast<long int>(0)); }
 
  566         operator unsigned long int()
 const 
  567                         { 
return conv(static_cast<unsigned long int>(0)); }
 
  569 #if !defined(NO_LONG_LONGS) 
  570         operator longlong()
 const 
  573                         { 
return conv(static_cast<longlong>(0)); }
 
  577         operator ulonglong()
 const 
  578                         { 
return conv(static_cast<ulonglong>(0)); }
 
  582         operator float()
 const 
  583                         { 
return conv(static_cast<float>(0)); }
 
  586         operator double()
 const 
  587                         { 
return conv(static_cast<double>(0)); }
 
  590         operator bool()
 const { 
return buffer_ ? atoi(c_str()) : 
false; }
 
  593         operator Date()
 const { 
return buffer_ ? 
Date(*
this) : Date(); }
 
  597                         { 
return buffer_ ? 
DateTime(*
this) : DateTime(); }
 
  600         operator Time()
 const { 
return buffer_ ? 
Time(*
this) : Time(); }
 
  605         template <
class T, 
class B>
 
  610         template <
class Type>
 
  611         Type do_conv(
const char* type_name)
 const 
  614                         std::stringstream buf;
 
  615                         buf.write(data(), static_cast<std::streamsize>(length()));
 
  616                         buf.imbue(std::locale::classic()); 
 
  628                                                 (
typeid(Type) != 
typeid(
float)) &&
 
  629                                                 (
typeid(Type) != 
typeid(
double))) {
 
  635                                         while (buf >> c && c == 
'0')  ;
 
  636                                         if (buf.eof() && c == 
'0') {
 
  641                         else if (buf.eof()) {
 
  645                         throw BadConversion(type_name, data(), 0, length());
 
  652         RefCountedBuffer buffer_;       
 
  654         friend class SQLTypeAdapter;
 
  657 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& o,
 
  661 #if !defined(MYSQLPP_NO_BINARY_OPERS) && !defined(DOXYGEN_IGNORE) 
  667 #define oprsw(opr, other, conv) \ 
  668         inline other operator opr (String x, other y) \ 
  669                         { return static_cast<conv>(x) opr y; } \ 
  670         inline other operator opr (other x, String y) \ 
  671                         { return x opr static_cast<conv>(y); } 
  673 #define operator_binary(other, conv) \ 
  674         oprsw(+, other, conv) \ 
  675         oprsw(-, other, conv) \ 
  676         oprsw(*, other, conv) \ 
  677         oprsw(/, other, conv) 
  679 #define operator_binary_int(other, conv) \ 
  680         operator_binary(other, conv) \ 
  681         oprsw(%, other, conv) \ 
  682         oprsw(&, other, conv) \ 
  683         oprsw(^, other, conv) \ 
  684         oprsw(|, other, conv) \ 
  685         oprsw(<<, other, conv) \ 
  686         oprsw(>>, other, conv) 
  689 #if defined(MYSQLPP_PLATFORM_VISUAL_CPP) 
  690 #       pragma warning(disable: 4244) 
  693 operator_binary(
float, 
double)
 
  694 operator_binary(
double, 
double)
 
  696 operator_binary_int(
char, 
long int)
 
  697 operator_binary_int(
int, 
long int)
 
  698 operator_binary_int(
short int, 
long int)
 
  699 operator_binary_int(
long int, 
long int)
 
  701 operator_binary_int(
unsigned char, 
unsigned long int)
 
  702 operator_binary_int(
unsigned int, 
unsigned long int)
 
  703 operator_binary_int(
unsigned short int, 
unsigned long int)
 
  704 operator_binary_int(
unsigned long int, 
unsigned long int)
 
  706 #if defined(MYSQLPP_PLATFORM_VISUAL_CPP) 
  707 #       pragma warning(default: 4244) 
  710 #if !defined(NO_LONG_LONGS) 
  711 operator_binary_int(longlong, longlong)
 
  712 operator_binary_int(ulonglong, ulonglong)
 
  713 #endif // !defined(NO_LONG_LONGS) 
  714 #endif // !defined(MYSQLPP_NO_BINARY_OPERS) && !defined(DOXYGEN_IGNORE) 
  717 #if !defined(DOXYGEN_IGNORE) 
  726 template <> MYSQLPP_EXPORT 
bool String::conv(
bool) 
const;
 
  740 template <> MYSQLPP_EXPORT String 
String::conv(String) 
const;
 
  743 template <> MYSQLPP_EXPORT std::string 
String::conv(std::string) 
const;
 
  750 template <> MYSQLPP_EXPORT Date 
String::conv(Date) 
const;
 
  757 template <> MYSQLPP_EXPORT DateTime 
String::conv(DateTime) 
const;
 
  764 template <> MYSQLPP_EXPORT Time 
String::conv(Time) 
const;
 
  766 #endif // !defined(DOXYGEN_IGNORE) 
  770 #endif // !defined(MYSQLPP_MYSTRING_H) 
const_iterator iterator
Same as const_iterator because the data cannot be changed. 
Definition: mystring.h:154
Declares classes that implement SQL "null" semantics within C++'s type system. 
Type conv(Type) const 
Template for converting the column data to most any numeric data type. 
Definition: mystring.h:298
size_t size_type
Type of "size" integers. 
Definition: mystring.h:147
void assign(const char *str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false)
Assign a C string to this object. 
Definition: mystring.h:269
Holds SQL data in string form plus type information for use in converting the string to compatible C+...
Definition: sql_buffer.h:41
C++ form of SQL's TIME type. 
Definition: datetime.h:347
C++ form of SQL's DATETIME type. 
Definition: datetime.h:48
Declares classes to add SQL-compatible date and time types to C++'s type system. 
SQL field type information. 
Definition: type_info.h:148
const char value_type
Type of the data stored in this object, when it is not equal to SQL null. 
Definition: mystring.h:144
Null< T, B > conv(Null< T, B >) const 
Overload of conv() for types wrapped with Null<> 
Definition: mystring.h:318
static const enum_field_types string_type
The internal constant we use for our string type. 
Definition: type_info.h:270
String(const char *str, size_type len, mysql_type_info type=mysql_type_info::string_type, bool is_null=false)
Full constructor. 
Definition: mystring.h:196
String(const String &other)
Copy ctor. 
Definition: mystring.h:179
The type of the global mysqlpp::null object. 
Definition: null.h:49
Declares the MySQL++-specific exception classes. 
const char * c_str() const 
Return a const pointer to the string data. 
Definition: mystring.h:288
mysql_type_info type() const 
Get this object's current MySQL type. 
Definition: mystring.h:448
void strip_leading_blanks(std::string &s) const 
Returns a copy of our internal string without leading blanks. 
Definition: mystring.h:421
C++ form of SQL's DATE type. 
Definition: datetime.h:225
const_iterator begin() const 
Return iterator pointing to the first character of the string. 
Definition: mystring.h:285
String(const std::string &str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false)
C++ string version of full ctor. 
Definition: mystring.h:210
const char * const_iterator
Type of iterators. 
Definition: mystring.h:150
bool empty() const 
Returns true if size() == 0. 
Definition: mystring.h:376
size_type max_size() const 
Return the maximum number of characters in the string. 
Definition: mystring.h:407
String()
Default constructor. 
Definition: mystring.h:167
This file includes top-level definitions for use both internal to the library, and outside it...
void assign(const std::string &str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false)
Assign a C++ string to this object. 
Definition: mystring.h:255
~String()
Destroy string. 
Definition: mystring.h:234
Declares the SQLBuffer class. 
Class for holding data from a SQL column with the NULL attribute. 
Definition: null.h:170
void assign(const char *str, size_type len, mysql_type_info type=mysql_type_info::string_type, bool is_null=false)
Assign raw data to this object. 
Definition: mystring.h:242
size_type size() const 
Return number of bytes in string. 
Definition: mystring.h:417
A std::string work-alike that can convert itself from SQL text data formats to C++ data types...
Definition: mystring.h:139
String(const char *str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false)
Null-terminated C string version of full ctor. 
Definition: mystring.h:225