arsd icon indicating copy to clipboard operation
arsd copied to clipboard

Get the result after executing the UPDATE SQL request

Open AlexanderZhirov opened this issue 3 years ago • 3 comments

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?

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

AlexanderZhirov avatar May 08 '22 14:05 AlexanderZhirov

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.

adamdruppe avatar May 08 '22 14:05 adamdruppe

You want that "updated rows" thing?

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

AlexanderZhirov avatar May 08 '22 15:05 AlexanderZhirov

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

adamdruppe avatar May 08 '22 19:05 adamdruppe