Skip to content

[PSQL] execute(false) into fetch() on a statement that returns no data leads to undefined behavior #1328

@GregTheMadMonk

Description

@GregTheMadMonk

I have a "generic" (in terms of queries it accepts) function that does something like

// std::string query = "UPDATE ... (without returning anything)" in this particular case
soci::row row;
soci::statement st = (sql.prepare << query, soci::into(row));
st.execute(false);
while (st.fetch()) {
    // do something with the row - the code is "generic" and should work with queries that return data too
}

in this case, I get a lot of iterations in the while loop which I think are due to multiple variables in the PSQL statement backend being in an undefined state. I stepped through the execution in a debugger and found that:

Documentation does not suggest the return value of execute() to be checked before following it up with fetch(), so I suppose it's not intended behavior and fetch() in my case should've returned false immediately?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions