Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

multiple results from a single submission to db #45

Open
mispp opened this issue Aug 14, 2018 · 2 comments
Open

multiple results from a single submission to db #45

mispp opened this issue Aug 14, 2018 · 2 comments

Comments

@mispp
Copy link
Owner

mispp commented Aug 14, 2018

in mssql management studio, several queries can be executed and several result sets can be displayed at once.

to be considered if this can be implemented

examples:

example1 multiple results

example2 multiple results

@asw-dev
Copy link
Collaborator

asw-dev commented Aug 28, 2018

for mysql, and mssql this is done with query.nextResult()

QSqlQuery query(db);
QString out = "";
if (!query.exec("select 42 as a; select 1 as b;"))
{
    out = "query.exec fail\n" + query.lastError().text();
    ui->plainTextEdit->setPlainText(out);
    return;
}

out = "ok";
while (query.next())
{
    out += "\n" + query.record().fieldName(0) + "=" + QString::number(query.record().value(0).toInt());
}

while (query.nextResult())
{
    out += "\n--- nextResult ---";
    while (query.next())
    {
        out += "\n" + query.record().fieldName(0) + "=" + QString::number(query.record().value(0).toInt());
    }
}

out += "\ndone";
ui->plainTextEdit->setPlainText(out.trimmed());

but does not work for other databases

  • sqlite: error
  • postgres executes both, returns last result

looks like postgres may be adding support in the future but for now you would have to parse the sql, extract the statements, and run them one at a time.

@mispp
Copy link
Owner Author

mispp commented Aug 28, 2018

but for now you would have to parse the sql, extract the statements, and run them one at a time.

nope. :)
i dont think this would be a good idea since we even now dont support basic querying, to much work for something that will be solved by postgres soon-ish. in this case, just take whatever is returned (i.e. last statement).

multiple result sets should be taken into account for further development though.

thanks for testing it all out 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants