summaryrefslogtreecommitdiff
path: root/res/res_config_odbc.c
diff options
context:
space:
mode:
authorJonathan Rose <jrose@digium.com>2011-07-07 16:18:18 +0000
committerJonathan Rose <jrose@digium.com>2011-07-07 16:18:18 +0000
commitc545e3b1c585f02efcdabe0324ce5dc3c13a2285 (patch)
treebf77711e29d3cbb17db9b70b4030ec87a4c6ccb3 /res/res_config_odbc.c
parentba1cc98f1ae05ff4278696dffb5e2e92fe18f695 (diff)
Merged revisions 326689 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r326689 | jrose | 2011-07-07 11:04:51 -0500 (Thu, 07 Jul 2011) | 10 lines res_odbc patch by tilghman to fix integers with null values Addresses some improper sql statements in res_odbc that would cause an update to fail on realtime peers due to trying to set as "(NULL)" rather than an actual NULL. (closes issue #1922STERISK-17791) Reported by: marcelloceschia Patches: 20110505__issue19223.diff.txt uploaded by tilghman (license 14) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@326694 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_config_odbc.c')
-rw-r--r--res/res_config_odbc.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c
index 8154ecc2b..f52f941be 100644
--- a/res/res_config_odbc.c
+++ b/res/res_config_odbc.c
@@ -481,7 +481,7 @@ static int update_odbc(const char *database, const char *table, const char *keyf
va_list aq;
struct custom_prepare_struct cps = { .sql = sql, .extra = lookup };
struct odbc_cache_tables *tableptr;
- struct odbc_cache_columns *column;
+ struct odbc_cache_columns *column = NULL;
struct ast_flags connected_flag = { RES_ODBC_CONNECTED };
if (!table) {
@@ -519,7 +519,16 @@ static int update_odbc(const char *database, const char *table, const char *keyf
while((newparam = va_arg(aq, const char *))) {
va_arg(aq, const char *);
if ((tableptr && (column = ast_odbc_find_column(tableptr, newparam))) || count > 63) {
- snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s=?", newparam);
+ /* NULL test for integer-based columns */
+ if (ast_strlen_zero(newparam) && tableptr && column && column->nullable && count < 64 &&
+ (column->type == SQL_INTEGER || column->type == SQL_BIGINT ||
+ column->type == SQL_SMALLINT || column->type == SQL_TINYINT ||
+ column->type == SQL_NUMERIC || column->type == SQL_DECIMAL)) {
+ snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s=NULL", newparam);
+ cps.skip |= (1LL << count);
+ } else {
+ snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s=?", newparam);
+ }
} else { /* the column does not exist in the table */
cps.skip |= (1LL << count);
}