[NTLUG:Discuss] Decipher C++ source
Fred James
fredjame at fredjame.cnc.net
Mon Jun 8 15:50:28 CDT 2009
Michael Barnes wrote:
> I have a MySQL database that logs telephone calls. A module puts the
> CallerID number into a variable. Then, this database query is
> supposed to return the last date and time that number called. The
> database table has fields for NUMBER, NAME, CALL_DATE and CALL_TIME.
> (There are others, but I don't care about them for this purpose.)
>
> Anyhow, it appears that the query is giving me the first time the
> number called, not the latest time.
>
> I'm hoping some good programmer out there could take a peek at this
> and answer some questions.
> First I need to know why I get the first call instead of the last call.
> Then some curiosity questions.
> What is the significance of the '!' after the NAME field?
> Is the value \"\" for NAME some type of a variable or wildcard?
>
> What line(s) actually select the proper data (last call) from the list
> returned by the query?
>
> Once it gets the right data, it puts it into an element in the
> BusDriver module. It also increments the call counter, which is
> working correctly.
>
> Here's the code.
>
> sql=QString().sprintf("select CALL_DATE,CALL_TIME from DETAILS_GAL \
> where (NUMBER=\"%s\")&&(NAME!=\"\") \
> order by CALL_DATE,CALL_TIME desc",
> (const char *)mon->showCode(),
> (const char *)pnum);
> q=new QSqlQuery(sql);
> if(q->first()) {
> mon->metaData(line)->
> setElement(BusDriver::LastCallDatetimeElement,
> QString().sprintf("%d",QDateTime(q->value(0).toDate(),
> q->value(1).toTime()).
> toTime_t()));
> }
> mon->metaData(line)->setElement(BusDriver::CounterElement,q->size());
> delete q;
>
>
> Any comments, English translations/explanations, potential problems,
> etc. are appreciated.
>
> Thanks,
> Michael
>
Michael Barnes
At first glance, the issue is in the embedded SQL statement ...
specifically the 'order by' clause ...
The 'desc' (descending) applies only to CALL_TIME?
Should read something like
order by CALL_DATE desc, CALL_TIME desc
For Reference, See
<http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html>
Hope that helps
Regards
Fred James
More information about the Discuss
mailing list