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. QSqlQueryModel dont show any row
Qt 6.11 is out! See what's new in the release blog

QSqlQueryModel dont show any row

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.2k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi, sorry for my english in advance :)

    First i try the code below on sql developer and works fine:

    FECHA IS A ORACLE DATE TYPE

    @
    SELECT idgasto, concepto, monto, TO_CHAR(fecha, 'dd-MM-yyyy'), observaciones
    FROM GASTOS WHERE concepto='KEVIN'
    AND TO_DATE(fecha,'dd-MM-yyyy') >= TO_DATE('01-09-1988' ,'dd-MM-yyyy')
    AND TO_DATE(fecha,'dd-MM-yyyy') < TO_DATE('1-10-1988','dd-MM-yyyy')
    ORDER BY (fecha)
    @

    i get 1 row (the onlyone i had on this table):

    @
    IDGASTO CONCEPTO MONTO TO_CHAR(FECHA,'DD-MM-YYYY') OBSERVACIONES


    3 KEVIN 10000 12-09-1988 aaaaaaaaaaaaa
    @

    so when i try the code below in my model i get 0 rows

    @
    void BuscarGasto::on_pushButtonBuscar_clicked()
    {
    model->setQuery("SELECT idgasto, concepto, monto, TO_CHAR(fecha, 'dd-MM-yyyy'), observaciones "
    " FROM GASTOS WHERE concepto='KEVIN' "
    " AND TO_DATE(fecha,'dd-MM-yyyy') >= TO_DATE('01-09-1988' ,'dd-MM-yyyy') "
    " AND TO_DATE(fecha,'dd-MM-yyyy') < TO_DATE('1-10-1988','dd-MM-yyyy') "
    " ORDER BY (fecha) ", db);
    qDebug()<<model->query().lastError().text();
    ui->tableView->setModel(model);
    }
    @

    but when i try the code below i get the same row that i got with sqldeveloper so....:

    @
    void BuscarGasto::on_pushButtonBuscar_clicked()
    {
    model->setQuery("SELECT idgasto, concepto, monto, TO_CHAR(fecha, 'dd-MM-yyyy'), observaciones "
    " FROM GASTOS WHERE concepto='KEVIN' "
    " ORDER BY (fecha) ", db);
    qDebug()<<model->query().lastError().text();
    ui->tableView->setModel(model);
    }
    @

    so the problem is somewhere in the lines below wich are exactly the same as i tried on sqldeveloper....

    @
    " AND TO_DATE(fecha,'dd-MM-yyyy') >= TO_DATE('01-09-1988' ,'dd-MM-yyyy') "
    " AND TO_DATE(fecha,'dd-MM-yyyy') < TO_DATE('1-10-1988','dd-MM-yyyy') "
    @

    the ouput of qDebug() is " ";

    other information: i use oracle express edition 11g

    so no clue where is the problem i tried everything that came to my head :(

    i dont post more information bcz the post is already to long and i dont think more infomation gona be usefull

    1 Reply Last reply
    0
    • C Offline
      C Offline
      clochydd
      wrote on last edited by
      #2

      What is the type and content of your field "fecha"?
      Have you tried to use for compare
      fecha::date >= '19880901' AND fecha::date < '19881001'?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        fecha is a oracle DATE TYPE

        1 Reply Last reply
        0
        • C Offline
          C Offline
          clochydd
          wrote on last edited by
          #4

          Unfortunately I'm not sure if my suggestion will work as I'm not familiar with Oracle. But your problem ist somewhere in the conversion of the date types and you should try without TO_DATE - especially for the field fecha from your database

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            but is the only way to compare qt qdate field with oracle date field and works when i try the same line in my sql developer so... thanks any way for your replies!! :)

            1 Reply Last reply
            0
            • C Offline
              C Offline
              clochydd
              wrote on last edited by
              #6

              in your sql developer you use TO_CHAR with fecha - which is OK, but in the WHERE clause of your Qt query you use TO_DATE - this might be the problem as you try to convert a date to date?

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                the code is exactly the same in sqldeveloper and in my code.... i use both functions in both codes... TO_CHAR for the data i retrieve taht is just what i am going to show i that column, and TO_DATE is the condition that the data have to sastisfy...

                sorry i did not make my self clear but i MUST use TO_DATE so i can compare them ... fecha and my string '1-10-1988' have to be same type to do that.

                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