예제 #1
0
파일: roqet.c 프로젝트: sengels/rasqal
static
void roqet_print_query(rasqal_query* rq,
                       raptor_world* raptor_world_ptr,
                       query_output_format output_format,
                       raptor_uri* base_uri)
{
    fprintf(stderr, "Query:\n");

    switch(output_format) {
    case QUERY_OUTPUT_DEBUG:
        rasqal_query_print(rq, stdout);
        break;

    case QUERY_OUTPUT_STRUCTURE:
        roqet_query_walk(rq, stdout, 0);
        break;

    case QUERY_OUTPUT_SPARQL:
        if(1) {
            raptor_iostream* output_iostr;
            output_iostr = raptor_new_iostream_to_file_handle(raptor_world_ptr,
                           stdout);
            rasqal_query_write(output_iostr, rq, NULL, base_uri);
            raptor_free_iostream(output_iostr);
        }
        break;

    case QUERY_OUTPUT_UNKNOWN:
    default:
        fprintf(stderr, "%s: Unknown query output format %d\n", program,
                output_format);
        abort();
    }
}
예제 #2
0
/**
 * rasqal_query_results_execute_with_engine:
 * @query_results: the #rasqal_query_results object
 * @engine: execution factory
 * @store_results: non-0 to store query results
 *
 * INTERNAL - Create a new query results set executing a prepared query with the given execution engine
 *
 * return value: non-0 on failure
 **/
int
rasqal_query_results_execute_with_engine(rasqal_query_results* query_results,
                                         const rasqal_query_execution_factory* engine,
                                         int store_results)
{
  int rc = 0;
  size_t ex_data_size;
  rasqal_query* query;
  

  RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(query_results, rasqal_query_results, 1);
  
  query = query_results->query;
  
  if(query->failed)
    return 1;

  query_results->execution_factory = engine;
  
  /* set executed flag early to enable cleanup on error */
  query_results->executed = 1;

  /* ensure stored results are present if ordering or distincting are being done */
  query_results->store_results = (store_results ||
                                  rasqal_query_get_order_conditions_sequence(query) ||
                                  query->distinct);
  
  ex_data_size = query_results->execution_factory->execution_data_size;
  if(ex_data_size > 0) {
    query_results->execution_data = RASQAL_CALLOC(data, 1, ex_data_size);

    if(!query_results->execution_data)
      return 1;
  } else
    query_results->execution_data = NULL;

  /* Update the current datetime once per query execution */
  rasqal_world_reset_now(query->world);
  
  if(query_results->execution_factory->execute_init) {
    rasqal_engine_error execution_error = RASQAL_ENGINE_OK;
    int execution_flags = 0;

    if(query_results->store_results)
      execution_flags |= 1;

    rc = query_results->execution_factory->execute_init(query_results->execution_data, query, query_results, execution_flags, &execution_error);

    if(rc || execution_error != RASQAL_ENGINE_OK) {
      query_results->failed = 1;
      return 1;
    }
  }

#ifdef RASQAL_DEBUG
  RASQAL_DEBUG1("After execute_init, query is now:\n");
  rasqal_query_print(query, stderr);
#endif

  /* Choose either to execute all now and store OR do it on demand (lazy) */
  if(query_results->store_results)
    rc = rasqal_query_results_execute_and_store_results(query_results);

  return rc;
}