Exemple #1
0
// methods for formatting
// ---------------------------------------------
std::string MysqlDatabase::vprepare(const char *format, va_list args)
{
  std::string strFormat = format;
  std::string strResult = "";
  char *p;
  size_t pos;

  //  %q is the sqlite format string for %s.
  //  Any bad character, like "'", will be replaced with a proper one
  pos = 0;
  while ( (pos = strFormat.find("%s", pos)) != std::string::npos )
    strFormat.replace(pos++, 2, "%q");

  p = mysql_vmprintf(strFormat.c_str(), args);
  if ( p )
  {
    strResult = p;
    free(p);

    //  RAND() is the mysql form of RANDOM()
    pos = 0;
    while ( (pos = strResult.find("RANDOM()", pos)) != std::string::npos )
    {
      strResult.replace(pos++, 8, "RAND()");
      pos += 6;
    }
  }

  return strResult;
}
Exemple #2
0
// methods for formatting
// ---------------------------------------------
std::string MysqlDatabase::vprepare(const char *format, va_list args)
{
  std::string strFormat = format;
  std::string strResult = "";
  size_t pos;

  //  %q is the sqlite format string for %s.
  //  Any bad character, like "'", will be replaced with a proper one
  pos = 0;
  while ( (pos = strFormat.find("%s", pos)) != std::string::npos )
    strFormat.replace(pos++, 2, "%q");

  strResult = mysql_vmprintf(strFormat.c_str(), args);
  //  RAND() is the mysql form of RANDOM()
  pos = 0;
  while ( (pos = strResult.find("RANDOM()", pos)) != std::string::npos )
  {
    strResult.replace(pos++, 8, "RAND()");
    pos += 6;
  }

  // Remove COLLATE NOCASE the SQLite case insensitive collation.
  // In MySQL all tables are defined with case insensitive collation utf8_general_ci
  pos = 0;
  while ((pos = strResult.find(" COLLATE NOCASE", pos)) != std::string::npos)
    strResult.erase(pos++, 15);

  return strResult;
}