QSqlQueryModel dont show any row
-
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
-
What is the type and content of your field "fecha"?
Have you tried to use for compare
fecha::date >= '19880901' AND fecha::date < '19881001'? -
fecha is a oracle DATE TYPE
-
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
-
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!! :)
-
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?
-
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.