char sqlcmd[2048], timestr[128];
int res = 0;
struct tm tm;
- struct timeval tv;
- time_t t;
- gettimeofday(&tv,NULL);
- t = tv.tv_sec;
- localtime_r(&t,&tm);
+ localtime_r(&cdr->start.tv_sec,&tm);
ast_mutex_lock(&odbc_lock);
strftime(timestr,128,DATE_FORMAT,&tm);
SQLBindCol(stmt,7,SQL_C_CHAR,&var_name,sizeof(var_name),&err);
SQLBindCol(stmt,8,SQL_C_CHAR,&var_val,sizeof(var_val),&err);
- sprintf(sql,"select * from %s where filename='%s' and commented=0 order by filename,cat_metric,var_metric,id",table,file);
+ sprintf(sql,"select * from %s where filename='%s' and commented=0 order by filename,cat_metric desc,var_metric asc,id",table,file);
res = SQLExecDirect(stmt,sql,SQL_NTS);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {