Results 1 to 8 of 8

Thread: join is not working

  1. #1
    Join Date
    Jan 2016
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default join is not working

    hi could anyone help me? I want join two tables into one, this code is working on my friends qt+db2 but on my qt+ingres isn't.

    Qt Code:
    1. void FouDialog::on_pushButton_4_clicked()
    2. {
    3. int num_rows, r, c;
    4. QSqlQuery q(db);
    5.  
    6. if(!q.exec("SELECT count(id_wizyty) as num_rows FROM wizyta")) qDebug() << q.lastError().text();
    7. q.first();
    8. num_rows = q.value(0).toInt();
    9.  
    10. ui->tableWidget->setRowCount(num_rows);
    11.  
    12. //if(!q.exec("SELECT * FROM wizyta ")) qDebug() << q.lastError().text();
    13. if(!q.exec("SELECT id_wizyty, data, w.id_pacjenta, id_lekarza, p.imie as Imie_Pacjenta ,p.nazwisko as Nazwisko_Pacjenta FROM wizyta w JOIN pacjent p ON w.id_pacjenta = p.id_pacjenta")) qDebug() << q.lastError().text();
    14. for(r = 0, q.first(); q.isValid(); q.next(), ++r){
    15. for(c = 0; c < 6; ++c){
    16. ui->tableWidget->setItem(r,c, new QTableWidgetItem(q.value(c).toString()));
    17. }
    18. }
    19. }
    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: join is not working

    What do you mean "is not working" ?

  3. #3
    Join Date
    Jan 2016
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: join is not working

    columns from pacjent tables are not added into wizyta table

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: join is not working

    columns from pacjent tables are not added into wizyta table
    Nothing in your code tries to add columns (or rows) to any database table.


    Does the query exec() call return true? Does your lastError() report anything?

    Does
    Qt Code:
    1. SELECT id_wizyty, data, w.id_pacjenta, id_lekarza, p.imie as Imie_Pacjenta ,p.nazwisko as Nazwisko_Pacjenta
    2. FROM wizyta w
    3. JOIN pacjent p ON w.id_pacjenta = p.id_pacjenta
    To copy to clipboard, switch view to plain text mode 
    Execute in isql and return what you expect?

    Does the execution enter your for loop? Is there a reason you did not use the more idiomatic:
    Qt Code:
    1. while (q.next()) {
    2. // do stuff
    3. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2016
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: join is not working

    Quote Originally Posted by ChrisW67 View Post
    Nothing in your code tries to add columns (or rows) to any database table.


    Does the query exec() call return true? Does your lastError() report anything?

    Does
    Qt Code:
    1. SELECT id_wizyty, data, w.id_pacjenta, id_lekarza, p.imie as Imie_Pacjenta ,p.nazwisko as Nazwisko_Pacjenta
    2. FROM wizyta w
    3. JOIN pacjent p ON w.id_pacjenta = p.id_pacjenta
    To copy to clipboard, switch view to plain text mode 
    Execute in isql and return what you expect?
    0 errors, in visual SQL it returns what it should

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: join is not working

    Has your program successfully open()ed the database?
    Does the code you have shown us actually get executed?
    Does the query returning the count() work?

  7. #7
    Join Date
    Jan 2016
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: join is not working

    Database if opened successfully, I can add, edit, remove and see all records from my database in qt app, I just can't use join to see records from two tables in one.

  8. #8
    Join Date
    Jan 2016
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: join is not working

    ok I fixed it with ui->tableWidget->setColumnCount(6); and now it is working as it should, thanks for all your help, regards!

Similar Threads

  1. Qwt Join x and y axis
    By sonulohani in forum Qwt
    Replies: 0
    Last Post: 18th July 2012, 09:51
  2. Join the QtBrasil
    By ross in forum General Discussion
    Replies: 0
    Last Post: 9th August 2010, 19:04
  3. QSqlRelationalTableModel & Left Join
    By mhbeyle in forum Qt Programming
    Replies: 3
    Last Post: 21st December 2009, 13:40
  4. Thread does not join
    By AlphaWolf in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2009, 09:09
  5. QDataTable + join
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2006, 13:56

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.