QQuery filtering by date

thread: 18 messages  |  last: a year ago  |  started: wednesday, october 17, 2007, 3:34 am pdt


#1  |  Riccardo Tacconi (Leamington Spa, UK) United Kingdom
Wednesday, October 17, 2007, 3:34 AM PDT

I'd like to filter a datagrid by date. I need an equivalent of:

select * from tablename where the_date='2007-12-22'

In the qform I am using QDateTimePickerType::Date but I cannot find an example on how to use that object with a QQuery.

#2  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Wednesday, October 17, 2007, 7:15 AM PDT

QDateTimePickers have a DateTime property.  Simply take that DateTime property and pass that to your QQuery using QQ::Equal:

Tablename::QueryArray(QQ::Equal(QQN::Tablename()->TheDate, $this->dtpFoo->DateTime));

#3  |  Riccardo Tacconi (Leamington Spa, UK) United Kingdom
Wednesday, October 17, 2007, 9:47 AM PDT

This is what I have done but I get back an empty array. I guess that the date in the query does not satisfy the equal condition. Is it possible to make a query with only the month and the year? I do not want to filter by day, minutes and seconds

#4  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Wednesday, October 17, 2007, 2:17 PM PDT

if the_date is a date*time* in the database, and if you want all entries for a given date (regardless of the time), then you'll need to do a “greater or equal to” 2007-12-22 and “less than” 2007-12-23, in an AndCondition.

#5  |  Riccardo Tacconi (Leamington Spa, UK) United Kingdom
Thursday, October 18, 2007, 12:10 AM PDT

This is the function:

        
public static function LoadByDataChiamata($calDataChiamata) {
            return ChiamataVodafone::QueryArray(
                QQ::AndCondition(
                    QQ::LessThan(QQN::ChiamataVodafone()->DataChiamata,   $calDataChiamata->DateTime),
                    QQ::GreaterOrEqual(QQN::ChiamataVodafone()->DataChiamata, $calDataChiamata->DateTime)
                )
            );
        }    

This is the calling function:

print_r(ChiamataVodafone::LoadByDataChiamata($this->calDataChiamata));

The value of $this->calDataChiamata is Sep 03 2007.

I have no idea how to manipulate that date object, probabily I should study the code of that object.

I am at a good point in the development of my first app in qcodo, but I have stopped at this query, and I am running out of time :-( However thanks mike for your help.

#6  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Thursday, October 18, 2007, 7:46 AM PDT

in LoadByDateChiamata, first of all I would suggest that it take in a datetime and NOT a calendar value.  Having it take in a qcalendar makes it hard to repurpose LoadByDateChiamata in other places.

To get a “next day”, you can do:

public static function LoadByDataChiamata($dttDateTime) {
    $dttDateTime->SetTime(null, null, null);
    $dttNextDay = new QDateTime($dttDateTime);
    $dttNextDay->Day++;

    return ChiamataVodafone::QueryArray(
        QQ::AndCondition(
            QQ::LessThan(QQN::ChiamataVodafone()->DataChiamata, $dttNextDay),
            QQ::GreaterOrEqual(QQN::ChiamataVodafone()->DataChiamata, $dttDateTime)
        )
    );
}

And therefore, your calling code can be

ChiamataVodafone::LoadByDataChiamata($this->calDataChiamata->DateTime)
.bc
#7  |  Riccardo Tacconi (Leamington Spa, UK) United Kingdom
Thursday, October 18, 2007, 9:29 AM PDT

Ok, I understand, it is quite interesting your query. I am still getting an empty array. The value, Sep 04 2007 is in the record of the table, I am shure, but I get an empty array.

#8  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Thursday, October 18, 2007, 1:32 PM PDT

run the dbprofiler to see what query it is trying to run, and then run that query manually in mysql.

#9  |  Riccardo Tacconi (Leamington Spa, UK) United Kingdom
Thursday, October 18, 2007, 11:45 PM PDT

I do not know dbprofiler, I will search some info on the web site. I am using the new Oracle adapter, probably the problem is due to the different SQL implementation of Oracle.

#10  |  animekun (Bandung) Indonesia
Friday, October 19, 2007, 2:11 AM PDT

profiling is in qcodo configuration

define('DB_CONNECTION_1', serialize(array(
                'adapter' => 'MySqli5',
                'server' => 'localhost',
                'port' => null,
                'database' => 'test',
                'username' => 'root',
                'password' => '',
                'profiling' => true)));

ratno



Copyright © 2005 - 2013, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.