Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Last active October 14, 2016 22:45
Show Gist options
  • Select an option

  • Save ableasdale/09c4dcc651c6d4de2409 to your computer and use it in GitHub Desktop.

Select an option

Save ableasdale/09c4dcc651c6d4de2409 to your computer and use it in GitHub Desktop.
Attempt to write a multi statement ad-hoc query in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Marklogic.Xcc;
using Marklogic.Xcc.Exceptions;
namespace ConsoleApplication1
{
class Program
{
private const string Host = "localhost";
private const int Port = 8000;
private const string Login = "admin";
private const string Password = "admin";
static void Main(string[] args)
{
var contentSource = ContentSourceFactory.NewContentSource(
Host,
Port,
Login,
Password);
var session = contentSource.NewSession();
string query =
@"xquery version '1.0-ml';
declare option xdmp:transaction-mode 'update';
text {'TransactionMode: ', xdmp:get-transaction-mode()},
text {'Timestamp at start of transaction: ', xdmp:transaction()},
xdmp:document-delete('/1.xml');
xdmp:document-insert('/2.xml', <data/>);
text {'Timestamp before commit: ', xdmp:transaction()},
xdmp:commit(), 'one doc deleted and new doc created';
text {'Timestamp after commit - to see this doc your query needs a timestamp that is here or later: ', xdmp:transaction()}
";
var request = session.NewAdhocQuery(query);
try
{
ResultSequence rs = session.SubmitRequest(request);
ResultItem item;
while ((item = rs.Next()) != null)
{
var data = item.AsString();
Console.WriteLine(data);
}
rs.Close();
}
catch (XQueryException e)
{
Console.WriteLine("Exception caught: " + e.FormatString);
}
session.Close();
Console.WriteLine("Any key to exit");
var name = Console.ReadLine();
}
}
}
@balouchi26
Copy link

Additional information: The type initializer for 'com.marklogic.xcc.ContentSourceFactory' threw an exception. Any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment