|
|
|
|
@ -382,6 +382,9 @@ static struct columns *find_column(struct tables *t, const char *colname)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define IS_SQL_LIKE_CLAUSE(x) ((x) && ast_ends_with(x, " LIKE"))
|
|
|
|
|
static char *ESCAPE_CLAUSE = " ESCAPE '\\'";
|
|
|
|
|
|
|
|
|
|
static struct ast_variable *realtime_pgsql(const char *database, const char *tablename, const struct ast_variable *fields)
|
|
|
|
|
{
|
|
|
|
|
RAII_VAR(PGresult *, result, NULL, PQclear);
|
|
|
|
|
@ -391,6 +394,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
|
|
|
|
|
char *stringp;
|
|
|
|
|
char *chunk;
|
|
|
|
|
char *op;
|
|
|
|
|
char *escape = "";
|
|
|
|
|
const struct ast_variable *field = fields;
|
|
|
|
|
struct ast_variable *var = NULL, *prev = NULL;
|
|
|
|
|
|
|
|
|
|
@ -418,7 +422,14 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
|
|
|
|
|
|
|
|
|
|
/* Create the first part of the query using the first parameter/value pairs we just extracted
|
|
|
|
|
If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
|
|
|
|
|
op = strchr(field->name, ' ') ? "" : " =";
|
|
|
|
|
if (!strchr(field->name, ' ')) {
|
|
|
|
|
op = " =";
|
|
|
|
|
} else {
|
|
|
|
|
op = "";
|
|
|
|
|
if (IS_SQL_LIKE_CLAUSE(field->name)) {
|
|
|
|
|
escape = ESCAPE_CLAUSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESCAPE_STRING(escapebuf, field->value);
|
|
|
|
|
if (pgresult) {
|
|
|
|
|
@ -426,12 +437,17 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'", tablename, field->name, op, ast_str_buffer(escapebuf));
|
|
|
|
|
ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'%s", tablename, field->name, op, ast_str_buffer(escapebuf), escape);
|
|
|
|
|
while ((field = field->next)) {
|
|
|
|
|
if (!strchr(field->name, ' '))
|
|
|
|
|
escape = "";
|
|
|
|
|
if (!strchr(field->name, ' ')) {
|
|
|
|
|
op = " =";
|
|
|
|
|
else
|
|
|
|
|
} else {
|
|
|
|
|
op = "";
|
|
|
|
|
if (IS_SQL_LIKE_CLAUSE(field->name)) {
|
|
|
|
|
escape = ESCAPE_CLAUSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESCAPE_STRING(escapebuf, field->value);
|
|
|
|
|
if (pgresult) {
|
|
|
|
|
@ -439,7 +455,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_str_append(&sql, 0, " AND %s%s '%s'", field->name, op, ast_str_buffer(escapebuf));
|
|
|
|
|
ast_str_append(&sql, 0, " AND %s%s '%s'%s", field->name, op, ast_str_buffer(escapebuf), escape);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We now have our complete statement; Lets connect to the server and execute it. */
|
|
|
|
|
@ -505,6 +521,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
|
|
|
|
|
char *stringp;
|
|
|
|
|
char *chunk;
|
|
|
|
|
char *op;
|
|
|
|
|
char *escape = "";
|
|
|
|
|
struct ast_variable *var = NULL;
|
|
|
|
|
struct ast_config *cfg = NULL;
|
|
|
|
|
struct ast_category *cat = NULL;
|
|
|
|
|
@ -543,10 +560,15 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
|
|
|
|
|
/* Create the first part of the query using the first parameter/value pairs we just extracted
|
|
|
|
|
If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
|
|
|
|
|
|
|
|
|
|
if (!strchr(field->name, ' '))
|
|
|
|
|
if (!strchr(field->name, ' ')) {
|
|
|
|
|
op = " =";
|
|
|
|
|
else
|
|
|
|
|
escape = "";
|
|
|
|
|
} else {
|
|
|
|
|
op = "";
|
|
|
|
|
if (IS_SQL_LIKE_CLAUSE(field->name)) {
|
|
|
|
|
escape = ESCAPE_CLAUSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESCAPE_STRING(escapebuf, field->value);
|
|
|
|
|
if (pgresult) {
|
|
|
|
|
@ -555,12 +577,18 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'", table, field->name, op, ast_str_buffer(escapebuf));
|
|
|
|
|
ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'%s", table, field->name, op, ast_str_buffer(escapebuf), escape);
|
|
|
|
|
while ((field = field->next)) {
|
|
|
|
|
if (!strchr(field->name, ' '))
|
|
|
|
|
escape = "";
|
|
|
|
|
if (!strchr(field->name, ' ')) {
|
|
|
|
|
op = " =";
|
|
|
|
|
else
|
|
|
|
|
escape = "";
|
|
|
|
|
} else {
|
|
|
|
|
op = "";
|
|
|
|
|
if (IS_SQL_LIKE_CLAUSE(field->name)) {
|
|
|
|
|
escape = ESCAPE_CLAUSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESCAPE_STRING(escapebuf, field->value);
|
|
|
|
|
if (pgresult) {
|
|
|
|
|
@ -569,7 +597,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_str_append(&sql, 0, " AND %s%s '%s'", field->name, op, ast_str_buffer(escapebuf));
|
|
|
|
|
ast_str_append(&sql, 0, " AND %s%s '%s'%s", field->name, op, ast_str_buffer(escapebuf), escape);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (initfield) {
|
|
|
|
|
|