title: How calculate the size of a MySQL statement (not the query results)
body: <p>I'm working on a tool that generates and runs SQL against a MySQL database. I'm trying to add the ability to limit the size of a insert statement based on a user-specified setting. I found some info about the <code>max_allowed_packet</code> setting, but I haven't found anything that explains how to calculate a packet's size. The MySQL docs say that "A communication packet is a single SQL statement sent to the MySQL server," but I don't understand how the size of the SQL statement is determined. </p>
  
  <p>I'm passing a SQL statement and some parameters to my driver:</p>
  
  <pre><code>cmd.CommandText= "INSERT INTO myTable VALUES(@int, @date, @text)";
  cmd.Parameters.AddWithValue("@int", 1);
  cmd.Parameters.AddWithValue("@date", DateTime.Now);
  cmd.Parameters.AddWithValue("@text", "how big is this???");
  cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>Is the size of the packet just the sum of the bytes used in the string representation of all the variables and the SQL statement? Or should I figure out the size of each parameter based on how much space they would take up in the database and sum that with the bytes used in the SQL string? Or something else? I'm not really sure how database drivers work, so maybe some context around that would be helpful, if you know anything about them.</p>