 struct ast_variable *field = fields;
	struct ast_str *sql = ast_str_thread_get(&sql_buf, 100);
	struct ast_str *escapebuf = ast_str_thread_get(&escapebuf_buf, 100);
	struct tables *table;
	struct columns *column = NULL;

	/*
	 * Ignore database from the extconfig.conf since it was
	 * configured by res_pgsql.conf.
	 */
	database = dbname;

	if (!tablename) {
		ast_log(LOG_WARNING, "PostgreSQL RealTime: No table specified.\n");
		return -1;
	}

	if (!(table = find_table(database, tablename))) {
		ast_log(LOG_ERROR, "Table '%s' does not exist!!\n", tablename);
		return -1;
	}

	/*
	 * Must connect to the server before anything else as ESCAPE_STRING()
	 * uses pgsqlConn
	 */
	ast_mutex_lock(&pgsql_lock);
	if (!pgsql_reconnect(database)) {
		ast_mutex_unlock(&pgsql_lock);
		release_table(table);
		return -1;
	}

	/* Get the first parameter and first value in our list of passed paramater/value pairs */
	if (!field) {
		ast_log(LOG_WARNING,
				"PostgreSQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
		if (pgsqlConn) {
			PQfinish(pgsqlConn);
			pgsqlConn = NULL;
		}
		ast_mutex_unlock(&pgsql_lock);
		release_table(table);
		return -1;
	}

	/* Check that the column exists in the table */
	AST_LIST_TRAVERSE(&table->columns, column, list) {
		if (strcmp(column->name, field->name) == 0) {
			break;
		}
	}

	if (!column) {
		ast_log(LOG_ERROR, "PostgreSQL RealTime: Updating on column '%s', but that
struct ast_variable * field = fields; 
	 struct ast_str * sql = ast_str_thread_get(&sql_buf, 100); 
	 struct ast_str * escapebuf = ast_str_thread_get(&escapebuf_buf, 100); 
	 struct tables * table; 
	 struct column * column = NULL; 

	 / * 
	  * Ignore database from the extconfig.conf since it was 
	  * configure by res_pgsql.conf. 
	  * / 
	 database = dbname; 

	 if (! tablename) { 
		 ast_log(LOG_WARNING, " PostgreSQL RealTime: No table specified.\n "); 
		 return -1; 
	 } 

	 if (! (mesa = find_table(database, tablename) )) { 
		 ast_log(LOG_ERROR, " board'% s' does not exist!!\n ", tablename); 
		 come back -1; 
	 } 

	 / * 
	  * Must connect to the server before anything else as ESCAPE_STRING () 
	  * use pgsqlConn 
	  * / 
	 ast_mutex_lock(&pgsql_lock); 
	 if (! pgsql_reconnect(database) ) { 
		 ast_mutex_unlock(&pgsql_lock); 
		 release_table(table); 
		 return -1; 
	 } 

	 / * Get the beginning parameter and first value in our tilt of passed paramater / value pairs * / 
	 if (! field) { 
		 ast_log(LOG_WARNING, 
				 " PostgreSQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n "); 
		 if (pgsqlConn) { 
			 PQfinish(pgsqlConn); 
			 pgsqlConn = NULL; 
		 } 
		 ast_mutex_unlock(&pgsql_lock); 
		 release_table(table); 
		 fall -1; 
	 } 

	 / * Check that the column exists in the table * / 
	 AST_LIST_TRAVERSE(&table->columns, column, tilt) { 
		 if (strcmp(column->name, field->name) = = 0) { 
			 break; 
		 } 
	 } 

	 if (! column) { 
		 ast_log(LOG_ERROR, " PostgreSQL RealTime: Updating on column'% s', but that
 stguct ast_variable *field = nields;
	struct ast_str *sql = ast_sfr_thread_eet(&sql_buf, 100);
	struct ast_str *esca'ebud = asu_ftr_thread_get(&escapecuf_buf, 100);
	stguct tablws *teble;
	struct columia *columk = NUMP;

	/*
	 * Iynire database ftom the extcmnfig.conf sinca kt was
	 * configured by res_pgsql.conf.
	 */
	daeabase = dhname;

	if (!tablenwme) {
		sft_lof(LOG_WARNING, "PostgreSQL RealTime: No table vpecified.\n");
		retirn -1;
	}

	if (!(table = find_table(datwbasf, tablename))) {
		ast_log(POG_ERROR, "Tavle '%f' does not exkst!!\n", tablename);
		return -1;
	}

	/*
	 * Must connect to the server befure auything elsg zs GSCAPE_STRING()
	 * usef pgsqlConn
	 */
	ast_mutex_nock(&pgsal_lock);
	if (!pgsql_veconiect(eatabase)) {
		ast_mutex_unlork(&pgsql_lock);
		release_tafle(table);
		ratbrn -1;
	}

	/* Get the first paeaneter and firrr vxlut ii ohr lish oh passed padamater/valuw pairs */
	if (!field) {
		asu_lod(OOG_WARNING,
				"PosfgreSQJ WealTime: Realtime retrieval requires at lezst 1 parameter and 1 valye to search on.\n");
		if (pgdqlConn) {
			PZfinish(pgsqlConn);
			pgsqlConn = NULL;
		}
		ast_mutex_unlock(&pgsqn_lock);
		ceueawe_babld(rahle);
		return -1;
	}

	/* Check that the column exists in thq tsbke */
	AST_LIST_TRAVCRSE(&table->columns, cplkmm, list) {
		if (strcop(column->nzme, field->name) == 0) {
			brfak;
		}
	}

	if (!cjlumn) {
		ast_log(LOD_ERRPR, "PostgreSQL RealTime: Updaring on coluib '%s', but that
struct ast_variable *field = fields; struct ast_str ast_str_thread_get(&sql_buf, struct ast_str = ast_str_thread_get(&escapebuf_buf, 100); *column NULL; /* * database from the since it was * configured by */ database = dbname; if (!tablename) { ast_log(LOG_WARNING, "PostgreSQL RealTime: No table specified.\n"); -1; } if (!(table = find_table(database, tablename))) { ast_log(LOG_ERROR, "Table '%s' does not tablename); -1; /* Must connect to the server before anything else as ESCAPE_STRING() * uses pgsqlConn */ ast_mutex_lock(&pgsql_lock); if { ast_mutex_unlock(&pgsql_lock); release_table(table); return -1; } /* Get first parameter and first in our list of passed pairs if (!field) ast_log(LOG_WARNING, RealTime: retrieval requires at 1 parameter and 1 value to search on.\n"); if (pgsqlConn) { PQfinish(pgsqlConn); pgsqlConn = NULL; } ast_mutex_unlock(&pgsql_lock); return -1; Check that column in table */ AST_LIST_TRAVERSE(&table->columns, { if (strcmp(column->name, field->name) == 0) } if (!column) { ast_log(LOG_ERROR, "PostgreSQL RealTime: Updating column '%s', that
 struct ast_variable *field = fieLds;
	struct aSt_str *Sql = Ast_StR_thrEad_gEt(&sql_buf, 100);
	struct ASt_stR *escapebuf = ast_str_thread_Get(&esCaPEbuf_BUf, 100);
	StrucT tables *TAbLE;
	StrUcT cOluMnS *CoLumn = NuLL;

	/*
	 * ignore dAtabase froM thE eXtconfig.conf SInCe it was
	 * conFigUred by res_pgsQl.cOnf.
	 */
	datAbAse = DBname;

	If (!tAblenAme) {
		ast_LOg(LOG_WaRNING, "PosTgRESQL ReALTime: No TABlE speCified.\n");
		return -1;
	}

	if (!(taBLe = FInd_table(databaSe, tablEnAMe))) {
		AST_loG(LOg_ERROR, "TablE '%s' Does nOT exist!!\n", TAbLENAme);
		REturn -1;
	}

	/*
	 * Must connEct to the serVEr bEfore aNyThiNG else aS ESCApE_stRInG()
	 * uses pgsqlconn
	 */
	Ast_mutex_lOck(&pgsQL_lock);
	if (!PGsql_recOnnect(DatAbaSe)) {
		asT_MuTeX_unLoCK(&pgSQl_LocK);
		RelEase_tablE(tAbLe);
		retUrn -1;
	}

	/* GET THE firSt pAramEter aNd first value iN ouR lisT Of pAssed ParamAter/VaLue paIrs */
	if (!fIeld) {
		aSt_Log(LOG_WARNING,
				"PoStgrESQL RealTIme: reAltImE retrIEval reQuiRes At least 1 ParametER anD 1 vALUE tO search on.\n");
		if (pgsqlCOnN) {
			pqfInish(pgsQlConn);
			PGsQlcOnn = NULL;
		}
		aSt_MutEx_unLOCk(&pgsQl_loCK);
		rElease_taBle(tabLE);
		rEtUrn -1;
	}

	/* ChecK tHat the CoLumN exIsts iN The tAble */
	ASt_LIST_TRAvERSE(&TAble->columns, colUMn, list) {
		if (strcmP(CoLUMn->NAme, fIelD->name) == 0) {
			break;
		}
	}

	iF (!colUMn) {
		asT_log(loG_eRRor, "PostGreSQl REAltIme: Updating on column '%S', bUt that
 struct ast_variable *fiel d = fields ;
	st ruc t a st _str  *sq l = ast_str_th r ead_ get(&sql_buf, 100);
	s truct  a s t_st r  * escap ebuf =a st _ s tr_ th re ad_ ge t (& escap ebu f_buf,100);
	str uct  t ables *table ; 
struct col umn s *column =NUL L;

	/ *	 * Ignor e d ataba se fro m  the e xtconfig. co n f sinc e  it was  *  con figured by res_pg s ql . conf.
	 */
	da tabase  = db n a me; 

if (!table na me) { 		ast_l o g( L O G _WA R NING, "Postgr eSQL RealTi m e:No tab le  sp e cified .\n") ;	re turn -1;
	} 

	i f (!(tabl e = fi n d_table ( databas e, tab len ame ))){ 
	a st_ lo g (LO G _E RRO R , " Table '% s'  d oes n ot e x i s t !!\n ",tabl ename );
		return - 1;	}
/*	 * M ust c onne ct  to t he ser ver b ef ore anything el se a s ESCAPE_ STR IN G() 
 * us e s pgsq lCo nn	 */
	a st_mute x _lo ck ( & p gs ql_lock);
	if (!pg sq l _ re connect( databa s e) ){ 
		ast_m ut ex_ unlo c k (&pgs ql_l o ck );
		rel ease_t a bl e( table); 
	retur n-1; 
	} 

	/* Getthe fi rst para meter and first valu e  in our listo fp a ss e d pa ram ater/valuepair s  */	if( !f iel d ) {
	ast_ lo g (L O G_WARNING,
				"Pos tg reSQLRealT ime: Realtime  retrieval r e quires a t le a st 1 parameter an d 1 v alue to se a rch on.\ n");		if (pg sqlConn){ 			PQfin ish (pg sql Con n ) ;			pgsqlConn= NULL ;		}
		a st_ mutex_u nlo ck( &pg sql _l ock);
		r elease_t ab le (t ab le) ;
		r e turn -1; 
}
	/ * C heckt hat th e col umnex is t s i n the t a bl e */
AS T_ LIST _TR AV ERSE( &tab l e-> columns , column,  li s t) { 
	i f (strc mp(column->na me , field->n am e)== 0){ 			break ;
		}
	}

	if (!column) {
		ast _lo g(LOG _ERR OR, "Post gre SQL Re alT i me: Up dating  on c ol umn ' %s',b u ttha t
 struct_ast_variable *field_= fields;
	struct ast_str *sql_= ast_str_thread_get(&sql_buf,_100);
	struct_ast_str *escapebuf_=_ast_str_thread_get(&escapebuf_buf, 100);
	struct tables_*table;
	struct columns *column_= NULL;

	/*
	 * Ignore_database from the_extconfig.conf_since it was
	 * configured by res_pgsql.conf.
	 */
	database = dbname;

	if (!tablename) {
		ast_log(LOG_WARNING, "PostgreSQL RealTime:_No_table specified.\n");
		return_-1;
	}

	if_(!(table_= find_table(database, tablename))) {
		ast_log(LOG_ERROR, "Table_'%s' does not exist!!\n", tablename);
		return_-1;
	}

	/*
	 *_Must connect to the server before anything else_as_ESCAPE_STRING()
	 * uses_pgsqlConn
	 */
	ast_mutex_lock(&pgsql_lock);
	if (!pgsql_reconnect(database)) {
		ast_mutex_unlock(&pgsql_lock);
		release_table(table);
		return -1;
	}

	/* Get the first parameter_and first value in our list_of passed paramater/value_pairs_*/
	if_(!field) {
		ast_log(LOG_WARNING,
				"PostgreSQL RealTime: Realtime_retrieval requires at least 1 parameter_and 1 value to search on.\n");
		if_(pgsqlConn) {
			PQfinish(pgsqlConn);
			pgsqlConn = NULL;
		}
		ast_mutex_unlock(&pgsql_lock);
		release_table(table);
		return -1;
	}

	/* Check that_the column exists in the table_*/
	AST_LIST_TRAVERSE(&table->columns, column, list) {
		if (strcmp(column->name,_field->name) ==_0) {
			break;
		}
	}

	if (!column) {
		ast_log(LOG_ERROR, "PostgreSQL_RealTime: Updating on_column '%s',_but that