[asterisk-commits] branch tilghman/res_odbc_rewrite r17027 - in
/team/tilghman/res_odbc_rewrite:...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Apr 3 00:04:17 MST 2006
Author: tilghman
Date: Mon Apr 3 02:04:15 2006
New Revision: 17027
URL: http://svn.digium.com/view/asterisk?rev=17027&view=rev
Log:
More error handling. Also, changes due to testing. Should be about ready for trunk.
Modified:
team/tilghman/res_odbc_rewrite/funcs/func_odbc.c
team/tilghman/res_odbc_rewrite/res/res_odbc.c
Modified: team/tilghman/res_odbc_rewrite/funcs/func_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/res_odbc_rewrite/funcs/func_odbc.c?rev=17027&r1=17026&r2=17027&view=diff
==============================================================================
--- team/tilghman/res_odbc_rewrite/funcs/func_odbc.c (original)
+++ team/tilghman/res_odbc_rewrite/funcs/func_odbc.c Mon Apr 3 02:04:15 2006
@@ -204,9 +204,9 @@
}
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
- odbc_obj_disconnect(obj);
+ odbc_release_obj(obj);
/* All handles are now invalid (after a disconnect), so we gotta redo all handles */
- odbc_obj_connect(obj);
+ obj = odbc_request_obj("asterisk", 1);
if (!retry) {
retry = 1;
goto retry_write;
Modified: team/tilghman/res_odbc_rewrite/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/res_odbc_rewrite/res/res_odbc.c?rev=17027&r1=17026&r2=17027&view=diff
==============================================================================
--- team/tilghman/res_odbc_rewrite/res/res_odbc.c (original)
+++ team/tilghman/res_odbc_rewrite/res/res_odbc.c Mon Apr 3 02:04:15 2006
@@ -258,11 +258,24 @@
break;
}
- ast_copy_string(new->name, cat, sizeof(new->name));
- ast_copy_string(new->dsn, dsn, sizeof(new->dsn));
- ast_copy_string(new->username, username, sizeof(new->username));
- ast_copy_string(new->password, password, sizeof(new->password));
+ if (cat)
+ ast_copy_string(new->name, cat, sizeof(new->name));
+ if (dsn)
+ ast_copy_string(new->dsn, dsn, sizeof(new->dsn));
+ if (username)
+ ast_copy_string(new->username, username, sizeof(new->username));
+ if (password)
+ ast_copy_string(new->password, password, sizeof(new->password));
+
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &new->env);
+ res = SQLSetEnvAttr(new->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
+
+ if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+ ast_log(LOG_WARNING, "res_odbc: Error SetEnv\n");
+ SQLFreeHandle(SQL_HANDLE_ENV, new->env);
+ return res;
+ }
+
if (pooling) {
new->haspool = pooling;
if (limit) {
@@ -407,8 +420,13 @@
}
ast_mutex_init(&obj->lock);
obj->parent = class;
- odbc_obj_connect(obj);
- AST_LIST_INSERT_HEAD(&class->odbc_obj, obj, list);
+ if (odbc_obj_connect(obj) == ODBC_FAIL) {
+ ast_log(LOG_WARNING, "Failed to connect\n");
+ ast_mutex_destroy(&obj->lock);
+ free(obj);
+ } else {
+ AST_LIST_INSERT_HEAD(&class->odbc_obj, obj, list);
+ }
}
}
AST_LIST_UNLOCK(&class->odbc_obj);
@@ -443,28 +461,34 @@
SQLINTEGER err;
short int mlen;
unsigned char msg[200], stat[10];
-
+#ifdef NEEDTRACE
+ SQLINTEGER enable = 1;
+ char *tracefile = "/tmp/odbc.trace";
+#endif
ast_mutex_lock(&obj->lock);
res = SQLAllocHandle(SQL_HANDLE_DBC, obj->parent->env, &obj->con);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- if (option_verbose > 3)
- ast_log(LOG_WARNING, "res_odbc: Error AllocHDB %d\n", res);
+ ast_log(LOG_WARNING, "res_odbc: Error AllocHDB %d\n", res);
SQLFreeHandle(SQL_HANDLE_ENV, obj->parent->env);
ast_mutex_unlock(&obj->lock);
return ODBC_FAIL;
}
SQLSetConnectAttr(obj->con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *) 10, 0);
+#ifdef NEEDTRACE
+ SQLSetConnectAttr(obj->con, SQL_ATTR_TRACE, &enable, SQL_IS_INTEGER);
+ SQLSetConnectAttr(obj->con, SQL_ATTR_TRACEFILE, tracefile, strlen(tracefile));
+#endif
if (obj->up) {
odbc_obj_disconnect(obj);
ast_log(LOG_NOTICE, "Re-connecting %s\n", obj->parent->name);
- }
-
- ast_log(LOG_NOTICE, "Connecting %s\n", obj->parent->name);
+ } else {
+ ast_log(LOG_NOTICE, "Connecting %s\n", obj->parent->name);
+ }
res = SQLConnect(obj->con,
(SQLCHAR *) obj->parent->dsn, SQL_NTS,
More information about the asterisk-commits
mailing list