Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vinoakash opened this issue Nov 15, 2020 · 1 comment
Open

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

vinoakash opened this issue Nov 15, 2020 · 1 comment

Comments

@vinoakash
Copy link

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();
@Heromyth
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants