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

Logging always reports rows: 0 for inserts #1570

Closed
jblachly opened this issue Dec 4, 2021 · 2 comments · Fixed by #1754
Closed

Logging always reports rows: 0 for inserts #1570

jblachly opened this issue Dec 4, 2021 · 2 comments · Fixed by #1754

Comments

@jblachly
Copy link

jblachly commented Dec 4, 2021

This affects both Postgresql (what I am seeing) as well as Mysql (which you can see from another user's logs in in e.g. #1366 ). It is likely affecting all backends?

An example:

INSERT INTO projects (id, …; rows: 0, elapsed: 4.623ms

Relevant code is here:

let rows = self.rows;
log::logger().log(
&log::Record::builder()
.args(format_args!(
"{}; rows: {}, elapsed: {:.3?}{}",
summary, rows, elapsed, sql
))
.level(lvl)
.module_path_static(Some("sqlx::query"))
.target("sqlx::query")
.build(),

But I am not sure yet how it is called.

Potentially of interest, psql reports the following on insertion:

db_name=*> insert into projects (name, owner_id) values ('Test transaction', '00000000-0000-0000-0000-000000000000');
INSERT 0 1

(i.e. is it possible sqlx reads the leading zero?)

@abonander
Copy link
Collaborator

This doesn't seem to be a bug so much as a misunderstanding of the intent here. It appears intentional that QueryLogger::rows is only incremented when a statement returns a result row. It's not necessarily meant to show how many rows were affected, just how many were received back from the database.

We could log a separate field showing the number of rows affected by the statement as reported by the database, but I don't think there's a bug here.

@mehcode wrote this part of the crate so I'd like him to chime in.

cc @david-mcgillicuddy-moixa since this concerns your PR.

@david-mcgillicuddy-moixa
Copy link
Contributor

Ah, I see, that certainly makes that bit of the code make a lot more sense and I never tested with selects, only inserts. I'll update that message to have two fields, "rows returned" and "rows affected".

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

Successfully merging a pull request may close this issue.

3 participants