When the field is blank, don't warn about the field being unable to be coerced, just skip the column.

(closes http://lists.digium.com/pipermail/asterisk-dev/2009-December/041362.html)
Reported by Nic Colledge on the -dev list, fixed by me.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@236847 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2009-12-30 17:53:29 +00:00
parent 5d2b47ffb8
commit 98a07b127f
2 changed files with 74 additions and 34 deletions

View File

@@ -458,7 +458,9 @@ static int odbc_log(struct ast_cdr *cdr)
ast_str_append(&sql2, 0, "'"); ast_str_append(&sql2, 0, "'");
break; break;
case SQL_TYPE_DATE: case SQL_TYPE_DATE:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
int year = 0, month = 0, day = 0; int year = 0, month = 0, day = 0;
if (sscanf(colptr, "%4d-%2d-%2d", &year, &month, &day) != 3 || year <= 0 || if (sscanf(colptr, "%4d-%2d-%2d", &year, &month, &day) != 3 || year <= 0 ||
month <= 0 || month > 12 || day < 0 || day > 31 || month <= 0 || month > 12 || day < 0 || day > 31 ||
@@ -481,7 +483,9 @@ static int odbc_log(struct ast_cdr *cdr)
} }
break; break;
case SQL_TYPE_TIME: case SQL_TYPE_TIME:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
int hour = 0, minute = 0, second = 0; int hour = 0, minute = 0, second = 0;
int count = sscanf(colptr, "%2d:%2d:%2d", &hour, &minute, &second); int count = sscanf(colptr, "%2d:%2d:%2d", &hour, &minute, &second);
@@ -497,7 +501,9 @@ static int odbc_log(struct ast_cdr *cdr)
break; break;
case SQL_TYPE_TIMESTAMP: case SQL_TYPE_TIMESTAMP:
case SQL_TIMESTAMP: case SQL_TIMESTAMP:
{ 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;
int count = sscanf(colptr, "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &minute, &second); int count = sscanf(colptr, "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &minute, &second);
@@ -523,7 +529,9 @@ static int odbc_log(struct ast_cdr *cdr)
} }
break; break;
case SQL_INTEGER: case SQL_INTEGER:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
int integer = 0; int integer = 0;
if (sscanf(colptr, "%30d", &integer) != 1) { if (sscanf(colptr, "%30d", &integer) != 1) {
ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
@@ -536,7 +544,9 @@ static int odbc_log(struct ast_cdr *cdr)
} }
break; break;
case SQL_BIGINT: case SQL_BIGINT:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
long long integer = 0; long long integer = 0;
if (sscanf(colptr, "%30lld", &integer) != 1) { if (sscanf(colptr, "%30lld", &integer) != 1) {
ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
@@ -549,7 +559,9 @@ static int odbc_log(struct ast_cdr *cdr)
} }
break; break;
case SQL_SMALLINT: case SQL_SMALLINT:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
short integer = 0; short integer = 0;
if (sscanf(colptr, "%30hd", &integer) != 1) { if (sscanf(colptr, "%30hd", &integer) != 1) {
ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
@@ -562,7 +574,9 @@ static int odbc_log(struct ast_cdr *cdr)
} }
break; break;
case SQL_TINYINT: case SQL_TINYINT:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
char integer = 0; char integer = 0;
if (sscanf(colptr, "%30hhd", &integer) != 1) { if (sscanf(colptr, "%30hhd", &integer) != 1) {
ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
@@ -575,7 +589,9 @@ static int odbc_log(struct ast_cdr *cdr)
} }
break; break;
case SQL_BIT: case SQL_BIT:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
char integer = 0; char integer = 0;
if (sscanf(colptr, "%30hhd", &integer) != 1) { if (sscanf(colptr, "%30hhd", &integer) != 1) {
ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
@@ -591,7 +607,9 @@ static int odbc_log(struct ast_cdr *cdr)
break; break;
case SQL_NUMERIC: case SQL_NUMERIC:
case SQL_DECIMAL: case SQL_DECIMAL:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
double number = 0.0; double number = 0.0;
if (sscanf(colptr, "%30lf", &number) != 1) { if (sscanf(colptr, "%30lf", &number) != 1) {
ast_log(LOG_WARNING, "CDR variable %s is not an numeric type.\n", entry->name); ast_log(LOG_WARNING, "CDR variable %s is not an numeric type.\n", entry->name);
@@ -606,7 +624,9 @@ static int odbc_log(struct ast_cdr *cdr)
case SQL_FLOAT: case SQL_FLOAT:
case SQL_REAL: case SQL_REAL:
case SQL_DOUBLE: case SQL_DOUBLE:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
double number = 0.0; double number = 0.0;
if (sscanf(colptr, "%30lf", &number) != 1) { if (sscanf(colptr, "%30lf", &number) != 1) {
ast_log(LOG_WARNING, "CDR variable %s is not an numeric type.\n", entry->name); ast_log(LOG_WARNING, "CDR variable %s is not an numeric type.\n", entry->name);

View File

@@ -403,39 +403,39 @@ static void odbc_log(const struct ast_event *event, void *userdata)
colptr = colbuf; colptr = colbuf;
} else { } else {
if (strcmp(entry->celname, "userdeftype") == 0) { if (strcmp(entry->celname, "userdeftype") == 0) {
strncpy(colbuf, record.user_defined_name, sizeof(colbuf)); ast_copy_string(colbuf, record.user_defined_name, sizeof(colbuf));
} else if (strcmp(entry->celname, "cid_name") == 0) { } else if (strcmp(entry->celname, "cid_name") == 0) {
strncpy(colbuf, record.caller_id_name, sizeof(colbuf)); ast_copy_string(colbuf, record.caller_id_name, sizeof(colbuf));
} else if (strcmp(entry->celname, "cid_num") == 0) { } else if (strcmp(entry->celname, "cid_num") == 0) {
strncpy(colbuf, record.caller_id_num, sizeof(colbuf)); ast_copy_string(colbuf, record.caller_id_num, sizeof(colbuf));
} else if (strcmp(entry->celname, "cid_ani") == 0) { } else if (strcmp(entry->celname, "cid_ani") == 0) {
strncpy(colbuf, record.caller_id_ani, sizeof(colbuf)); ast_copy_string(colbuf, record.caller_id_ani, sizeof(colbuf));
} else if (strcmp(entry->celname, "cid_rdnis") == 0) { } else if (strcmp(entry->celname, "cid_rdnis") == 0) {
strncpy(colbuf, record.caller_id_rdnis, sizeof(colbuf)); ast_copy_string(colbuf, record.caller_id_rdnis, sizeof(colbuf));
} else if (strcmp(entry->celname, "cid_dnid") == 0) { } else if (strcmp(entry->celname, "cid_dnid") == 0) {
strncpy(colbuf, record.caller_id_dnid, sizeof(colbuf)); ast_copy_string(colbuf, record.caller_id_dnid, sizeof(colbuf));
} else if (strcmp(entry->celname, "exten") == 0) { } else if (strcmp(entry->celname, "exten") == 0) {
strncpy(colbuf, record.extension, sizeof(colbuf)); ast_copy_string(colbuf, record.extension, sizeof(colbuf));
} else if (strcmp(entry->celname, "context") == 0) { } else if (strcmp(entry->celname, "context") == 0) {
strncpy(colbuf, record.context, sizeof(colbuf)); ast_copy_string(colbuf, record.context, sizeof(colbuf));
} else if (strcmp(entry->celname, "channame") == 0) { } else if (strcmp(entry->celname, "channame") == 0) {
strncpy(colbuf, record.channel_name, sizeof(colbuf)); ast_copy_string(colbuf, record.channel_name, sizeof(colbuf));
} else if (strcmp(entry->celname, "appname") == 0) { } else if (strcmp(entry->celname, "appname") == 0) {
strncpy(colbuf, record.application_name, sizeof(colbuf)); ast_copy_string(colbuf, record.application_name, sizeof(colbuf));
} else if (strcmp(entry->celname, "appdata") == 0) { } else if (strcmp(entry->celname, "appdata") == 0) {
strncpy(colbuf, record.application_data, sizeof(colbuf)); ast_copy_string(colbuf, record.application_data, sizeof(colbuf));
} else if (strcmp(entry->celname, "accountcode") == 0) { } else if (strcmp(entry->celname, "accountcode") == 0) {
strncpy(colbuf, record.account_code, sizeof(colbuf)); ast_copy_string(colbuf, record.account_code, sizeof(colbuf));
} else if (strcmp(entry->celname, "peeraccount") == 0) { } else if (strcmp(entry->celname, "peeraccount") == 0) {
strncpy(colbuf, record.peer_account, sizeof(colbuf)); ast_copy_string(colbuf, record.peer_account, sizeof(colbuf));
} else if (strcmp(entry->celname, "uniqueid") == 0) { } else if (strcmp(entry->celname, "uniqueid") == 0) {
strncpy(colbuf, record.unique_id, sizeof(colbuf)); ast_copy_string(colbuf, record.unique_id, sizeof(colbuf));
} else if (strcmp(entry->celname, "linkedid") == 0) { } else if (strcmp(entry->celname, "linkedid") == 0) {
strncpy(colbuf, record.linked_id, sizeof(colbuf)); ast_copy_string(colbuf, record.linked_id, sizeof(colbuf));
} else if (strcmp(entry->celname, "userfield") == 0) { } else if (strcmp(entry->celname, "userfield") == 0) {
strncpy(colbuf, record.user_field, sizeof(colbuf)); ast_copy_string(colbuf, record.user_field, sizeof(colbuf));
} else if (strcmp(entry->celname, "peer") == 0) { } else if (strcmp(entry->celname, "peer") == 0) {
strncpy(colbuf, record.peer, sizeof(colbuf)); ast_copy_string(colbuf, record.peer, sizeof(colbuf));
} else if (strcmp(entry->celname, "amaflags") == 0) { } else if (strcmp(entry->celname, "amaflags") == 0) {
snprintf(colbuf, sizeof(colbuf), "%d", record.amaflag); snprintf(colbuf, sizeof(colbuf), "%d", record.amaflag);
} else { } else {
@@ -501,7 +501,9 @@ static void odbc_log(const struct ast_event *event, void *userdata)
ast_str_append(&sql2, 0, "'"); ast_str_append(&sql2, 0, "'");
break; break;
case SQL_TYPE_DATE: case SQL_TYPE_DATE:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
int year = 0, month = 0, day = 0; int year = 0, month = 0, day = 0;
if (sscanf(colptr, "%4d-%2d-%2d", &year, &month, &day) != 3 || year <= 0 || if (sscanf(colptr, "%4d-%2d-%2d", &year, &month, &day) != 3 || year <= 0 ||
month <= 0 || month > 12 || day < 0 || day > 31 || month <= 0 || month > 12 || day < 0 || day > 31 ||
@@ -524,7 +526,9 @@ static void odbc_log(const struct ast_event *event, void *userdata)
} }
break; break;
case SQL_TYPE_TIME: case SQL_TYPE_TIME:
{ if (ast_strlen_zero(colptr)) {
continue;
} else {
int hour = 0, minute = 0, second = 0; int hour = 0, minute = 0, second = 0;
int count = sscanf(colptr, "%2d:%2d:%2d", &hour, &minute, &second); int count = sscanf(colptr, "%2d:%2d:%2d", &hour, &minute, &second);
@@ -540,7 +544,9 @@ static void odbc_log(const struct ast_event *event, void *userdata)
break; break;
case SQL_TYPE_TIMESTAMP: case SQL_TYPE_TIMESTAMP:
case SQL_TIMESTAMP: case SQL_TIMESTAMP:
{ 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;
int count = sscanf(colptr, "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &minute, &second); int count = sscanf(colptr, "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &minute, &second);
@@ -570,6 +576,8 @@ static void odbc_log(const struct ast_event *event, void *userdata)
int integer = 0; int integer = 0;
if (strcasecmp(entry->name, "eventtype") == 0) { if (strcasecmp(entry->name, "eventtype") == 0) {
integer = (int) record.event_type; integer = (int) record.event_type;
} else if (ast_strlen_zero(colptr)) {
continue;
} else if (sscanf(colptr, "%30d", &integer) != 1) { } else if (sscanf(colptr, "%30d", &integer) != 1) {
ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
continue; continue;
@@ -585,6 +593,8 @@ static void odbc_log(const struct ast_event *event, void *userdata)
long long integer = 0; long long integer = 0;
if (strcasecmp(entry->name, "eventtype") == 0) { if (strcasecmp(entry->name, "eventtype") == 0) {
integer = (long long) record.event_type; integer = (long long) record.event_type;
} else if (ast_strlen_zero(colptr)) {
continue;
} else if (sscanf(colptr, "%30lld", &integer) != 1) { } else if (sscanf(colptr, "%30lld", &integer) != 1) {
ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
continue; continue;
@@ -600,6 +610,8 @@ static void odbc_log(const struct ast_event *event, void *userdata)
short integer = 0; short integer = 0;
if (strcasecmp(entry->name, "eventtype") == 0) { if (strcasecmp(entry->name, "eventtype") == 0) {
integer = (short) record.event_type; integer = (short) record.event_type;
} else if (ast_strlen_zero(colptr)) {
continue;
} else if (sscanf(colptr, "%30hd", &integer) != 1) { } else if (sscanf(colptr, "%30hd", &integer) != 1) {
ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
continue; continue;
@@ -615,6 +627,8 @@ static void odbc_log(const struct ast_event *event, void *userdata)
char integer = 0; char integer = 0;
if (strcasecmp(entry->name, "eventtype") == 0) { if (strcasecmp(entry->name, "eventtype") == 0) {
integer = (char) record.event_type; integer = (char) record.event_type;
} else if (ast_strlen_zero(colptr)) {
continue;
} else if (sscanf(colptr, "%30hhd", &integer) != 1) { } else if (sscanf(colptr, "%30hhd", &integer) != 1) {
ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
continue; continue;
@@ -630,6 +644,8 @@ static void odbc_log(const struct ast_event *event, void *userdata)
char integer = 0; char integer = 0;
if (strcasecmp(entry->name, "eventtype") == 0) { if (strcasecmp(entry->name, "eventtype") == 0) {
integer = (char) record.event_type; integer = (char) record.event_type;
} else if (ast_strlen_zero(colptr)) {
continue;
} else if (sscanf(colptr, "%30hhd", &integer) != 1) { } else if (sscanf(colptr, "%30hhd", &integer) != 1) {
ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
continue; continue;
@@ -648,6 +664,8 @@ static void odbc_log(const struct ast_event *event, void *userdata)
double number = 0.0; double number = 0.0;
if (strcasecmp(entry->name, "eventtype") == 0) { if (strcasecmp(entry->name, "eventtype") == 0) {
number = (double)record.event_type; number = (double)record.event_type;
} else if (ast_strlen_zero(colptr)) {
continue;
} else if (sscanf(colptr, "%30lf", &number) != 1) { } else if (sscanf(colptr, "%30lf", &number) != 1) {
ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name); ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name);
continue; continue;
@@ -665,6 +683,8 @@ static void odbc_log(const struct ast_event *event, void *userdata)
double number = 0.0; double number = 0.0;
if (strcasecmp(entry->name, "eventtype") == 0) { if (strcasecmp(entry->name, "eventtype") == 0) {
number = (double) record.event_type; number = (double) record.event_type;
} else if (ast_strlen_zero(colptr)) {
continue;
} else if (sscanf(colptr, "%30lf", &number) != 1) { } else if (sscanf(colptr, "%30lf", &number) != 1) {
ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name); ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name);
continue; continue;