- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
static void mysql_update_values(string sensorname, string sensorvalue)
{
MySql.Data.MySqlClient.MySqlConnection conn;
MySqlCommand cmd = new MySqlCommand();
MySqlDataReader mysqlr;
string myConnectionString;
myConnectionString = "server=" + mysql_server + ";uid=" + mysql_login + ";pwd=" + mysql_password + ";database=" + mysql_db + ";";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
if (conn.State == System.Data.ConnectionState.Open)
{
cmd.CommandText = "SELECT * FROM sensordata WHERE sensorname = '" + sensorname + "'";
log("DEBUG: mysqlcommand: " + cmd.CommandText);
cmd.Connection = conn;
cmd.Prepare();
mysqlr = cmd.ExecuteReader();
if (mysqlr.HasRows)
{
mysqlr.Close();
cmd.CommandText = "DELETE FROM sensordata WHERE sensorname = '" + sensorname + "'";
log("DEBUG: mysqlcommand: " + cmd.CommandText);
cmd.Connection = conn;
cmd.Prepare();
cmd.ExecuteNonQuery();
System.DateTime.Now.ToString() + "' WHERE sensorname = '" + sensorname + "'";
cmd.CommandText = "INSERT INTO sensordata VALUES('" + sensorname + "','" + sensorvalue + "','" + System.DateTime.Now.ToString() + "')";
log("DEBUG: mysqlcommand: " + cmd.CommandText);
cmd.Connection = conn;
cmd.Prepare();
cmd.ExecuteNonQuery();
}
else
{
mysqlr.Close();
cmd.CommandText = "INSERT INTO sensordata VALUES('" + sensorname + "','" + sensorvalue + "','" + System.DateTime.Now.ToString() + "')";
log("DEBUG: mysqlcommand: " + cmd.CommandText);
cmd.Connection = conn;
cmd.Prepare();
cmd.ExecuteNonQuery();
}
}
log("mysql_update_values(" + sensorname + "," + sensorvalue + ")");
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
log_e(ex.Message + ex.StackTrace);
}
}
Комментарии (0) RSS
Добавить комментарий