0

I have the following code:

QString req = QString( "dbo.create_bsk @sico = " ) + QString(current_sico.c_str()) + ", @dev_cod='" + local_ccy.c_str() +"'";
QSqlQuery query = db.exec(req);
std::cout << req.toStdString() << std::endl;

std::cout << query.isActive() << std::endl
          << query.isSelect() << std::endl;
if(query.next())
{
    current_bk = query.record().value("bk_cod").toString().toStdString();

    if(current_bk.compare("") != 0)
    {
        std::cout << current_sico << " ==> " << current_bk << std::endl;
    }
}
else
{
    std::cout << "no next" << std::endl;
}

and I got something like this at execution:

dbo.create_bsk @sico = 1300610792, @dev_cod='EUR'
1
0
no next

And I keep getting "no next" no matter how many times I execute it. Then I copy and paste

dbo.create_bsk @sico = 1300610792, @dev_cod='EUR'

into my favorite sql editor and execute it. It returns one cell ( one line/ one column ), column is named "bk_cod" and value is 'bk38'

Then I execute the program again and get:

dbo.create_bsk @sico = 1300610792, @dev_cod='EUR'
1
1
1300610792 ==> bk38

And from there I keep getting "1300610792 ==> bk38" no matter how many times I execute it.

Some context

the query create_bsk is not re-entrant, It performs updates so that the result 'bk38' which is an identifier is either:

  1. created
  2. retrieved
  3. '' (the empty string) is the cell value to tell that basket will be ignored and no id was generated

But It always returns a cell. So according to here QSqlQuery::next() should be "true".

And as shown above, no matter how many times I execute my program, it always returns "no next" as long as it has not been executed in sql editor, and then as soon as I execute it in my editor, no matter how many times I execute my program, it will always return the same 'bk_cod' as ID.

What am I missing ? The problem occurs in most cases but not all the time and I haven't been able to figure out any pattern.

4

1 回答 1

0

https://bugreports.qt-project.org/browse/QTBUG-34225#comment-218380

This is a problem with the driver I use for TDS.

CLOSED

于 2013-10-23T15:18:59.120 回答