コード例 #1
0
ファイル: cerror.c プロジェクト: buchenberg/zorba
/**
 * Use an error handler and test it by executing a query that raises an error.
 */
int
cerror_example_2(XQC_Implementation* impl)
{
  XQC_Expression*   lExpr;
  XQC_DynamicContext* lCtx;
  XQC_ErrorHandler* lErrorHandler = create_error_handler();
  XQC_Sequence*     lResult;

  // compile the query
  impl->prepare(impl, "1 div 0", NULL, &lExpr);

  // set the error handler for handling errors
  // during query execution
  lExpr->create_context(lExpr, &lCtx);
  lCtx->set_error_handler(lCtx, lErrorHandler);

  // execute it and iterate results
  lExpr->execute(lExpr, lCtx, &lResult);
  while (lResult->next(lResult) == XQC_NO_ERROR);
  
  // release all resources
  lResult->free(lResult);
  lExpr->free(lExpr);
  lCtx->free(lCtx);
  free(lErrorHandler);

  return gError == XQC_DYNAMIC_ERROR ? 1 : 0;
}
コード例 #2
0
ファイル: cerror.c プロジェクト: buchenberg/zorba
int
cerror_example_3(XQC_Implementation* impl) 
{
  XQC_Error       lError = XQC_NO_ERROR;
  XQC_Expression* lExpr;
  XQC_StaticContext* lCtx;
  const char*     lStringValue;
  XQC_Sequence*   lResult;
  XQC_ErrorHandler* lErrorHandler = create_error_handler();

  // Assign error handler to the static context
  impl->create_context(impl, &lCtx);
  lCtx->set_error_handler(lCtx, lErrorHandler);

  // compile the query and get the result as a sequence
  lError = impl->prepare(impl, "for $i in (3, 2, 1, 0) return 3 div $i",
    lCtx, &lExpr);

  lExpr->execute(lExpr, NULL, &lResult);

  // an error is reported during the last for iteration
  // the error callback function is called and the loop terminates
  while ( lResult->next(lResult) == XQC_NO_ERROR ) {
    lResult->string_value(lResult, &lStringValue);
    printf("%s ", lStringValue);
  }

  // release all aquired resources
  free(lErrorHandler);
  lResult->free(lResult);
  lExpr->free(lExpr);
  lCtx->free(lCtx);

  return (gError == XQC_DYNAMIC_ERROR && lError == XQC_NO_ERROR) ? 1 : 0;
}
コード例 #3
0
ファイル: csequences.c プロジェクト: alyst/zorba
int
csequences_4(XQC_Implementation* impl)
{
  XQC_Error lError = XQC_NO_ERROR;
  XQC_Sequence *lSeq;
  lError = impl->create_empty_sequence(impl, &lSeq);
  if (check_error("create_empty_sequence", lError)) return 0;
  lError = lSeq->next(lSeq);
  if (lError != XQC_END_OF_SEQUENCE) {
    printf("next failed to return XQC_END_OF_SEQUENCE for empty sequence");
    return 0;
  }
  lSeq->free(lSeq);
  return 1;  
}
コード例 #4
0
ファイル: cparsing.c プロジェクト: zorba-processor/zorba
/**
 * Utility testing method for parsed documents.
 */
int
parse_test(XQC_Implementation* impl, XQC_Sequence* doc)
{
  XQC_Error           lError;
  XQC_Expression*     lExpr;
  XQC_DynamicContext* lContext;
  XQC_Sequence*       lResult;

  // Advance to the document node in the sequence (since we will bind
  // to the context *item*)
  lError = doc->next(doc);
  if (check_error("next", lError)) return 0;

  // Compile query over document
  lError = impl->prepare(impl, "./doc/a/elem/text()", NULL, &lExpr);
  if (check_error("prepare", lError)) return 0;

  // get the dynamic context and set the context item
  lError = lExpr->create_context(lExpr, &lContext);
  if (check_error("create_context", lError)) return 0;
  lError = lContext->set_context_item(lContext, doc);
  if (check_error("set_context_item", lError)) return 0;

  // execute the query
  lError = lExpr->execute(lExpr, lContext, &lResult);
  if (check_error("execute", lError)) return 0;
  while ( (lResult->next(lResult)) == XQC_NO_ERROR) {
    const char* lValue;
    lResult->string_value(lResult, &lValue);
    printf("%s\n", lValue);
  }

  // free all resources
  lResult->free(lResult);
  lContext->free(lContext);
  lExpr->free(lExpr);
  // Must free the document sequence also since it was bound to the
  // context item, not a variable
  doc->free(doc);
  return 1;
}
コード例 #5
0
ファイル: csequences.c プロジェクト: alyst/zorba
/**
 * Test case for create_singleton_sequence. Args:
 * @arg impl the XQC_Implementation.
 * @arg xqctype the XQC_ItemType.
 * @arg schematype the localname of the schema type.
 * @arg value the (string) value to test with.
 */
int
cr_sngl_test
(XQC_Implementation* impl, XQC_ItemType xqctype, const char* schematype,
  const char* value)
{
  XQC_Error lError = XQC_NO_ERROR;
  XQC_Sequence *lSeq;
  const char* lUri;
  const char* lName;
  const char* lValue;

  lError = impl->create_singleton_sequence(impl, xqctype, value, &lSeq);
  if (check_error("create_singleton_sequence", lError)) return 0;
  lError = lSeq->next(lSeq);
  if (check_error("next", lError)) return 0;
  lError = lSeq->type_name(lSeq, &lUri, &lName);
  if (check_error("type_name", lError)) return 0;
  if (strcmp(lUri, "http://www.w3.org/2001/XMLSchema") != 0) {
    printf("type_name returned wrong namespace %s for xqctype %d\n",
      lUri, xqctype);
    return 0;
  }
  if (strcmp(lName, schematype) != 0) {
    printf("type_name returned wrong localname %s for xqctype %d\n",
      lName, xqctype);
    return 0;
  }
  lError = lSeq->string_value(lSeq, &lValue);
  if (strcmp(lValue, value) != 0) {
    printf("string_value returned wrong value %s for xqctype %d\n", lValue,
      xqctype);
    return 0;
  }
  lError = lSeq->next(lSeq);
  if (lError != XQC_END_OF_SEQUENCE) {
    printf("more than one value from singleton sequence!");
    return 0;
  }
  // Leaks if test fails...
  lSeq->free(lSeq);
  return 1;
}