/[pgestraier]/trunk/pgest.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/pgest.c

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

revision 47 by dpavlin, Sun Sep 11 21:44:56 2005 UTC revision 49 by dpavlin, Sat Oct 29 18:54:40 2005 UTC
# Line 355  char *attr2text(ESTDOC *doc, char *attr) Line 355  char *attr2text(ESTDOC *doc, char *attr)
355   *   *
356   */   */
357    
358    /* select * from pgest( */
359    #define _arg_node_uri 0
360    #define _arg_login 1
361    #define _arg_passwd 2
362    #define _arg_depth 3
363    #define _arg_query 4
364    #define _arg_attr 5
365    #define _arg_order 6
366    #define _arg_limit 7
367    #define _arg_offset 8
368    #define _arg_attr_array 9
369    /* as (foo text, ... ); */
370    
371    
372  PG_FUNCTION_INFO_V1(pgest_node);  PG_FUNCTION_INFO_V1(pgest_node);
373  Datum pgest_node(PG_FUNCTION_ARGS)  Datum pgest_node(PG_FUNCTION_ARGS)
374  {  {
375          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(8);          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(_arg_attr_array);
376          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);
377          int             attr_ndims = ARR_NDIM(attr_arr);          int             attr_ndims = ARR_NDIM(attr_arr);
378          int             *attr_dim_counts = ARR_DIMS(attr_arr);          int             *attr_dim_counts = ARR_DIMS(attr_arr);
# Line 389  Datum pgest_node(PG_FUNCTION_ARGS) Line 403  Datum pgest_node(PG_FUNCTION_ARGS)
403          int resnum = 0;          int resnum = 0;
404          int limit = 0;          int limit = 0;
405          int offset = 0;          int offset = 0;
406            int depth = 0;
407    
408          char            *node_url;          char            *node_url;
409          char            *user, *passwd;          char            *user, *passwd;
# Line 448  Datum pgest_node(PG_FUNCTION_ARGS) Line 463  Datum pgest_node(PG_FUNCTION_ARGS)
463          /* take rest of arguments from function */          /* take rest of arguments from function */
464    
465          /* node URL */          /* node URL */
466          if (PG_ARGISNULL(0)) {          if (PG_ARGISNULL(_arg_node_uri)) {
467                  ereport(ERROR,                  ereport(ERROR,
468                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
469                                   errmsg("node URL can't be null"),                                   errmsg("node URL can't be null"),
470                                   errdetail("Node URL must be valid URL to HyperEstraier node")));                                   errdetail("Node URL must be valid URL to HyperEstraier node")));
471          }          }
472          node_url = _textout(PG_GETARG_TEXT_P(0));          node_url = _textout(PG_GETARG_TEXT_P(_arg_node_uri));
473    
474          /* login and password */          /* login and password */
475          if (PG_ARGISNULL(1) || PG_ARGISNULL(2)) {          if (PG_ARGISNULL(_arg_login) || PG_ARGISNULL(_arg_passwd)) {
476                  ereport(ERROR,                  ereport(ERROR,
477                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
478                                   errmsg("username and password can't be NULL"),                                   errmsg("username and password can't be NULL"),
479                                   errdetail("You must specify valid username and password to HyperEstraier node")));                                   errdetail("You must specify valid username and password to HyperEstraier node")));
480          }          }
481          user = _textout(PG_GETARG_TEXT_P(1));          user = _textout(PG_GETARG_TEXT_P(_arg_login));
482          passwd = _textout(PG_GETARG_TEXT_P(2));          passwd = _textout(PG_GETARG_TEXT_P(_arg_passwd));
483    
484            /* depth of search */
485            if (PG_ARGISNULL(_arg_depth)) {
486                    depth = 0;
487            } else {
488                    depth = PG_GETARG_INT32(_arg_depth);
489            }
490    
491          /* query string */          /* query string */
492          if (PG_ARGISNULL(3)) {          if (PG_ARGISNULL(_arg_query)) {
493                  query = "";                  query = "";
494          } else {          } else {
495                  query = _textout(PG_GETARG_TEXT_P(3));                  query = _textout(PG_GETARG_TEXT_P(_arg_query));
496          }          }
497    
498          /* atribute filter */          /* atribute filter */
499          if (PG_ARGISNULL(4)) {          if (PG_ARGISNULL(_arg_attr)) {
500                  attr = "";                  attr = "";
501          } else {          } else {
502                  attr = _textout(PG_GETARG_TEXT_P(4));                  attr = _textout(PG_GETARG_TEXT_P(_arg_attr));
503          }          }
504                    
505          /* sort order */          /* sort order */
506          if (PG_ARGISNULL(5)) {          if (PG_ARGISNULL(_arg_order)) {
507                  order = "";                  order = "";
508          } else {          } else {
509                  order = _textout(PG_GETARG_TEXT_P(5));                  order = _textout(PG_GETARG_TEXT_P(_arg_order));
510          }          }
511    
512    
513          /* limit */          /* limit */
514          if (PG_ARGISNULL(6)) {          if (PG_ARGISNULL(_arg_limit)) {
515                  limit = 0;                  limit = 0;
516          } else {          } else {
517                  limit = PG_GETARG_INT32(6);                  limit = PG_GETARG_INT32(_arg_limit);
518          }          }
519    
520          /* offset */          /* offset */
521          if (PG_ARGISNULL(7)) {          if (PG_ARGISNULL(_arg_offset)) {
522                  offset = 0;                  offset = 0;
523          } else {          } else {
524                  offset = PG_GETARG_INT32(7);                  offset = PG_GETARG_INT32(_arg_offset);
525          }          }
526    
527          /* initialize the network environment */          /* initialize the network environment */
# Line 513  Datum pgest_node(PG_FUNCTION_ARGS) Line 535  Datum pgest_node(PG_FUNCTION_ARGS)
535          node = est_node_new(node_url);          node = est_node_new(node_url);
536          est_node_set_auth(node, user, passwd);          est_node_set_auth(node, user, passwd);
537    
538          elog(DEBUG1, "pgest_node: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(4) ? "NULL" : attr), limit, offset);          elog(DEBUG1, "pgest_node: node: %s (d:%d) query[%s] attr[%s] limit %d offset %d", node_url, depth, query, (PG_ARGISNULL(_arg_attr) ? "NULL" : attr), limit, offset);
539                    
540          /* create a search condition object */          /* create a search condition object */
541          if (!(cond = est_cond_new())) {          if (!(cond = est_cond_new())) {
# Line 522  Datum pgest_node(PG_FUNCTION_ARGS) Line 544  Datum pgest_node(PG_FUNCTION_ARGS)
544          }          }
545                    
546          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
547          if (! PG_ARGISNULL(3) && strlen(query) > 0)          if (! PG_ARGISNULL(_arg_query) && strlen(query) > 0)
548                  est_cond_set_phrase(cond, query);                  est_cond_set_phrase(cond, query);
549    
550          /* minimum valid attribute length is 10: @a STREQ a */          /* minimum valid attribute length is 10: @a STREQ a */
551          if (! PG_ARGISNULL(4) && strlen(attr) >= 10) {          if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) {
552                  elog(DEBUG1,"attributes: %s", attr);                  elog(DEBUG1,"attributes: %s", attr);
553                  char *curr_attr;                  char *curr_attr;
554                  curr_attr = strtok(attr, ATTR_DELIMITER);                  curr_attr = strtok(attr, ATTR_DELIMITER);
# Line 538  Datum pgest_node(PG_FUNCTION_ARGS) Line 560  Datum pgest_node(PG_FUNCTION_ARGS)
560          }          }
561    
562          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
563          if (! PG_ARGISNULL(5) && strlen(order) > 0) {          if (! PG_ARGISNULL(_arg_order) && strlen(order) > 0) {
564                  elog(DEBUG1,"est_cond_set_order(%s)", order);                  elog(DEBUG1,"est_cond_set_order(%s)", order);
565                  est_cond_set_order(cond, order);                  est_cond_set_order(cond, order);
566          }          }
# Line 549  Datum pgest_node(PG_FUNCTION_ARGS) Line 571  Datum pgest_node(PG_FUNCTION_ARGS)
571          }          }
572    
573          /* get the result of search */          /* get the result of search */
574          /* FIXME: allow user to specify depath of search */          nres = est_node_search(node, cond, depth);
         nres = est_node_search(node, cond, 0);  
575    
576          if (! nres) {          if (! nres) {
577                  int status = est_node_status(node);                  int status = est_node_status(node);

Legend:
Removed from v.47  
changed lines
  Added in v.49

  ViewVC Help
Powered by ViewVC 1.1.26