--- asterisk/apps/app_sql_postgres.c 2004-04-29 22:27:35.000000000 -0700 +++ asterisk_patched/apps/app_sql_postgres.c 2004-06-15 19:31:59.000000000 -0700 @@ -29,7 +29,7 @@ #include #include "libpq-fe.h" - +#define EXTRA_LOG 0 static char *tdesc = "Simple PostgreSQL Interface"; @@ -250,6 +250,7 @@ static int aPGSQL_query(struct ast_channel *chan, void *data) { + char *s1,*s2,*s3,*s4,*s5; char s[100]; char *querystring; @@ -303,13 +304,14 @@ free(s1); free(s2); + return(res); } static int aPGSQL_fetch(struct ast_channel *chan, void *data) { - char *s1,*s2,*s3,*s4,*s5,*s6,*s7; + char *s1,*s2,*fetchid_var,*s4,*s5,*s6,*s7; char s[100]; char *var; int l; @@ -332,13 +334,13 @@ strcpy(s1,data); stringp=s1; strsep(&stringp," "); // eat the first token, we already know it :P - s3=strsep(&stringp," "); + fetchid_var=strsep(&stringp," "); while (1) { // ugly trick to make branches with break; - var=s3; // fetchid + var=fetchid_var; // fetchid fnd=0; AST_LIST_TRAVERSE(headp,variables,entries) { - if (strncasecmp(ast_var_name(variables),s3,strlen(s3))==0) { + if (strncasecmp(ast_var_name(variables),fetchid_var,strlen(fetchid_var))==0) { s7=ast_var_value(variables); fnd=1; break; @@ -347,7 +349,7 @@ if (fnd==0) { s7="0"; - pbx_builtin_setvar_helper(chan,s3,s7); + pbx_builtin_setvar_helper(chan,fetchid_var,s7); } s4=strsep(&stringp," "); @@ -359,12 +361,14 @@ } id=atoi(s7); //fetchid if ((lalares=find_identifier(id,AST_PGSQL_ID_FETCHID))==NULL) { - i=0; + i=0; // fetching the very first row } else { i=*lalares; free(lalares); - del_identifier(id,AST_PGSQL_ID_FETCHID); + del_identifier(id,AST_PGSQL_ID_FETCHID); // will re-add it a bit later } + + if (i