Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PostgreSql Query wont show tables form DB
Forum Updated to NodeBB v4.3 + New Features

PostgreSql Query wont show tables form DB

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    You should also check the QSqlTableModel::lastError just in case.

    And maybe a silly question but are you sure that your PostgreSQL database contains the same content as your MySQL database ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    C 1 Reply Last reply
    2
    • SGaistS SGaist

      You should also check the QSqlTableModel::lastError just in case.

      And maybe a silly question but are you sure that your PostgreSQL database contains the same content as your MySQL database ?

      C Offline
      C Offline
      Csonytii
      wrote on last edited by Csonytii
      #5

      @SGaist

      Sorry for late answer. LastError dont report any problem either. In the Tables completely the same as the MySQL table scheme... If this application wasn't be used widely, i would not care about PostgreSQL .
      It is started to frustrate me that i spend days to configure sql databases in different configuration and they're mess with me indirectly...

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #6

        Then maybe something specific to PostgreSQL, are you using the default schema ?

        In doubt, this small blog article gives a nice overview of the PostgreSQL schema.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • C Csonytii

          Hello Everybody,
          I Have the following part of code where i set my connection:

           QSqlDatabase DataBaseSample=QSqlDatabase::addDatabase("QPSQL","Sample");
           void setSample(){
                   DataBaseSample.setDatabaseName("MyDbName");
                   DataBaseSample.setUserName("myuser");
                   DataBaseSample.setPassword("mypw");
                   DataBaseSample.setHostName("mysite.xy");
                   bool ok=DataBaseSample.open();
          }
          ...
          

          And after that i have the following code which is list of all the Tables from the given DB:

              QStringList Tableslist(int DBID){
                  QSqlDatabase Current=db->ReturnDataBase(DBID);
                  return Current.tables();
              }
          ...
              QSqlTableModel *model=MC.TableReturn(Choose);
              model->setTable(Tabletoshow);
              model->select();
              ui->tableView->setModel(model);
          ...
          

          i wanted to check with wireshark where i got wrong but Postgre is encrypt better than mysql.
          So code is working with MySql but not with PostgreSql what should i do?

          Thank you for your answer

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #7

          Can you show us the body of db->ReturnDataBase(DBID); and MC.TableReturn(Choose);?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          C 1 Reply Last reply
          0
          • VRoninV VRonin

            Can you show us the body of db->ReturnDataBase(DBID); and MC.TableReturn(Choose);?

            C Offline
            C Offline
            Csonytii
            wrote on last edited by
            #8

            @SGaist
            i have a schame named public. with DataGrip show both way,

            select * 
            from  public.Table
            --or simply Table
            

            @VRonin

            QSqlTableModel *TableReturn(int DBID){
            
                    QSqlTableModel *model = new QSqlTableModel(nullptr,db->ReturnDataBase(DBID));
                    qDebug()<<model->tableName();
                    return model;
                }
            
              QSqlDatabase ReturnDataBase(int DBID){
                     QSqlDatabase db;
                     if(DBID==0){
                           setmydb1();
                        db=QSqlDatabase::database("mydb0");
                        return db;
                     }else if (DBID==1) {
                            setmydb1();
                         db=QSqlDatabase::database("mydb1");
                         return db;
                     }
                    ...
                        return db;
            
                 }
            

            i dont know how efficient is this.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #9

              What does setmydb1 do ? It's called for both databases.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              C 2 Replies Last reply
              0
              • SGaistS SGaist

                What does setmydb1 do ? It's called for both databases.

                C Offline
                C Offline
                Csonytii
                wrote on last edited by Csonytii
                #10

                @SGaist

                setmydb1 is like SetSample with different cities, (i don't want to use real data if that is not a problem). And i know it is harder to help when i do stuff like this, so sorry about that
                EDIT1:I finally figured out... Sample is not equal sample... I named the DB as Sample and i wanted to return with sample
                EDIT2: now its list the tables, but not the content of it...
                EDIT3: for example model->setTable("\"City\""); does the trick

                Thank you for your answers!

                1 Reply Last reply
                0
                • SGaistS SGaist

                  What does setmydb1 do ? It's called for both databases.

                  C Offline
                  C Offline
                  Csonytii
                  wrote on last edited by Csonytii
                  #11
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    Are you sure you setup the database properly ?

                    I find it very strange that you have to add double quotes around the table name to be able to access its content.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    C 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Are you sure you setup the database properly ?

                      I find it very strange that you have to add double quotes around the table name to be able to access its content.

                      C Offline
                      C Offline
                      Csonytii
                      wrote on last edited by
                      #13

                      @SGaist
                      The Double quotes used by pgadmin 4 and DataGrip too. So probably the same as the `tablename` in the Mysql syntax but its obligatory in PostgreSQL

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        After verification, here you can find why double quotes should be used.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        C 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          After verification, here you can find why double quotes should be used.

                          C Offline
                          C Offline
                          Csonytii
                          wrote on last edited by
                          #15

                          @SGaist

                          Thanks For you Help

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved