hunt-database icon indicating copy to clipboard operation
hunt-database copied to clipboard

Return value of statment.execute is always 2 in mysql.

Open vinoakash opened this issue 5 years ago • 1 comments

Hi All,

The below code always returns value 2(result = stmt.execute()) but the data in the tables are getting inserted/ updated perfectly, so shoudnt the below code return the value 0 instead of 2. please correct me if my understanding is wrong.

Code

 auto con = new GetConnections();
ini result;
 Statement stmt = con.db.prepare("INSERT INTO test (Hostname,Location,Rack,Updated)
                                  VALUES(:Hostname,:Location,:Location,:Updated)
                                  ON DUPLICATE KEY UPDATE
                                  Location = IF(Location != VALUES(Location), VALUES(Location), :Location),
                                  Rack = IF(Rack != VALUES(Rack), VALUES(Rack), :Rack),
                                  Updated = :Updated");
 foreach(i,ref h,ref l,ref r; lockstep(data["Hostname"][], data["Location"][], data["Rack"][])) {
    stmt.setParameter("Hostname", data["Hostname"][i]);
    stmt.setParameter("Location", data["Location"][i]);
    stmt.setParameter("Rack", data["Rack"][i]);
    stmt.setParameter("Updated", Clock.currTime().toISOExtString()[0..19]);
    result =  stmt.execute();
 }
 con.db.close();

vinoakash avatar Nov 15 '20 08:11 vinoakash

The execcute() returns the affected rows count, see here.

Heromyth avatar Nov 16 '20 06:11 Heromyth