/[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 48 by dpavlin, Thu Oct 20 16:24:26 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_query 3
363    #define _arg_attr 4
364    #define _arg_order 5
365    #define _arg_limit 6
366    #define _arg_offset 7
367    #define _arg_attr_array 8
368    /* as (foo text, ... ); */
369    
370    
371  PG_FUNCTION_INFO_V1(pgest_node);  PG_FUNCTION_INFO_V1(pgest_node);
372  Datum pgest_node(PG_FUNCTION_ARGS)  Datum pgest_node(PG_FUNCTION_ARGS)
373  {  {
374          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(8);          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(_arg_attr_array);
375          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);
376          int             attr_ndims = ARR_NDIM(attr_arr);          int             attr_ndims = ARR_NDIM(attr_arr);
377          int             *attr_dim_counts = ARR_DIMS(attr_arr);          int             *attr_dim_counts = ARR_DIMS(attr_arr);
# Line 448  Datum pgest_node(PG_FUNCTION_ARGS) Line 461  Datum pgest_node(PG_FUNCTION_ARGS)
461          /* take rest of arguments from function */          /* take rest of arguments from function */
462    
463          /* node URL */          /* node URL */
464          if (PG_ARGISNULL(0)) {          if (PG_ARGISNULL(_arg_node_uri)) {
465                  ereport(ERROR,                  ereport(ERROR,
466                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
467                                   errmsg("node URL can't be null"),                                   errmsg("node URL can't be null"),
468                                   errdetail("Node URL must be valid URL to HyperEstraier node")));                                   errdetail("Node URL must be valid URL to HyperEstraier node")));
469          }          }
470          node_url = _textout(PG_GETARG_TEXT_P(0));          node_url = _textout(PG_GETARG_TEXT_P(_arg_node_uri));
471    
472          /* login and password */          /* login and password */
473          if (PG_ARGISNULL(1) || PG_ARGISNULL(2)) {          if (PG_ARGISNULL(_arg_login) || PG_ARGISNULL(_arg_passwd)) {
474                  ereport(ERROR,                  ereport(ERROR,
475                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
476                                   errmsg("username and password can't be NULL"),                                   errmsg("username and password can't be NULL"),
477                                   errdetail("You must specify valid username and password to HyperEstraier node")));                                   errdetail("You must specify valid username and password to HyperEstraier node")));
478          }          }
479          user = _textout(PG_GETARG_TEXT_P(1));          user = _textout(PG_GETARG_TEXT_P(_arg_login));
480          passwd = _textout(PG_GETARG_TEXT_P(2));          passwd = _textout(PG_GETARG_TEXT_P(_arg_passwd));
481    
482          /* query string */          /* query string */
483          if (PG_ARGISNULL(3)) {          if (PG_ARGISNULL(_arg_query)) {
484                  query = "";                  query = "";
485          } else {          } else {
486                  query = _textout(PG_GETARG_TEXT_P(3));                  query = _textout(PG_GETARG_TEXT_P(_arg_query));
487          }          }
488    
489          /* atribute filter */          /* atribute filter */
490          if (PG_ARGISNULL(4)) {          if (PG_ARGISNULL(_arg_attr)) {
491                  attr = "";                  attr = "";
492          } else {          } else {
493                  attr = _textout(PG_GETARG_TEXT_P(4));                  attr = _textout(PG_GETARG_TEXT_P(_arg_attr));
494          }          }
495                    
496          /* sort order */          /* sort order */
497          if (PG_ARGISNULL(5)) {          if (PG_ARGISNULL(_arg_order)) {
498                  order = "";                  order = "";
499          } else {          } else {
500                  order = _textout(PG_GETARG_TEXT_P(5));                  order = _textout(PG_GETARG_TEXT_P(_arg_order));
501          }          }
502    
503    
504          /* limit */          /* limit */
505          if (PG_ARGISNULL(6)) {          if (PG_ARGISNULL(_arg_limit)) {
506                  limit = 0;                  limit = 0;
507          } else {          } else {
508                  limit = PG_GETARG_INT32(6);                  limit = PG_GETARG_INT32(_arg_limit);
509          }          }
510    
511          /* offset */          /* offset */
512          if (PG_ARGISNULL(7)) {          if (PG_ARGISNULL(_arg_offset)) {
513                  offset = 0;                  offset = 0;
514          } else {          } else {
515                  offset = PG_GETARG_INT32(7);                  offset = PG_GETARG_INT32(_arg_offset);
516          }          }
517    
518          /* initialize the network environment */          /* initialize the network environment */
# Line 513  Datum pgest_node(PG_FUNCTION_ARGS) Line 526  Datum pgest_node(PG_FUNCTION_ARGS)
526          node = est_node_new(node_url);          node = est_node_new(node_url);
527          est_node_set_auth(node, user, passwd);          est_node_set_auth(node, user, passwd);
528    
529          elog(DEBUG1, "pgest_node: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(4) ? "NULL" : attr), limit, offset);          elog(DEBUG1, "pgest_node: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(_arg_attr) ? "NULL" : attr), limit, offset);
530                    
531          /* create a search condition object */          /* create a search condition object */
532          if (!(cond = est_cond_new())) {          if (!(cond = est_cond_new())) {
# Line 522  Datum pgest_node(PG_FUNCTION_ARGS) Line 535  Datum pgest_node(PG_FUNCTION_ARGS)
535          }          }
536                    
537          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
538          if (! PG_ARGISNULL(3) && strlen(query) > 0)          if (! PG_ARGISNULL(_arg_query) && strlen(query) > 0)
539                  est_cond_set_phrase(cond, query);                  est_cond_set_phrase(cond, query);
540    
541          /* minimum valid attribute length is 10: @a STREQ a */          /* minimum valid attribute length is 10: @a STREQ a */
542          if (! PG_ARGISNULL(4) && strlen(attr) >= 10) {          if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) {
543                  elog(DEBUG1,"attributes: %s", attr);                  elog(DEBUG1,"attributes: %s", attr);
544                  char *curr_attr;                  char *curr_attr;
545                  curr_attr = strtok(attr, ATTR_DELIMITER);                  curr_attr = strtok(attr, ATTR_DELIMITER);
# Line 538  Datum pgest_node(PG_FUNCTION_ARGS) Line 551  Datum pgest_node(PG_FUNCTION_ARGS)
551          }          }
552    
553          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
554          if (! PG_ARGISNULL(5) && strlen(order) > 0) {          if (! PG_ARGISNULL(_arg_order) && strlen(order) > 0) {
555                  elog(DEBUG1,"est_cond_set_order(%s)", order);                  elog(DEBUG1,"est_cond_set_order(%s)", order);
556                  est_cond_set_order(cond, order);                  est_cond_set_order(cond, order);
557          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26