Errors in overloaded "<<" operator

Markus Gerwinski markus@gerwinski.de
Mon Jun 9 11:25:00 GMT 2003


Hi folks,

I'm trying to port the mysql++ API to MinGW, and I found I had to change some
stuff in the sources to do so. I'm stuck at a point now where the "<<" operator
is overloaded for a database query. "make" gives me the following error messages
here:

  In file included from c:/mingw/include/c++/3.2/backward/strstream:51,
		   from c:/mingw/include/c++/3.2/backward/strstream.h:33,
		   from sql_query1.hh:4,
		   from manip1.hh:12,
		   from manip2.hh:2,
		   from manip3.hh:2,
		   from manip.cc:2:
  c:/mingw/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
  manip.cc: In function `SQLQuery& operator<<(SQLQuery&, const 
     mysql_ColData<std::string>&)':
  manip.cc:120: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<const_string>&)'
  manip.cc:120:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:120: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<std::string>&)'
  manip.cc:120:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:122: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<const_string>&)'
  manip.cc:122:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:122: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<std::string>&)'
  manip.cc:122:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:125: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<const_string>&)'
  manip.cc:125:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:125: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<std::string>&)'
  manip.cc:125:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc: In function `SQLQuery& operator<<(SQLQuery&, const 
     mysql_ColData<const_string>&)':
  manip.cc:139: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<const_string>&)'
  manip.cc:139:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:139: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<std::string>&)'
  manip.cc:139:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:141: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<const_string>&)'
  manip.cc:141:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:141: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<std::string>&)'
  manip.cc:141:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:144: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<const_string>&)'
  manip.cc:144:   because worst conversion for the former is better than worst 
     conversion for the latter
  manip.cc:144: choosing `std::basic_ostream<char, _Traits>& 
     std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with 
     _Traits = std::char_traits<char>]' over `SQLQuery& operator<<(SQLQuery&, 
     const mysql_ColData<std::string>&)'
  manip.cc:144:   because worst conversion for the former is better than worst 
     conversion for the latter
  make[3]: *** [manip.lo] Error 1
  make[2]: *** [all] Error 2
  make[1]: *** [all-recursive] Error 1
  make: *** [all] Error 2

The source it complains about is in the attachment.

Can anyone help me with an idea how to fix that?

Thanks,

  Markus
-------------- next part --------------

#include "manip3.hh"

// quote manipulator

bool dont_quote_auto=false;

SQLQueryParms& operator << (quote_type2 p, SQLString &in) {
  if (in.is_string) {
    if (in.dont_escape) {
      SQLString in2 = "'" + in + "'";
      in2.processed = true;
      return *p.qparms << in2;
    } else {
      char* s = new char[in.size()*2+1];
      mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
      SQLString in2 = SQLString("'") + s + "'";
      in2.processed = true;
      *p.qparms << in2;
      delete[] s;
      return *p.qparms;
    }
  } else {
    in.processed = true;
    return *p.qparms << in;
  }
}

template <>
ostream& operator << (quote_type1 o, const string &in) {
  char* s = new char[in.size()*2+1];
  mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
  *o.ostr << "'" << s << "'";
  delete[] s;
  return *o.ostr;
}

template <>
ostream& operator << (quote_type1 o, const char* const &in) {
  unsigned int size;
  for (size=0; in[size]; size++);
  char* s = new char[size*2+1];
  mysql_escape_string(s, const_cast<char *>(in), size);
  *o.ostr << "'" << s << "'";
  delete[] s; 
  return *o.ostr;
}

template <class Str>
inline ostream& _manip (quote_type1 o, const mysql_ColData<Str>& in) {
  if (in.escape_q()) {
    char *s = new char[in.size()*2+1];
    mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
    if (in.quote_q())
      *o.ostr << "'" << s << "'";
    else
      *o.ostr << s;
    delete[] s;
  } else if (in.quote_q()) {
    *o.ostr << "'" << in << "'";
  } else {
    *o.ostr << in;
  }
  return *o.ostr;
}

template <>
ostream& operator << (quote_type1 o, const mysql_ColData<string>& in) {
  return _manip(o,in);
}

template <>
ostream& operator << (quote_type1 o, const mysql_ColData<const_string>& in) {
  return _manip(o,in);
}

ostream& operator << (ostream& o, const mysql_ColData<string>& in) {
	if (dont_quote_auto || (o.rdbuf() == cout.rdbuf()) || (o.rdbuf() == cerr.rdbuf())) return o << in.get_string();
  if (in.escape_q()) {
    char *s = new char[in.size()*2+1];
    mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
    if (in.quote_q())
      o << "'" << s << "'";
    else
      o << s;
    delete[] s;
  } else if (in.quote_q()) {
    o << "'" << in.get_string() << "'";
  } else {
    o << in.get_string();
  }
  return o;
}


ostream& operator << (ostream& o, const mysql_ColData<const_string>& in) {
	if (dont_quote_auto || (o.rdbuf() == cout.rdbuf()) || (o.rdbuf() == cerr.rdbuf())) return o << in.get_string();
  if (in.escape_q()) {
    char *s = new char[in.size()*2+1];
    mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
    if (in.quote_q())
      o << "'" << s << "'";
    else
      o << s;
    delete[] s;
  } else if (in.quote_q()) {
    o << "'" << in.get_string() << "'";
  } else {
    o << in.get_string();
  }
  return o;
}

SQLQuery& operator << (SQLQuery& o, const mysql_ColData<string>& in) {
	if (dont_quote_auto) {o << in.get_string(); return o;}
  if (in.escape_q()) {
    char *s = new char[in.size()*2+1];
    mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
    if (in.quote_q())
      o << "'" << s << "'";
    else
      o << s;
    delete[] s;
  } else if (in.quote_q()) {
    o << "'" << in.get_string() << "'";
  } else {
    o << in.get_string();
  }
  return o;
}


SQLQuery& operator << (SQLQuery& o, const mysql_ColData<const_string>& in) {
	if (dont_quote_auto) {o << in.get_string(); return o;}
  if (in.escape_q()) {
    char *s = new char[in.size()*2+1];
    mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
    if (in.quote_q())
      o << "'" << s << "'";
    else
      o << s;
    delete[] s;
  } else if (in.quote_q()) {
    o << "'" << in.get_string() << "'";
  } else {
    o << in.get_string();
  }
  return o;
}

// quote only manipulator

SQLQueryParms & operator << (quote_only_type2 p, SQLString &in) {
  if (in.is_string) {
    SQLString in2 = "'" + in + "'";
    in2.processed = true;
    return *p.qparms << in2;
  } else {
    in.processed = true;
    return *p.qparms << in;
  }
}

template <>
ostream& operator << (quote_only_type1 o, const mysql_ColData<string>& in) {
  if (in.quote_q()) {
    *o.ostr << "'" << in << "'";
  } else {
    *o.ostr << in;
  }
  return *o.ostr;
}

template <>
ostream& operator << (quote_only_type1 o, const mysql_ColData<const_string>& in) {
  if (in.quote_q()) {
    *o.ostr << "'" << in << "'";
  } else {
    *o.ostr << in;
  }
  return *o.ostr;
}

// quote double only manipulator

SQLQueryParms & operator << (quote_double_only_type2 p, SQLString &in) {
  if (in.is_string) {
    SQLString in2 = "\"" + in + "\"";
    in2.processed = true;
    return *p.qparms << in2;
  } else {
    in.processed = true;
    return *p.qparms << in;
  }
}


template <>
ostream& operator << (quote_double_only_type1 o, const mysql_ColData<string>& in) {
  if (in.quote_q()) {
    *o.ostr << "'" << in << "'";
  } else {
    *o.ostr << in;
  }
  return *o.ostr;
}

template <>
ostream& operator << (quote_double_only_type1 o, const mysql_ColData<const_string>& in) {
  if (in.quote_q()) {
    *o.ostr << "'" << in << "'";
  } else {
    *o.ostr << in;
  }
  return *o.ostr;
}

// escape manipulator

SQLQueryParms & operator << (escape_type2 p, SQLString &in) {
  if (in.is_string) {
    if (in.dont_escape) {
      in.processed = true;
      return *p.qparms << in;
    } else {
      char* s = new char[in.size()*2+1];
      mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
      SQLString in2 = s;
      in2.processed = true;
      *p.qparms << in2;
      delete[] s;
      return *p.qparms;
    }
  } else {
    in.processed = true;
    return *p.qparms << in;
  }
}

template <>
ostream& operator << (escape_type1 o, const string &in) {
  char* s = new char[in.size()*2+1];
  mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size());
  *o.ostr << s;
  delete[] s;
  return *o.ostr;
}

template <>
ostream& operator << (escape_type1 o, const char* const &in) {
  unsigned int size;
  for (size=0; in[size]; size++);
  char* s = new char[size*2+1];
  mysql_escape_string(s, const_cast<char *>(in), size);
  *o.ostr << s;
  delete[] s; 
  return *o.ostr;
}


template <class Str>
inline ostream& _manip (escape_type1 o, const mysql_ColData<Str>& in) {
  if (in.escape_q()) {
    char *s = new char[in.size()*2+1];
    mysql_escape_string(s, const_cast<char *>(in.c_str()), in.size() );
    delete[] s;
  } else {
    *o.ostr << in;
  }
  return *o.ostr;
}

template <>
ostream& operator << (escape_type1 o, const mysql_ColData<string>& in) {
  return _manip(o,in);
}

template <>
ostream& operator << (escape_type1 o, const mysql_ColData<const_string>& in) {
  return _manip(o,in);
}






More information about the Gcc-help mailing list