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

Get the result after executing the UPDATE SQL request #325

Open
AlexanderZhirov opened this issue May 8, 2022 · 3 comments
Open

Get the result after executing the UPDATE SQL request #325

AlexanderZhirov opened this issue May 8, 2022 · 3 comments

Comments

@AlexanderZhirov
Copy link

AlexanderZhirov commented May 8, 2022

I am making a request to update an entry in PostgreSQL. I would like to get the result to understand whether the request was executed or not.

auto result = db.query("update amts.t_client set ip = ? where id = ?", ip.idup, id);

How to pull the result of affected update rows from variable result?

изображение
изображение

@adamdruppe
Copy link
Owner

You want that "updated rows" thing? The C function is PQcmdTuples but indeed I never added that to my interface.

Just pushed something to master. It is a bit awkward to use but it is like:

       auto pg = new PostgreSql("dbname=test");
        auto res = cast(PostgresResult) pg.query("UPDATE employees set name = 'aas' where id = 1749411001000");
        assert(res !is null);
        import std.stdio;
        writeln(res.affectedRows);

Notice the cast so you can get to the new member.

I'll see about cleaning up the interface later.

@AlexanderZhirov
Copy link
Author

You want that "updated rows" thing?

Yes, I would like to get the result of the number of affected rows after the update.

@adamdruppe
Copy link
Owner

that function i don't think tells you which ones actually changed but rather which ones matched the where clause

but yeah it seems to work so if that master thing works let me know

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