Merged revisions 89559 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r89559 | tilghman | 2007-11-25 11:17:10 -0600 (Sun, 25 Nov 2007) | 14 lines We previously attempted to use the ESCAPE clause to set the escape delimiter to a backslash. Unfortunately, this does not universally work on all databases, since on databases which natively use the backslash as a delimiter, the backslash itself needs to be delimited, but on other databases that have no delimiter, backslashing the backslash causes an error. So the only solution that I can come up with is to create an option in res_odbc that explicitly specifies whether or not backslash is a native delimiter. If it is, we use it natively; if not, we use the ESCAPE clause to make it one. Reported by: elguero Patch by: tilghman (Closes issue #11364) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89561 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
c8edf66bb4
commit
f1de129e5f
|
@ -40,6 +40,9 @@ username => oscar
|
||||||
password => thegrouch
|
password => thegrouch
|
||||||
pre-connect => yes
|
pre-connect => yes
|
||||||
sanitysql => select count(*) from systables
|
sanitysql => select count(*) from systables
|
||||||
|
; Many databases have a default of '\' to escape special characters. MS SQL
|
||||||
|
; Server does not.
|
||||||
|
backslash_is_escape => no
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,12 @@ void ast_odbc_release_obj(struct odbc_obj *obj);
|
||||||
*/
|
*/
|
||||||
int ast_odbc_sanity_check(struct odbc_obj *obj);
|
int ast_odbc_sanity_check(struct odbc_obj *obj);
|
||||||
|
|
||||||
|
/*! \brief Checks if the database natively supports backslash as an escape character.
|
||||||
|
* \param obj The ODBC object
|
||||||
|
* \return Returns 1 if an ESCAPE clause is needed to support '\', 0 otherwise
|
||||||
|
*/
|
||||||
|
int ast_odbc_backslash_is_escape(struct odbc_obj *obj);
|
||||||
|
|
||||||
/*! \brief Executes an non prepared statement and returns the resulting
|
/*! \brief Executes an non prepared statement and returns the resulting
|
||||||
* statement handle.
|
* statement handle.
|
||||||
* \param obj The ODBC object
|
* \param obj The ODBC object
|
||||||
|
|
|
@ -142,11 +142,12 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
|
||||||
return NULL;
|
return NULL;
|
||||||
newval = va_arg(aq, const char *);
|
newval = va_arg(aq, const char *);
|
||||||
op = !strchr(newparam, ' ') ? " =" : "";
|
op = !strchr(newparam, ' ') ? " =" : "";
|
||||||
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s ?", table, newparam, op);
|
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s ?%s", table, newparam, op,
|
||||||
|
strcasestr(newparam, "LIKE") && !ast_odbc_backslash_is_escape(obj) ? " ESCAPE '\\'" : "");
|
||||||
while((newparam = va_arg(aq, const char *))) {
|
while((newparam = va_arg(aq, const char *))) {
|
||||||
op = !strchr(newparam, ' ') ? " =" : "";
|
op = !strchr(newparam, ' ') ? " =" : "";
|
||||||
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s ?%s", newparam, op,
|
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s ?%s", newparam, op,
|
||||||
strcasestr(newparam, "LIKE") ? " ESCAPE '\\'" : "");
|
strcasestr(newparam, "LIKE") && !ast_odbc_backslash_is_escape(obj) ? " ESCAPE '\\'" : "");
|
||||||
newval = va_arg(aq, const char *);
|
newval = va_arg(aq, const char *);
|
||||||
}
|
}
|
||||||
va_end(aq);
|
va_end(aq);
|
||||||
|
@ -290,11 +291,11 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
|
||||||
newval = va_arg(aq, const char *);
|
newval = va_arg(aq, const char *);
|
||||||
op = !strchr(newparam, ' ') ? " =" : "";
|
op = !strchr(newparam, ' ') ? " =" : "";
|
||||||
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s ?%s", table, newparam, op,
|
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s ?%s", table, newparam, op,
|
||||||
strcasestr(newparam, "LIKE") ? " ESCAPE '\\'" : "");
|
strcasestr(newparam, "LIKE") && !ast_odbc_backslash_is_escape(obj) ? " ESCAPE '\\'" : "");
|
||||||
while((newparam = va_arg(aq, const char *))) {
|
while((newparam = va_arg(aq, const char *))) {
|
||||||
op = !strchr(newparam, ' ') ? " =" : "";
|
op = !strchr(newparam, ' ') ? " =" : "";
|
||||||
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s ?%s", newparam, op,
|
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s%s ?%s", newparam, op,
|
||||||
strcasestr(newparam, "LIKE") ? " ESCAPE '\\'" : "");
|
strcasestr(newparam, "LIKE") && !ast_odbc_backslash_is_escape(obj) ? " ESCAPE '\\'" : "");
|
||||||
newval = va_arg(aq, const char *);
|
newval = va_arg(aq, const char *);
|
||||||
}
|
}
|
||||||
if (initfield)
|
if (initfield)
|
||||||
|
|
|
@ -60,6 +60,7 @@ struct odbc_class
|
||||||
unsigned int limit:10; /* Gives a limit of 1023 maximum */
|
unsigned int limit:10; /* Gives a limit of 1023 maximum */
|
||||||
unsigned int count:10; /* Running count of pooled connections */
|
unsigned int count:10; /* Running count of pooled connections */
|
||||||
unsigned int delme:1; /* Purge the class */
|
unsigned int delme:1; /* Purge the class */
|
||||||
|
unsigned int backslash_is_escape:1; /* On this database, the backslash is a native escape sequence */
|
||||||
AST_LIST_HEAD(, odbc_obj) odbc_obj;
|
AST_LIST_HEAD(, odbc_obj) odbc_obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -227,7 +228,7 @@ static int load_odbc_config(void)
|
||||||
struct ast_variable *v;
|
struct ast_variable *v;
|
||||||
char *cat;
|
char *cat;
|
||||||
const char *dsn, *username, *password, *sanitysql;
|
const char *dsn, *username, *password, *sanitysql;
|
||||||
int enabled, pooling, limit;
|
int enabled, pooling, limit, bse;
|
||||||
int connect = 0, res = 0;
|
int connect = 0, res = 0;
|
||||||
struct ast_flags config_flags = { 0 };
|
struct ast_flags config_flags = { 0 };
|
||||||
|
|
||||||
|
@ -251,6 +252,7 @@ static int load_odbc_config(void)
|
||||||
connect = 0;
|
connect = 0;
|
||||||
pooling = 0;
|
pooling = 0;
|
||||||
limit = 0;
|
limit = 0;
|
||||||
|
bse = 1;
|
||||||
for (v = ast_variable_browse(config, cat); v; v = v->next) {
|
for (v = ast_variable_browse(config, cat); v; v = v->next) {
|
||||||
if (!strcasecmp(v->name, "pooling")) {
|
if (!strcasecmp(v->name, "pooling")) {
|
||||||
if (ast_true(v->value))
|
if (ast_true(v->value))
|
||||||
|
@ -277,6 +279,8 @@ static int load_odbc_config(void)
|
||||||
password = v->value;
|
password = v->value;
|
||||||
} else if (!strcasecmp(v->name, "sanitysql")) {
|
} else if (!strcasecmp(v->name, "sanitysql")) {
|
||||||
sanitysql = v->value;
|
sanitysql = v->value;
|
||||||
|
} else if (!strcasecmp(v->name, "backslash_is_escape")) {
|
||||||
|
bse = ast_true(v->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +322,8 @@ static int load_odbc_config(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new->backslash_is_escape = bse ? 1 : 0;
|
||||||
|
|
||||||
odbc_register_class(new, connect);
|
odbc_register_class(new, connect);
|
||||||
ast_log(LOG_NOTICE, "Registered ODBC class '%s' dsn->[%s]\n", cat, dsn);
|
ast_log(LOG_NOTICE, "Registered ODBC class '%s' dsn->[%s]\n", cat, dsn);
|
||||||
}
|
}
|
||||||
|
@ -422,6 +428,11 @@ void ast_odbc_release_obj(struct odbc_obj *obj)
|
||||||
obj->used = 0;
|
obj->used = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ast_odbc_backslash_is_escape(struct odbc_obj *obj)
|
||||||
|
{
|
||||||
|
return obj->parent->backslash_is_escape;
|
||||||
|
}
|
||||||
|
|
||||||
struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
||||||
{
|
{
|
||||||
struct odbc_obj *obj = NULL;
|
struct odbc_obj *obj = NULL;
|
||||||
|
@ -577,7 +588,7 @@ static int reload(void)
|
||||||
struct ast_variable *v;
|
struct ast_variable *v;
|
||||||
char *cat;
|
char *cat;
|
||||||
const char *dsn, *username, *password, *sanitysql;
|
const char *dsn, *username, *password, *sanitysql;
|
||||||
int enabled, pooling, limit;
|
int enabled, pooling, limit, bse;
|
||||||
int connect = 0, res = 0;
|
int connect = 0, res = 0;
|
||||||
struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
|
struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
|
||||||
|
|
||||||
|
@ -605,6 +616,7 @@ static int reload(void)
|
||||||
connect = 0;
|
connect = 0;
|
||||||
pooling = 0;
|
pooling = 0;
|
||||||
limit = 0;
|
limit = 0;
|
||||||
|
bse = 1;
|
||||||
for (v = ast_variable_browse(config, cat); v; v = v->next) {
|
for (v = ast_variable_browse(config, cat); v; v = v->next) {
|
||||||
if (!strcasecmp(v->name, "pooling")) {
|
if (!strcasecmp(v->name, "pooling")) {
|
||||||
pooling = 1;
|
pooling = 1;
|
||||||
|
@ -630,6 +642,8 @@ static int reload(void)
|
||||||
password = v->value;
|
password = v->value;
|
||||||
} else if (!strcasecmp(v->name, "sanitysql")) {
|
} else if (!strcasecmp(v->name, "sanitysql")) {
|
||||||
sanitysql = v->value;
|
sanitysql = v->value;
|
||||||
|
} else if (!strcasecmp(v->name, "backslash_is_escape")) {
|
||||||
|
bse = ast_true(v->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,6 +700,8 @@ static int reload(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new->backslash_is_escape = bse;
|
||||||
|
|
||||||
if (class) {
|
if (class) {
|
||||||
ast_log(LOG_NOTICE, "Refreshing ODBC class '%s' dsn->[%s]\n", cat, dsn);
|
ast_log(LOG_NOTICE, "Refreshing ODBC class '%s' dsn->[%s]\n", cat, dsn);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue