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

Feature Request: Return number of rows affected by update/delete queries. #120

Open
crazyjaco opened this issue Oct 22, 2018 · 4 comments
Open

Comments

@crazyjaco
Copy link

Hello.

I recently used WP-CLI to run some SQL queries.
After they run, I only got a success or failure message.
If it was a success, I did not receive any feedback about how many rows were affected.
Running the query directly in MySQL, it lets me know how many rows were affected.

It was would nice to have that metric returned or optionally returned.

Not sure if that would be part of the normal output or added as a new switch.

Thank you for your time.

@schlessera
Copy link
Member

Yes, that makes sense and I think it would be a worthwhile improvement.

Would you be up for creating a pull request for this, @crazyjaco ?

@crazyjaco
Copy link
Author

I would be interested in that, but I don't have a lot of time to spare in the next week or two. I can look at it after that I think. Would that be alright?

@schlessera
Copy link
Member

@crazyjaco Yes, sure. Feel free to ping me when you started to work on it and get stuck!

@lkraav
Copy link

lkraav commented Feb 21, 2022

I could've used this today in connection with a large DELETE operation https://stackoverflow.com/questions/1318972/deleting-millions-of-rows-in-mysql to do something like

rows_affected = 0
do {
 rows_affected = do_query(
   "DELETE FROM messages WHERE created < DATE_SUB(NOW(),INTERVAL 3 MONTH)
   LIMIT 10000"
 )
} while rows_affected > 0

But can't get "rows affected" from wp db query.

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

No branches or pull requests

5 participants