[asterisk-commits] mjordan: branch 12 r427953 - in /branches/12: ./ cel/cel_odbc.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Nov 15 10:56:23 CST 2014


Author: mjordan
Date: Sat Nov 15 10:56:20 2014
New Revision: 427953

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=427953
Log:
cel/cel_odbc: Provide microsecond precision in 'eventtime' column when possible

This patch adds microsecond precision when inserting a CEL record into a table
with an "eventtime" column of type timestamp, instead of second precision. The
documentation (configs/cel_odbc.conf.sample) was already saying that the
eventtime column included microseconds precision, but that was not the case.

Also, without this patch, if you had a table with an "eventtime" column of
type varchar, you had millisecond precision. With this patch, you also get
microsecond precision in this case.

Review: https://reviewboard.asterisk.org/r/3980

ASTERISK-24283 #close
Reported by: Etienne Lessard
patches:
  cel_odbc_time_precision.patch uploaded by Etienne Lessard (License 6394)
........

Merged revisions 427952 from http://svn.asterisk.org/svn/asterisk/branches/11

Modified:
    branches/12/   (props changed)
    branches/12/cel/cel_odbc.c

Propchange: branches/12/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Modified: branches/12/cel/cel_odbc.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/cel/cel_odbc.c?view=diff&rev=427953&r1=427952&r2=427953
==============================================================================
--- branches/12/cel/cel_odbc.c (original)
+++ branches/12/cel/cel_odbc.c Sat Nov 15 10:56:20 2014
@@ -436,7 +436,7 @@
 				   This should be ok, however, as nobody is going to store just event
 				   date or just time for CDR purposes.
 				 */
-				ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S.%q", &tm);
+				ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S.%6q", &tm);
 				colptr = colbuf;
 			} else {
 				if (strcmp(entry->celname, "userdeftype") == 0) {
@@ -615,7 +615,7 @@
 					if (ast_strlen_zero(colptr)) {
 						continue;
 					} else {
-						int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
+						int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, fraction = 0;
 						if (strcasecmp(entry->name, "eventdate") == 0) {
 							struct ast_tm tm;
 							ast_localtime(&record.event_time, &tm, tableptr->usegmtime ? "UTC" : NULL);
@@ -625,17 +625,18 @@
 							hour = tm.tm_hour;
 							minute = tm.tm_min;
 							second = (tableptr->allowleapsec || tm.tm_sec < 60) ? tm.tm_sec : 59;
+							fraction = tm.tm_usec;
 						} else {
-							int count = sscanf(colptr, "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &minute, &second);
-
-							if ((count != 3 && count != 5 && count != 6) || year <= 0 ||
+							int count = sscanf(colptr, "%4d-%2d-%2d %2d:%2d:%2d.%6d", &year, &month, &day, &hour, &minute, &second, &fraction);
+
+							if ((count != 3 && count != 5 && count != 6 && count != 7) || year <= 0 ||
 								month <= 0 || month > 12 || day < 0 || day > 31 ||
 								((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) ||
 								(month == 2 && year % 400 == 0 && day > 29) ||
 								(month == 2 && year % 100 == 0 && day > 28) ||
 								(month == 2 && year % 4 == 0 && day > 29) ||
 								(month == 2 && year % 4 != 0 && day > 28) ||
-								hour > 23 || minute > 59 || second > (tableptr->allowleapsec ? 60 : 59) || hour < 0 || minute < 0 || second < 0) {
+								hour > 23 || minute > 59 || second > (tableptr->allowleapsec ? 60 : 59) || hour < 0 || minute < 0 || second < 0 || fraction < 0) {
 								ast_log(LOG_WARNING, "CEL variable %s is not a valid timestamp ('%s').\n", entry->name, colptr);
 								continue;
 							}
@@ -647,7 +648,7 @@
 
 						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(27);
-						ast_str_append(&sql2, 0, "%s{ts '%04d-%02d-%02d %02d:%02d:%02d'}", first ? "" : ",", year, month, day, hour, minute, second);
+						ast_str_append(&sql2, 0, "%s{ts '%04d-%02d-%02d %02d:%02d:%02d.%d'}", first ? "" : ",", year, month, day, hour, minute, second, fraction);
 					}
 					break;
 				case SQL_INTEGER:




More information about the asterisk-commits mailing list