--- trunk/pgswish.c 2005/02/19 16:01:46 13 +++ trunk/pgswish.c 2005/02/19 20:59:17 14 @@ -36,6 +36,7 @@ SW_HANDLE swish_handle = NULL;/* Database handle */ SW_SEARCH search = NULL; /* search handle -- holds search parameters */ SW_RESULTS swish_results = NULL; /* results handle -- holds list of results */ +SW_RESULT *sw_res = NULL; /* one row from swish-e results */ /* define PostgreSQL v1 function */ PG_FUNCTION_INFO_V1(pgswish); @@ -130,7 +131,6 @@ char **values; HeapTuple tuple; Datum result; - SW_RESULT *sw_res; /* one row from swish-e results */ elog(INFO, "pgswish: loop count %d", call_cntr); @@ -139,7 +139,7 @@ SRF_RETURN_DONE(funcctx); } - elog(INFO, "pgswish: check for swish-e error"); + elog(DEBUG1, "pgswish: check for swish-e error"); error_or_abort( swish_handle ); /* @@ -211,17 +211,29 @@ } } -/* - * elog errors - * - */ +Datum swtextprop(PG_FUNCTION_ARGS) { + char *prop; + char *val; + + prop = _textout(PG_GETARG_TEXT_P(0)); + elog(INFO, "pgswish: swextprop(%s)", prop); + + val = prop2int( sw_res, prop ); + error_or_abort( swish_handle ); + + elog(INFO, "pgswish: swextprop(%s) = '%s'", prop, val ); + PG_FREE_IF_COPY(prop, 0); + PG_RETURN_TEXT_P( _textin(val) ); +} + +/* make text var prom property */ char *prop2text(SW_RESULT sw_res, char *propname) { char *val; char *prop; int len; - elog(INFO, "prop2text(%s)", propname); + elog(DEBUG1, "prop2text(%s)", propname); prop = SwishResultPropertyStr( sw_res, propname ); error_or_abort( swish_handle ); @@ -232,24 +244,25 @@ len++; len *= sizeof(char); - elog(INFO, "palloc(%d)", len); + elog(DEBUG1, "palloc(%d)", len); val = palloc(len); memset(val, 0, len); strncpy(val, prop, len); - elog(INFO, "val=%s", val); + elog(DEBUG1, "val=%s", val); return val; } +/* make integer variable from property */ char *prop2int(SW_RESULT sw_res, char *propname) { char *val; unsigned long prop; int len; - elog(INFO, "prop2int(%s)", propname); + elog(DEBUG1, "prop2int(%s)", propname); prop = SwishResultPropertyULong( sw_res, propname ); error_or_abort( swish_handle ); @@ -257,19 +270,22 @@ elog(INFO, "prop2int(%s) = %lu", propname, prop); len = 128 * sizeof(char); - elog(INFO, "palloc(%d)", len); + elog(DEBUG1, "palloc(%d)", len); val = palloc(len); memset(val, 0, len); snprintf(val, len, "%lu", prop); - elog(INFO, "val=%s", val); + elog(DEBUG1, "val=%s", val); return val; } +/* + * check if swish has returned error, and elog it. + */ static void error_or_abort( SW_HANDLE swish_handle ) { if ( !SwishError( swish_handle ) ) return; @@ -283,7 +299,5 @@ ); if ( search ) Free_Search_Object( search ); SwishClose( swish_handle ); - - /* do when there is no more left */ }