adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
531 stars 128 forks source link

Get the result after executing the UPDATE SQL request #325

Open AlexanderZhirov opened 2 years ago

AlexanderZhirov commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

You want that "updated rows" thing?

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

adamdruppe commented 2 years ago

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