[svn-commits] tilghman: trunk r47530 - in /trunk: configs/res_odbc.conf.sample res/res_odbc.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Nov 12 22:58:15 MST 2006


Author: tilghman
Date: Sun Nov 12 23:58:14 2006
New Revision: 47530

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47530
Log:
Feature:  allow the sanity SQL to be customized per connection class (Issue 6453)

Modified:
    trunk/configs/res_odbc.conf.sample
    trunk/res/res_odbc.c

Modified: trunk/configs/res_odbc.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/res_odbc.conf.sample?view=diff&rev=47530&r1=47529&r2=47530
==============================================================================
--- trunk/configs/res_odbc.conf.sample (original)
+++ trunk/configs/res_odbc.conf.sample Sun Nov 12 23:58:14 2006
@@ -15,6 +15,10 @@
 ;username => myuser
 ;password => mypass
 pre-connect => yes
+; What should we execute to ensure that our connection is still alive?  The
+; statement should return a non-zero value in the first field of its first
+; record.  The default is "select 1".
+;sanitysql => select 1
 
 
 [mysql2]
@@ -35,7 +39,7 @@
 username => oscar
 password => thegrouch
 pre-connect => yes
+sanitysql => select count(*) from systables
 
 
 
-

Modified: trunk/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_odbc.c?view=diff&rev=47530&r1=47529&r2=47530
==============================================================================
--- trunk/res/res_odbc.c (original)
+++ trunk/res/res_odbc.c Sun Nov 12 23:58:14 2006
@@ -60,6 +60,7 @@
 	char dsn[80];
 	char username[80];
 	char password[80];
+	char sanitysql[256];
 	SQLHENV env;
 	unsigned int haspool:1;         /* Boolean - TDS databases need this */
 	unsigned int limit:10;          /* Gives a limit of 1023 maximum */
@@ -115,17 +116,12 @@
 				 * While this isn't the best way to try to correct an error, this won't automatically
 				 * fail when the statement handle invalidates.
 				 */
-				/* XXX Actually, it might, if we're using a non-pooled connection. Possible race here. XXX */
-				odbc_obj_disconnect(obj);
-				odbc_obj_connect(obj);
+				ast_odbc_sanity_check(obj);
 				continue;
 			}
 			break;
-		} else {
-			ast_log(LOG_WARNING, "SQL Prepare failed.  Attempting a reconnect...\n");
-			odbc_obj_disconnect(obj);
-			odbc_obj_connect(obj);
-		}
+		} else if (attempt == 0)
+			ast_odbc_sanity_check(obj);
 	}
 
 	return stmt;
@@ -179,6 +175,9 @@
 	SQLHSTMT stmt;
 	int res = 0;
 
+	if (obj->parent->sanitysql)
+		test_sql = obj->parent->sanitysql;
+
 	if (obj->up) {
 		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
@@ -210,7 +209,7 @@
 	static char *cfg = "res_odbc.conf";
 	struct ast_config *config;
 	struct ast_variable *v;
-	char *cat, *dsn, *username, *password;
+	char *cat, *dsn, *username, *password, *sanitysql;
 	int enabled, pooling, limit;
 	int connect = 0, res = 0;
 
@@ -229,7 +228,7 @@
 			}
 		} else {
 			/* Reset all to defaults for each class of odbc connections */
-			dsn = username = password = NULL;
+			dsn = username = password = sanitysql = NULL;
 			enabled = 1;
 			connect = 0;
 			pooling = 0;
@@ -258,6 +257,8 @@
 					username = v->value;
 				} else if (!strcasecmp(v->name, "password")) {
 					password = v->value;
+				} else if (!strcasecmp(v->name, "sanitysql")) {
+					sanitysql = v->value;
 				}
 			}
 
@@ -277,6 +278,8 @@
 					ast_copy_string(new->username, username, sizeof(new->username));
 				if (password)
 					ast_copy_string(new->password, password, sizeof(new->password));
+				if (sanitysql)
+					ast_copy_string(new->sanitysql, sanitysql, sizeof(new->sanitysql));
 
 				SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &new->env);
 				res = SQLSetEnvAttr(new->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
@@ -524,7 +527,7 @@
 	static char *cfg = "res_odbc.conf";
 	struct ast_config *config;
 	struct ast_variable *v;
-	char *cat, *dsn, *username, *password;
+	char *cat, *dsn, *username, *password, *sanitysql;
 	int enabled, pooling, limit;
 	int connect = 0, res = 0;
 
@@ -547,7 +550,7 @@
 				}
 			} else {
 				/* Reset all to defaults for each class of odbc connections */
-				dsn = username = password = NULL;
+				dsn = username = password = sanitysql = NULL;
 				enabled = 1;
 				connect = 0;
 				pooling = 0;
@@ -575,6 +578,8 @@
 						username = v->value;
 					} else if (!strcasecmp(v->name, "password")) {
 						password = v->value;
+					} else if (!strcasecmp(v->name, "sanitysql")) {
+						sanitysql = v->value;
 					}
 				}
 
@@ -606,6 +611,8 @@
 						ast_copy_string(new->username, username, sizeof(new->username));
 					if (password)
 						ast_copy_string(new->password, password, sizeof(new->password));
+					if (sanitysql)
+						ast_copy_string(new->sanitysql, sanitysql, sizeof(new->sanitysql));
 
 					if (!class) {
 						SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &new->env);



More information about the svn-commits mailing list