/[pgswish]/trunk/pgswish.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/pgswish.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 13 by dpavlin, Sat Feb 19 16:01:46 2005 UTC revision 14 by dpavlin, Sat Feb 19 20:59:17 2005 UTC
# Line 36  Line 36 
36  SW_HANDLE   swish_handle = NULL;/* Database handle */  SW_HANDLE   swish_handle = NULL;/* Database handle */
37  SW_SEARCH   search = NULL;      /* search handle -- holds search parameters */  SW_SEARCH   search = NULL;      /* search handle -- holds search parameters */
38  SW_RESULTS  swish_results = NULL;       /* results handle -- holds list of results */  SW_RESULTS  swish_results = NULL;       /* results handle -- holds list of results */
39    SW_RESULT   *sw_res = NULL;     /* one row from swish-e results */
40    
41  /* define PostgreSQL v1 function */  /* define PostgreSQL v1 function */
42  PG_FUNCTION_INFO_V1(pgswish);  PG_FUNCTION_INFO_V1(pgswish);
# Line 130  Datum pgswish(PG_FUNCTION_ARGS) { Line 131  Datum pgswish(PG_FUNCTION_ARGS) {
131                  char            **values;                  char            **values;
132                  HeapTuple       tuple;                  HeapTuple       tuple;
133                  Datum           result;                  Datum           result;
                 SW_RESULT       *sw_res;        /* one row from swish-e results */  
134    
135                  elog(INFO, "pgswish: loop count %d", call_cntr);                  elog(INFO, "pgswish: loop count %d", call_cntr);
136    
# Line 139  Datum pgswish(PG_FUNCTION_ARGS) { Line 139  Datum pgswish(PG_FUNCTION_ARGS) {
139                          SRF_RETURN_DONE(funcctx);                          SRF_RETURN_DONE(funcctx);
140                  }                  }
141                                    
142                  elog(INFO, "pgswish: check for swish-e error");                  elog(DEBUG1, "pgswish: check for swish-e error");
143                  error_or_abort( swish_handle );                  error_or_abort( swish_handle );
144    
145                  /*                  /*
# Line 211  Datum pgswish(PG_FUNCTION_ARGS) { Line 211  Datum pgswish(PG_FUNCTION_ARGS) {
211          }          }
212  }  }
213    
214  /*  Datum swtextprop(PG_FUNCTION_ARGS) {
215   * elog errors          char    *prop;
216   *          char    *val;
217   */  
218            prop = _textout(PG_GETARG_TEXT_P(0));
219            elog(INFO, "pgswish: swextprop(%s)", prop);
220    
221            val = prop2int( sw_res, prop );
222            error_or_abort( swish_handle );
223    
224            elog(INFO, "pgswish: swextprop(%s) = '%s'", prop, val );
225    
226            PG_FREE_IF_COPY(prop, 0);
227            PG_RETURN_TEXT_P( _textin(val) );
228    }
229    
230    /* make text var prom property */
231  char *prop2text(SW_RESULT sw_res, char *propname) {  char *prop2text(SW_RESULT sw_res, char *propname) {
232          char *val;          char *val;
233          char *prop;          char *prop;
234          int len;          int len;
235    
236          elog(INFO, "prop2text(%s)", propname);          elog(DEBUG1, "prop2text(%s)", propname);
237    
238          prop = SwishResultPropertyStr( sw_res, propname );          prop = SwishResultPropertyStr( sw_res, propname );
239          error_or_abort( swish_handle );          error_or_abort( swish_handle );
# Line 232  char *prop2text(SW_RESULT sw_res, char * Line 244  char *prop2text(SW_RESULT sw_res, char *
244          len++;          len++;
245          len *= sizeof(char);          len *= sizeof(char);
246    
247          elog(INFO, "palloc(%d)", len);          elog(DEBUG1, "palloc(%d)", len);
248    
249          val = palloc(len);          val = palloc(len);
250    
251          memset(val, 0, len);          memset(val, 0, len);
252          strncpy(val, prop, len);          strncpy(val, prop, len);
253    
254          elog(INFO, "val=%s", val);          elog(DEBUG1, "val=%s", val);
255    
256          return val;          return val;
257  }  }
258    
259    /* make integer variable from property */
260  char *prop2int(SW_RESULT sw_res, char *propname) {  char *prop2int(SW_RESULT sw_res, char *propname) {
261          char *val;          char *val;
262          unsigned long prop;          unsigned long prop;
263          int len;          int len;
264    
265          elog(INFO, "prop2int(%s)", propname);          elog(DEBUG1, "prop2int(%s)", propname);
266    
267          prop = SwishResultPropertyULong( sw_res, propname );          prop = SwishResultPropertyULong( sw_res, propname );
268          error_or_abort( swish_handle );          error_or_abort( swish_handle );
# Line 257  char *prop2int(SW_RESULT sw_res, char *p Line 270  char *prop2int(SW_RESULT sw_res, char *p
270          elog(INFO, "prop2int(%s) = %lu", propname, prop);          elog(INFO, "prop2int(%s) = %lu", propname, prop);
271    
272          len = 128 * sizeof(char);          len = 128 * sizeof(char);
273          elog(INFO, "palloc(%d)", len);          elog(DEBUG1, "palloc(%d)", len);
274    
275          val = palloc(len);          val = palloc(len);
276          memset(val, 0, len);          memset(val, 0, len);
277    
278          snprintf(val, len, "%lu", prop);          snprintf(val, len, "%lu", prop);
279    
280          elog(INFO, "val=%s", val);          elog(DEBUG1, "val=%s", val);
281    
282          return val;          return val;
283  }  }
284    
285    
286    /*
287     * check if swish has returned error, and elog it.
288     */
289  static void error_or_abort( SW_HANDLE swish_handle ) {  static void error_or_abort( SW_HANDLE swish_handle ) {
290          if ( !SwishError( swish_handle ) )          if ( !SwishError( swish_handle ) )
291                  return;                  return;
# Line 283  static void error_or_abort( SW_HANDLE sw Line 299  static void error_or_abort( SW_HANDLE sw
299          );          );
300          if ( search ) Free_Search_Object( search );          if ( search ) Free_Search_Object( search );
301          SwishClose( swish_handle );          SwishClose( swish_handle );
   
         /* do when there is no more left */  
302  }  }
303    

Legend:
Removed from v.13  
changed lines
  Added in v.14

  ViewVC Help
Powered by ViewVC 1.1.26