mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-20 00:30:20 +00:00
res_config_odbc/res_odbc: Fix handling of non-text columns updates with empty values.
This patch fixes setting nullable integer columns to NULL instead of an empty string, which fails for PostgreSQL, for example. The current code is supposed to do so, but the check is broken. The patch also allows the first column in the list to be a nullable integer. This patch also adds a compatibility setting in res_odbc.conf, allow_empty_string_in_nontext. It is enabled by default. It should be disabled for database backends (such as PostgreSQL) that require NULL instead of an empty string for Integer columns. Review: https://reviewboard.asterisk.org/r/3375 (issue ASTERISK-23459) Reported by: zvision patches: res_config_odbc.diff uploaded by zvision (License 5755) ........ Merged revisions 411399 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@411408 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -128,6 +128,7 @@ struct odbc_class
|
||||
unsigned int delme:1; /*!< Purge the class */
|
||||
unsigned int backslash_is_escape:1; /*!< On this database, the backslash is a native escape sequence */
|
||||
unsigned int forcecommit:1; /*!< Should uncommitted transactions be auto-committed on handle release? */
|
||||
unsigned int allow_empty_strings:1; /*!< Implicit conversion from an empty string to a number is valid for this database */
|
||||
unsigned int isolation; /*!< Flags for how the DB should deal with data in other, uncommitted transactions */
|
||||
unsigned int limit; /*!< Maximum number of database handles we will allow */
|
||||
int count; /*!< Running count of pooled connections */
|
||||
@@ -772,7 +773,7 @@ static int load_odbc_config(void)
|
||||
struct ast_variable *v;
|
||||
char *cat;
|
||||
const char *dsn, *username, *password, *sanitysql;
|
||||
int enabled, pooling, limit, bse, conntimeout, forcecommit, isolation;
|
||||
int enabled, pooling, limit, bse, conntimeout, forcecommit, isolation, allow_empty_strings;
|
||||
struct timeval ncache = { 0, 0 };
|
||||
unsigned int idlecheck;
|
||||
int preconnect = 0, res = 0;
|
||||
@@ -801,6 +802,7 @@ static int load_odbc_config(void)
|
||||
bse = 1;
|
||||
conntimeout = 10;
|
||||
forcecommit = 0;
|
||||
allow_empty_strings = 1;
|
||||
isolation = SQL_TXN_READ_COMMITTED;
|
||||
for (v = ast_variable_browse(config, cat); v; v = v->next) {
|
||||
if (!strcasecmp(v->name, "pooling")) {
|
||||
@@ -836,6 +838,8 @@ static int load_odbc_config(void)
|
||||
sanitysql = v->value;
|
||||
} else if (!strcasecmp(v->name, "backslash_is_escape")) {
|
||||
bse = ast_true(v->value);
|
||||
} else if (!strcasecmp(v->name, "allow_empty_string_in_nontext")) {
|
||||
allow_empty_strings = ast_true(v->value);
|
||||
} else if (!strcasecmp(v->name, "connect_timeout")) {
|
||||
if (sscanf(v->value, "%d", &conntimeout) != 1 || conntimeout < 1) {
|
||||
ast_log(LOG_WARNING, "connect_timeout must be a positive integer\n");
|
||||
@@ -897,6 +901,7 @@ static int load_odbc_config(void)
|
||||
new->idlecheck = idlecheck;
|
||||
new->conntimeout = conntimeout;
|
||||
new->negative_connection_cache = ncache;
|
||||
new->allow_empty_strings = allow_empty_strings ? 1 : 0;
|
||||
|
||||
if (cat)
|
||||
ast_copy_string(new->name, cat, sizeof(new->name));
|
||||
@@ -1114,6 +1119,11 @@ int ast_odbc_backslash_is_escape(struct odbc_obj *obj)
|
||||
return obj->parent->backslash_is_escape;
|
||||
}
|
||||
|
||||
int ast_odbc_allow_empty_string_in_nontext(struct odbc_obj *obj)
|
||||
{
|
||||
return obj->parent->allow_empty_strings;
|
||||
}
|
||||
|
||||
static int commit_exec(struct ast_channel *chan, const char *data)
|
||||
{
|
||||
struct odbc_txn_frame *tx;
|
||||
|
||||
Reference in New Issue
Block a user