Problem getting the MySQL Connector to take a variable

I've got the MySQL connector working in my project, but just writing dummy data.

I've got a clunky way to get the values from a few float values from temp sensors, but I'm able to get a string out the end that is what the SQL line should be, but when I put that variable in the MySQL command, it fails with the message

_2014_08_14.ino: In function 'void LogData()':
_2014_08_14:433: error: no matching function for call to 'Connector::cmd_query(String&)'
C:\Users\Matt\Documents\Arduino\libraries\mysql/mysql.h:121: note: candidates are: boolean Connector::cmd_query(const char*)

This works
my_conn.cmd_query("INSERT INTO brew master.fermenterlog VALUES ('Log Data', NULL, NULL, NULL, NULL, NULL)");

But this doesn't
my_conn.cmd_query(INSERT_SQL);

Here's how I'm building that INSERT_SQL string. Any help on how to better do that would be great.

void LogData() {
  FermenterID = String("MattConical");
  CurrentMode = String("Cooling");

  Serial.print("SetTemp ");
  Serial.println(SetTemp);
  Serial.print("CurrentTempBeer ");
  Serial.println(CurrentTempBeer);

  //Convert Current Beer Temp to 2 decimal string
  CurrentTempBeerInt = CurrentTempBeer * 100;
  char CurrentTempBeerStringRaw[5];
  String str;
  str=String(CurrentTempBeerInt);
  str.toCharArray(CurrentTempBeerStringRaw,5);
  CurrentTempBeerString = String(CurrentTempBeerStringRaw);
  char CurrentTempBeerStringChar1 = CurrentTempBeerString.charAt(0);
  char CurrentTempBeerStringChar2 = CurrentTempBeerString.charAt(1);
  char CurrentTempBeerStringChar3 = CurrentTempBeerString.charAt(2);
  char CurrentTempBeerStringChar4 = CurrentTempBeerString.charAt(3);
  CurrentTempBeerString = String("");
  CurrentTempBeerString += CurrentTempBeerStringChar1;
  CurrentTempBeerString += CurrentTempBeerStringChar2;
  CurrentTempBeerString += ".";
  CurrentTempBeerString += CurrentTempBeerStringChar3;
  CurrentTempBeerString += CurrentTempBeerStringChar4;

  //Convert Current Set Temp to 2 decimal string
  CurrentSetTempInt = SetTemp * 100;
  char SetTempStringRaw[5];
  String str2;
  str2=String(CurrentSetTempInt);
  str2.toCharArray(SetTempStringRaw,5);
  SetTempString = String(SetTempStringRaw);
  char SetTempStringChar1 = SetTempString.charAt(0);
  char SetTempStringChar2 = SetTempString.charAt(1);
  char SetTempStringChar3 = SetTempString.charAt(2);
  char SetTempStringChar4 = SetTempString.charAt(3);
  SetTempString = String("");
  SetTempString += SetTempStringChar1;
  SetTempString += SetTempStringChar2;
  SetTempString += ".";
  SetTempString += SetTempStringChar3;
  SetTempString += SetTempStringChar4;

  INSERT_SQL = String("INSERT INTO `brew master`.fermenterlog VALUES ('");
  INSERT_SQL += FermenterID;
  INSERT_SQL += "',NULL,'";
  INSERT_SQL += CurrentMode;
  INSERT_SQL += "','";
  INSERT_SQL += CurrentTempBeerString;
  INSERT_SQL += "','";
  INSERT_SQL += SetTempString;
  INSERT_SQL += "','";
  INSERT_SQL += num_fails;
  INSERT_SQL += "')";
  
  Serial.println(INSERT_SQL);  // prints Full SQL String
//  my_conn.cmd_query("INSERT INTO `brew master`.fermenterlog VALUES ('Log Data', NULL, NULL, NULL, NULL, NULL)");
  my_conn.cmd_query(INSERT_SQL);
}

This part of the error message

Connector::cmd_query(const char*)

is telling you that the function is expecting a null-terminated C string, not a String. You should avoid the use of String anyway. It doesn't work well on Arduino.

Pete

How would I got about constructing that SQL statement, gathering vales from the different temp sensors, without using a string?

Use a string with a small s rather than a String with a big S.

...R

Robin2:
Use a string with a small s rather than a String with a big S.

...R

And use sprintf() to populate it with the values in the variables.

Robin2:
Use a string with a small s rather than a String with a big S.

...R

Not being super familiar with Arduino code yet, simply turning String into string causes error:
_2014_08_14:419: error: 'string' was not declared in this scope

When I use

my_conn.cmd_query("INSERT INTO `brew master`.fermenterlog VALUES ('Log Data', NULL, NULL, NULL, NULL, NULL)");

it works just fine, but I haven't found a way to get the values from the different temp sensors and other variables to replace the NULLs. What I've written is the result of a ton of searching, but not finding whole lot of examples. Any ideas?

I'm not recommending you use String, because it can be a memory hog, but you can convert from String to const char * with c_str:

my_conn.cmd_query(INSERT_SQL.c_str ());

BTW, as a style thing, constants are normally in all caps, and variables are not in all caps.

mpcluever:
it works just fine, but I haven't found a way to get the values from the different temp sensors and other variables to replace the NULLs. What I've written is the result of a ton of searching, but not finding whole lot of examples. Any ideas?

Lookup sprintf, as PaulS said.