Esempio n. 1
0
/**
 * rasqal_variable_write:
 * @v: the #rasqal_variable object
 * @iostr: the #raptor_iostream handle to write to
 *
 * Write a Rasqal variable to an iostream in a debug format.
 * 
 * The write debug format may change in any release.
 * 
 **/
void
rasqal_variable_write(rasqal_variable* v, raptor_iostream* iostr)
{
  if(!v || !iostr)
    return;
    
  if(v->type == RASQAL_VARIABLE_TYPE_ANONYMOUS)
    raptor_iostream_counted_string_write("anon-variable(", 14, iostr);
  else
    raptor_iostream_counted_string_write("variable(", 9, iostr);

  raptor_iostream_string_write(v->name, iostr);

  if(v->expression) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_expression_write(v->expression, iostr);
  }

  if(v->value) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_literal_write(v->value, iostr);
  }

#ifdef RASQAL_DEBUG_VARIABLE_USAGE
  raptor_iostream_write_byte('[', iostr);
  raptor_iostream_decimal_write(v->usage, iostr);
  raptor_iostream_write_byte(']', iostr);
#endif

  raptor_iostream_write_byte(')', iostr);
}
Esempio n. 2
0
/**
 * rasqal_triple_write:
 * @t: #rasqal_triple object.
 * @iostr: The #raptor_iostream handle to write to.
 * 
 * Write a Rasqal triple to an iostream in a debug format.
 * 
 * The print debug format may change in any release.
 **/
void
rasqal_triple_write(rasqal_triple* t, raptor_iostream* iostr)
{
  RASQAL_ASSERT_OBJECT_POINTER_RETURN(t, rasqal_triple);
  RASQAL_ASSERT_OBJECT_POINTER_RETURN(iostr, raptor_iostream);
  
  raptor_iostream_counted_string_write("triple(", 7, iostr);
  rasqal_literal_write(t->subject, iostr);
  raptor_iostream_counted_string_write(", ", 2, iostr);
  rasqal_literal_write(t->predicate, iostr);
  raptor_iostream_counted_string_write(", ", 2, iostr);
  rasqal_literal_write(t->object, iostr);
  raptor_iostream_write_byte(')', iostr);
  if(t->origin) {
    raptor_iostream_counted_string_write(" with origin(", 13, iostr);
    rasqal_literal_write(t->origin, iostr);
    raptor_iostream_write_byte(')', iostr);
  }
}
Esempio n. 3
0
/**
 * rasqal_variable_write:
 * @v: the #rasqal_variable object
 * @iostr: the #raptor_iostream handle to write to
 *
 * Write a Rasqal variable to an iostream in a debug format.
 * 
 * The write debug format may change in any release.
 * 
 **/
void
rasqal_variable_write(rasqal_variable* v, raptor_iostream* iostr)
{
  if(v->type == RASQAL_VARIABLE_TYPE_ANONYMOUS)
    raptor_iostream_counted_string_write("anon-variable(", 14, iostr);
  else
    raptor_iostream_counted_string_write("variable(", 9, iostr);
  raptor_iostream_string_write(v->name, iostr);
  if(v->expression) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_expression_write(v->expression, iostr);
  }
  if(v->value) {
    raptor_iostream_write_byte('=', iostr);
    rasqal_literal_write(v->value, iostr);
  }
  raptor_iostream_write_byte(')', iostr);
}
Esempio n. 4
0
/*
 * Return value: non-0 if equal
 */
static int
compare_query_results_compare(compare_query_results* cqr)
{
  int differences = 0;
  int i;
  int rowi;
  int size1;
  int size2;
  int row_differences_count = 0;
  
  size1 = rasqal_query_results_get_bindings_count(cqr->qr1);
  size2 = rasqal_query_results_get_bindings_count(cqr->qr2);
  
  if(size1 != size2) {
    cqr->message.level = RAPTOR_LOG_LEVEL_ERROR;
    cqr->message.text = "Results have different numbers of bindings";
    if(cqr->log_handler)
      cqr->log_handler(cqr->log_user_data, &cqr->message);

    differences++;
    goto done;
  }
  
  
  /* check variables in each results project the same variables */
  for(i = 0; 1; i++) {
    const unsigned char* v1;
    const unsigned char* v2;
    
    v1 = rasqal_query_results_get_binding_name(cqr->qr1, i);
    v2 = rasqal_query_results_get_binding_name(cqr->qr2, i);
    if(!v1 && !v2)
      break;

    if(v1 && v2) {
      if(strcmp((const char*)v1, (const char*)v2)) {
        /* different names */
        differences++;
      }
    } else
      /* one is NULL, the other is a name */
      differences++;
  }

  if(differences) {
    cqr->message.level = RAPTOR_LOG_LEVEL_ERROR;
    cqr->message.text = "Results have different binding names";
    if(cqr->log_handler)
      cqr->log_handler(cqr->log_user_data, &cqr->message);

    goto done;
  }
  

  /* set results to be stored? */

  /* sort rows by something ?  As long as the sort is the same it
   * probably does not matter what the method is. */

  /* what to do about blank nodes? */

  /* for each row */
  for(rowi = 0; 1; rowi++) {
    int bindingi;
    rasqal_row* row1 = rasqal_query_results_get_row_by_offset(cqr->qr1, rowi);
    rasqal_row* row2 = rasqal_query_results_get_row_by_offset(cqr->qr2, rowi);
    int this_row_different = 0;
    
    if(!row1 && !row2)
      break;
    
    /* for each variable in row1 (== same variables in row2) */
    for(bindingi = 0; bindingi < size1; bindingi++) {
      /* we know the binding names are the same */
      const unsigned char* name;
      rasqal_literal *value1;
      rasqal_literal *value2;
      int error = 0;

      name = rasqal_query_results_get_binding_name(cqr->qr1, bindingi);

      value1 = rasqal_query_results_get_binding_value(cqr->qr1, bindingi);
      value2 = rasqal_query_results_get_binding_value(cqr->qr2, bindingi);

      /* should have compare as native flag? 
       * RASQAL_COMPARE_XQUERY doesn't compare all values
       */
      if(!rasqal_literal_equals_flags(value1, value2, RASQAL_COMPARE_XQUERY,
                                      &error)) {
        /* if different report it */
        raptor_world* raptor_world_ptr;
        void *string;
        size_t length;
        raptor_iostream* string_iostr;

        raptor_world_ptr = rasqal_world_get_raptor(cqr->world);

        string_iostr = raptor_new_iostream_to_string(raptor_world_ptr, 
                                                     &string, &length,
                                                     (raptor_data_malloc_handler)malloc);

        raptor_iostream_counted_string_write("Difference in row ", 18,
                                             string_iostr);
        raptor_iostream_decimal_write(rowi + 1,
                                      string_iostr);
        raptor_iostream_counted_string_write(" binding '", 10, 
                                             string_iostr);
        raptor_iostream_string_write(name,
                                     string_iostr);
        raptor_iostream_counted_string_write("' ", 2, 
                                             string_iostr);
        raptor_iostream_string_write(cqr->qr1_label, string_iostr);
        raptor_iostream_counted_string_write(" value ", 7,
                                             string_iostr);
        rasqal_literal_write(value1,
                             string_iostr);
        raptor_iostream_write_byte(' ',
                                   string_iostr);
        raptor_iostream_string_write(cqr->qr2_label,
                                     string_iostr);
        raptor_iostream_counted_string_write(" value ", 7,
                                             string_iostr);
        rasqal_literal_write(value2,
                             string_iostr);
        raptor_iostream_write_byte(' ',
                                   string_iostr);

        /* this allocates and copies result into 'string' */
        raptor_free_iostream(string_iostr);

        cqr->message.level = RAPTOR_LOG_LEVEL_ERROR;
        cqr->message.text = (const char*)string;
        if(cqr->log_handler)
          cqr->log_handler(cqr->log_user_data, &cqr->message);

        free(string);
        
        differences++;
        this_row_different = 1;
      }
    } /* end for each var */

    if(this_row_different)
      row_differences_count++;

    rasqal_query_results_next(cqr->qr1);
    rasqal_query_results_next(cqr->qr2);
  } /* end for each row */

  if(row_differences_count) {
    cqr->message.level = RAPTOR_LOG_LEVEL_ERROR;
    cqr->message.text = "Results have different values";
    if(cqr->log_handler)
      cqr->log_handler(cqr->log_user_data, &cqr->message);
  }

  done:
  return (differences == 0);
}