return -1;
}
- obj = odbc_request_obj(query->dsn, 0);
+ obj = ast_odbc_request_obj(query->dsn, 0);
if (!obj) {
ast_log(LOG_ERROR, "No database handle available with the name of '%s' (check res_odbc.conf)\n", query->dsn);
AST_LIST_UNLOCK(&queries);
- stmt = odbc_prepare_and_execute(obj, generic_prepare, buf);
+ stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, buf);
if (stmt) {
/* Rows affected */
if (stmt)
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
if (obj)
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return 0;
}
return -1;
}
- obj = odbc_request_obj(query->dsn, 0);
+ obj = ast_odbc_request_obj(query->dsn, 0);
if (!obj) {
ast_log(LOG_ERROR, "No such DSN registered (or out of connections): %s (check res_odbc.conf)\n", query->dsn);
AST_LIST_UNLOCK(&queries);
- stmt = odbc_prepare_and_execute(obj, generic_prepare, sql);
+ stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, sql);
if (!stmt) {
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return -1;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return -1;
}
ast_log(LOG_WARNING, "Error %d in FETCH [%s]\n", res, sql);
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return res1;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return -1;
}
buf[buflen - 1] = '\0';
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return 0;
}
* This function really only ever worked with MySQL, where the statement handle is
* not prepared on the server. If you are not using MySQL, you should avoid it.
*/
-int odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt); /* DEPRECATED */
+int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt); /* DEPRECATED */
/*! \brief Retrieves a connected ODBC object
* \param name The name of the ODBC class for which a connection is needed.
* thread which requests it. Note that all connections should be released
* when the thread is done by calling odbc_release_obj(), below.
*/
-struct odbc_obj *odbc_request_obj(const char *name, int check);
+struct odbc_obj *ast_odbc_request_obj(const char *name, int check);
/*! \brief Releases an ODBC object previously allocated by odbc_request_obj()
* \param obj The ODBC object
*/
-void odbc_release_obj(struct odbc_obj *obj);
+void ast_odbc_release_obj(struct odbc_obj *obj);
/*! \brief Checks an ODBC object to ensure it is still connected
* \param obj The ODBC object
* \return Returns 0 if connected, -1 otherwise.
*/
-int odbc_sanity_check(struct odbc_obj *obj);
+int ast_odbc_sanity_check(struct odbc_obj *obj);
/*! \brief Prepares, executes, and returns the resulting statement handle.
* \param obj The ODBC object
* \param data A parameter to be passed to the prepare_cb parameter function, indicating which statement handle is to be prepared.
* \return Returns a statement handle or NULL on error.
*/
-SQLHSTMT odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data);
+SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data);
#endif /* _ASTERISK_RES_ODBC_H */
if (!table)
return NULL;
- obj = odbc_request_obj(database, 0);
+ obj = ast_odbc_request_obj(database, 0);
if (!obj)
return NULL;
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
newparam = va_arg(aq, const char *);
if (!newparam) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
newval = va_arg(aq, const char *);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
}
- res = odbc_smart_execute(obj, stmt);
+ res = ast_odbc_smart_execute(obj, stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
res = SQLFetch(stmt);
if (res == SQL_NO_DATA) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
for (x = 0; x < colcount; x++) {
ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
if (var)
ast_variables_destroy(var);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
if (var)
ast_variables_destroy(var);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
stringp = rowdata;
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return var;
}
return NULL;
memset(&ra, 0, sizeof(ra));
- obj = odbc_request_obj(database, 0);
+ obj = ast_odbc_request_obj(database, 0);
if (!obj)
return NULL;
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
newparam = va_arg(aq, const char *);
if (!newparam) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
initfield = ast_strdupa(newparam);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
}
- res = odbc_smart_execute(obj, stmt);
+ res = ast_odbc_smart_execute(obj, stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
if (!cfg) {
ast_log(LOG_WARNING, "Out of memory!\n");
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return cfg;
}
if (!table)
return -1;
- obj = odbc_request_obj(database, 0);
+ obj = ast_odbc_request_obj(database, 0);
if (!obj)
return -1;
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return -1;
}
newparam = va_arg(aq, const char *);
if (!newparam) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return -1;
}
newval = va_arg(aq, const char *);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return -1;
}
SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(lookup), 0, (void *)lookup, 0, NULL);
- res = odbc_smart_execute(obj, stmt);
+ res = ast_odbc_smart_execute(obj, stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return -1;
}
res = SQLRowCount(stmt, &rowcount);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
if (!file || !strcmp (file, "res_config_odbc.conf"))
return NULL; /* cant configure myself with myself ! */
- obj = odbc_request_obj(database, 0);
+ obj = ast_odbc_request_obj(database, 0);
if (!obj)
return NULL;
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE filename='%s' and commented=0 ORDER BY filename,cat_metric desc,var_metric asc,category,var_name,var_val,id", table, file);
q.sql = sql;
- stmt = odbc_prepare_and_execute(obj, config_odbc_prepare, &q);
+ stmt = ast_odbc_prepare_and_execute(obj, config_odbc_prepare, &q);
if (!stmt) {
ast_log(LOG_WARNING, "SQL select error!\n[%s]\n\n", sql);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL NumResultCols error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
if (!rowcount) {
ast_log(LOG_NOTICE, "found nothing\n");
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return cfg;
}
if (!strcmp (q.var_name, "#include")) {
if (!ast_config_internal_load(q.var_val, cfg, 0)) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return NULL;
}
continue;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_release_obj(obj);
+ ast_odbc_release_obj(obj);
return cfg;
}
static int odbc_register_class(struct odbc_class *class, int connect);
-SQLHSTMT odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data)
+SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data)
{
int res = 0, i, attempt;
SQLINTEGER nativeerror=0, numfields=0;
return stmt;
}
-int odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt)
+int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt)
{
int res = 0, i;
SQLINTEGER nativeerror=0, numfields=0;
}
-int odbc_sanity_check(struct odbc_obj *obj)
+int ast_odbc_sanity_check(struct odbc_obj *obj)
{
char *test_sql = "select 1";
SQLHSTMT stmt;
ast_cli(fd, "Pooled: yes\nLimit: %d\nConnections in use: %d\n", class->limit, class->count);
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
- ast_cli(fd, " Connection %d: %s", ++count, current->up && odbc_sanity_check(current) ? "connected" : "disconnected");
+ ast_cli(fd, " Connection %d: %s", ++count, current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
}
} else {
/* Should only ever be one of these */
AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
- ast_cli(fd, "Pooled: no\nConnected: %s\n", current->up && odbc_sanity_check(current) ? "yes" : "no");
+ ast_cli(fd, "Pooled: no\nConnected: %s\n", current->up && ast_odbc_sanity_check(current) ? "yes" : "no");
}
}
if (connect) {
/* Request and release builds a connection */
- obj = odbc_request_obj(class->name, 0);
- odbc_release_obj(obj);
+ obj = ast_odbc_request_obj(class->name, 0);
+ ast_odbc_release_obj(obj);
}
return 0;
}
}
-void odbc_release_obj(struct odbc_obj *obj)
+void ast_odbc_release_obj(struct odbc_obj *obj)
{
/* For pooled connections, this frees the connection to be
* reused. For non-pooled connections, it does nothing. */
obj->used = 0;
}
-struct odbc_obj *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_class *class;
AST_LIST_UNLOCK(&class->odbc_obj);
if (obj && check) {
- odbc_sanity_check(obj);
+ ast_odbc_sanity_check(obj);
}
return obj;
}