Results 1 to 6 of 6

Thread: MS SQL QODBC Query Size -1

  1. #1
    Join Date
    Apr 2012
    Posts
    40
    Platforms
    Unix/X11 Windows

    Default MS SQL QODBC Query Size -1

    Hi, i have problem with MS SQL, after i open connection without error, all query i exec have size -1

    Qt Code:
    1. void MainWindow::on_pushButtonLogin_clicked()
    2. {
    3. QString nameServer = "192.168.3.201\\OPTIMA";
    4. QString dbName = "CDN_Test";
    5. QString dataBaseName = QString("DRIVER={SQL Server};SERVER=%1;DATABASE=%2;").arg(nameServer).arg(dbName);
    6.  
    7. db = QSqlDatabase::addDatabase("QODBC");
    8. db.setDatabaseName(dataBaseName);
    9. db.setUserName("<LOGIN>");
    10. db.setPassword("<PASSWORD>");
    11.  
    12. if (!db.open())
    13. QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
    14. }
    15.  
    16. void MainWindow::on_pushButtonGetUsers_clicked()
    17. {
    18. QSqlQuery query(db);
    19. query.exec("SELECT * FROM [CDN].[Kontrahenci]");
    20.  
    21. QMessageBox::critical(0, QObject::tr("Database Error"), query.lastError().text() ); //No error
    22. QMessageBox::critical(0, QObject::tr("Database Error"), QString::number( query.size() )); // -1
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MS SQL QODBC Query Size -1

    From QSqlQuery::size doc : Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or if the database does not support reporting information about query sizes.

  3. #3
    Join Date
    Apr 2012
    Posts
    40
    Platforms
    Unix/X11 Windows

    Default Re: MS SQL QODBC Query Size -1

    So how i can get result of my query ??

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MS SQL QODBC Query Size -1

    I do not understand what the problem is. Size () == - 1 does not mean no result of query.

  5. #5
    Join Date
    Apr 2012
    Posts
    40
    Platforms
    Unix/X11 Windows

    Default Re: MS SQL QODBC Query Size -1

    Sorry i think if Szie() is -1 then next() and value() will by not work. Thx for help.
    Is other way to check how meny record have query ???

    I do someting like that, it work's but is not good way.
    Qt Code:
    1. void MainWindow::on_pushButtonGetUsers_clicked()
    2. {
    3.  
    4.  
    5. QSqlQuery query(db);
    6. query.exec("SELECT Knt_Kod, Knt_Ulica, Knt_NrDomu, Knt_Miasto, Knt_KodPocztowy, Knt_Poczta, Knt_Pesel FROM CDN.Kontrahenci");
    7. query.next();
    8. if(!query.value(0).toString().isEmpty())
    9. {
    10. ui->tableWidget->setRowCount(1);
    11. addRecordToTable(&query, 0);
    12. query.next();
    13.  
    14. int row=2;
    15. while(!query.value(0).toString().isEmpty())
    16. {
    17. ui->tableWidget->setRowCount(row);
    18. addRecordToTable(&query, row-1);
    19. row++;
    20. query.next();
    21. }
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Pablik; 30th March 2017 at 08:25.

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MS SQL QODBC Query Size -1

    Shorter code :
    Qt Code:
    1. void MainWindow::on_pushButtonGetUsers_clicked()
    2. {
    3.  
    4.  
    5. QSqlQuery query(db);
    6. query.exec("SELECT Knt_Kod, Knt_Ulica, Knt_NrDomu, Knt_Miasto, Knt_KodPocztowy, Knt_Poczta, Knt_Pesel FROM CDN.Kontrahenci");
    7. int row=1;
    8. while(query.next())
    9. {
    10. ui->tableWidget->setRowCount(row);
    11. addRecordToTable(&query, row-1);
    12. row++;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    BTW : why not to use QTableWidget with QSqlQuryModel ?

Similar Threads

  1. Replies: 7
    Last Post: 16th April 2015, 17:11
  2. Replies: 2
    Last Post: 13th October 2014, 18:35
  3. SSL with QODBC ??!
    By codeman in forum Qt Programming
    Replies: 0
    Last Post: 21st September 2010, 09:01
  4. QODBC has feaure (Query Size)
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 18th September 2009, 03:29
  5. Query Size needed
    By baray98 in forum Qt Programming
    Replies: 5
    Last Post: 18th July 2009, 08:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.