[NTLUG:Discuss] Decipher C++ source

Michael Barnes barnmichael at gmail.com
Mon Jun 8 14:49:55 CDT 2009


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



More information about the Discuss mailing list