[asterisk-dev] tilghman: trunk r151682 - in /trunk: CHANGES funcs/func_odbc.c

Russell Bryant russell at digium.com
Thu Oct 23 07:28:54 CDT 2008


On Oct 22, 2008, at 5:11 PM, SVN commits to the Digium repositories  
wrote:

> Author: tilghman
> Date: Wed Oct 22 17:11:31 2008
> New Revision: 151682
>
> URL: http://svn.digium.com/view/asterisk?view=rev&rev=151682
> Log:
> Added debugging CLI functions
>
> Modified:
>    trunk/CHANGES
>    trunk/funcs/func_odbc.c
>

> +	if (a->argc == 5 && !strcmp(a->argv[4], "exec")) {
> +		/* Execute the query */
> +		struct odbc_obj *obj;
> +		int dsn, executed = 0;
> +		SQLHSTMT stmt;
> +		int rows = 0, res, x;
> +		SQLSMALLINT colcount = 0, collength;
> +		SQLLEN indicator;
> +
> +		for (dsn = 0; dsn < 5; dsn++) {
> +			if (!ast_strlen_zero(query->readhandle[dsn])) {
> +				ast_debug(1, "Found handle %s\n", query->readhandle[dsn]);
> +				if ((obj = ast_odbc_request_obj(query->readhandle[dsn], 0))) {
> +					ast_debug(1, "Got obj\n");
> +					if ((stmt = ast_odbc_direct_execute(obj, generic_execute, sql- 
> >str))) {

All of this code is seriously begging for some reduction of  
indentation.  Try using the reverse of a lot of this logic to return/ 
break/continue early instead of writing blocks like this.  (There are  
a couple of other places in here that I think could use similar  
cleanup.)

> +						res = SQLNumResultCols(stmt, &colcount);
> +						if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
> +							ast_cli(a->fd, "SQL Column Count error!\n[%s]\n\n", sql->str);
> +							SQLCloseCursor(stmt);
> +							SQLFreeHandle (SQL_HANDLE_STMT, stmt);
> +							ast_odbc_release_obj(obj);
> +							AST_RWLIST_UNLOCK(&queries);
> +						}

It looks like you missed a return or something in this block.

--
Russell Bryant
Senior Software Engineer
Open Source Team Lead
Digium, Inc.







More information about the asterisk-dev mailing list