[Asterisk-cvs] asterisk/res res_config_odbc.c,1.9,1.10

markster at lists.digium.com markster at lists.digium.com
Thu Oct 7 15:56:35 CDT 2004


Update of /usr/cvsroot/asterisk/res
In directory mongoose.digium.com:/tmp/cvs-serv19554/res

Modified Files:
	res_config_odbc.c 
Log Message:
Oops, we have to be able to pass multiple restrictions for when we go to voicemail...


Index: res_config_odbc.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_config_odbc.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- res_config_odbc.c	5 Oct 2004 06:46:11 -0000	1.9
+++ res_config_odbc.c	7 Oct 2004 19:57:50 -0000	1.10
@@ -31,13 +31,14 @@
 
 LOCAL_USER_DECL;
 
-static struct ast_variable *realtime_odbc(const char *database, const char *table, const char *keyfield, const char *lookup)
+static struct ast_variable *realtime_odbc(const char *database, const char *table, va_list ap)
 {
 	odbc_obj *obj;
 	SQLHSTMT stmt;
 	char sql[256];
 	char coltitle[256];
 	char rowdata[2048];
+	const char *newparam, *newval;
 	char *stringp;
 	char *chunk;
 	SQLSMALLINT collen;
@@ -50,6 +51,10 @@
 	SQLSMALLINT datatype;
 	SQLSMALLINT decimaldigits;
 	SQLSMALLINT nullable;
+	va_list aq;
+	
+	va_copy(aq, ap);
+	
 	
 	if (!table)
 		return NULL;
@@ -64,7 +69,19 @@
 		return NULL;
 	}
 
-	snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s=?", table, keyfield);
+	newparam = va_arg(aq, const char *);
+	if (!newparam)  {
+		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+		return NULL;
+	}
+	newval = va_arg(aq, const char *);
+	
+	snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s=?", table, newparam);
+	while((newparam = va_arg(aq, const char *))) {
+		snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " AND %s=?", newparam);
+		newval = va_arg(aq, const char *);
+	}
+	va_end(aq);
 	
 	res = SQLPrepare(stmt, sql, SQL_NTS);
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
@@ -72,8 +89,15 @@
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 		return NULL;
 	}
-	SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(lookup), 0, (void *)lookup, 0, NULL);
+	
+	/* Now bind the parameters */
+	x = 1;
 
+	while((newparam = va_arg(ap, const char *))) {
+		newval = va_arg(ap, const char *);
+		SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
+	}
+		
 	res = SQLExecute(stmt);
 
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {




More information about the svn-commits mailing list