Exemplo n.º 1
0
        public void CheckTable(VirtuosoConnection connection, TestCaseResult result)
        {
            VirtuosoCommand select = connection.CreateCommand();

            select.CommandText = "select * from foo";

            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter();

            adapter.SelectCommand = (VirtuosoCommand)select;

            DataSet dataset = new DataSet();

            adapter.Fill(dataset);

            DataTable table = dataset.Tables["Table"];

            result.FailIfNotEqual(checkTable.Rows.Count, table.Rows.Count);
            result.FailIfNotEqual(checkTable.Columns.Count, table.Columns.Count);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow row      = table.Rows[i];
                DataRow checkRow = checkTable.Rows[i];
                for (int j = 0; j < table.Columns.Count; j++)
                {
                    string name = table.Columns[j].ColumnName;
                    result.FailIfNotEqual(checkRow[name], row[name]);
                }
            }
        }
Exemplo n.º 2
0
        private void CheckTable(TestCaseResult result)
        {
            VirtuosoCommand select = connection.CreateCommand();

            select.CommandText = "select * from foo";

            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter();

            adapter.SelectCommand = (VirtuosoCommand)select;

            DataSet dataset = new DataSet();

            adapter.Fill(dataset);

            DataTable table = dataset.Tables["table"];

            result.FailIfNotEqual(checkTable.Rows.Count, table.Rows.Count);
            result.FailIfNotEqual(checkTable.Columns.Count, table.Columns.Count);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                Debug.WriteLine("row #" + i);
                DataRow row      = table.Rows[i];
                DataRow checkRow = checkTable.Rows[i];
                for (int j = 0; j < table.Columns.Count; j++)
                {
                    string name = table.Columns[j].ColumnName;
                    result.FailIfNotEqual(this, "Comparison failed for column " + name + ": ", checkRow[name], row[name]);
                }
            }
        }
Exemplo n.º 3
0
        public void TableUpdate(TestCaseResult result)
        {
            DropTable();
            CreateTable();
            InsertRow(1);
            InsertRow(2);

            DataSet                dataset = new DataSet();
            VirtuosoDataAdapter    adapter = null;
            VirtuosoCommandBuilder builder = null;

            try
            {
                adapter = new VirtuosoDataAdapter();
                adapter.SelectCommand = new VirtuosoCommand("select * from foo", connection);
                adapter.Fill(dataset, "table");

                builder             = new VirtuosoCommandBuilder();
                builder.DataAdapter = adapter;

                DataTable table = dataset.Tables["table"];
                if (table.Rows.Count > 0)
                {
                    DataRow row = table.Rows[0];
                    row.Delete();
                }
                //if (table.Rows.Count > 1)
                //{
                //	DataRow row = table.Rows[1];
                //	row["j"] = 555;
                //	row["s"] = "bbb";
                //}
                DataRow newrow = table.NewRow();
                newrow["i"] = 3;
                newrow["n"] = 333;
                table.Rows.Add(newrow);

                adapter.Update(dataset, "Table");
            }
            finally
            {
                if (builder != null)
                {
                    builder.Dispose();
                    builder = null;
                }
                if (adapter != null)
                {
                    adapter.Dispose();
                    adapter = null;
                }
            }
        }
Exemplo n.º 4
0
        public DataTable ExecuteQuery(string queryString, ITransaction transaction = null)
        {
            DataTable result = new DataTable();

            VirtuosoDataAdapter adapter = null;
            VirtuosoCommand     command = null;

            try
            {
                command             = Connection.CreateCommand();
                command.CommandText = queryString;

                if (transaction != null && transaction is VirtuosoTransaction)
                {
                    command.Transaction = (transaction as VirtuosoTransaction).Transaction;
                }

                result.Columns.CollectionChanged += OnColumnsCollectionChanged;

                adapter = new VirtuosoDataAdapter(command);
                adapter.Fill(result);

                result.Columns.CollectionChanged -= OnColumnsCollectionChanged;
            }
            catch (InvalidOperationException ex)
            {
                string msg = string.Format("Error: Caught {0} exception.", ex.GetType());
                Debug.WriteLine(msg);
            } /* This seems to be different in 7.x version of Openlink.Virtuoso.dll
               * catch (VirtuosoException e)
               * {
               *
               * if (e.ErrorCode == 40001)
               *    throw new ResourceLockedException(e);
               * else
               *
               *    throw;
               * } */
            finally
            {
                if (adapter != null)
                {
                    adapter.Dispose();
                }

                if (command != null)
                {
                    command.Dispose();
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Executes a Query SQL Command against the database and fills the supplied DataTable with the results
        /// </summary>
        /// <param name="sqlCmd">SQL Command</param>
        /// <param name="data">DataTable to fill with results</param>
        /// <remarks>Allows for queries which wish to strongly type the results for quicker reading</remarks>
        protected override void ExecuteQuery(string sqlCmd, DataTable data)
        {
            //Get Thread ID
            int thread = Thread.CurrentThread.ManagedThreadId;

            //Create the SQL Command
            VirtuosoCommand cmd = new VirtuosoCommand(sqlCmd, this._dbConnections[thread]);

            if (this._dbTrans[thread] != null)
            {
                //Add to the Transaction if required
                cmd.Transaction = this._dbTrans[thread];
            }

            //Execute the Query
            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);

            adapter.Fill(data);
        }
Exemplo n.º 6
0
        public void GetMethods(TestCaseResult result)
        {
            DropTable();
            CreateTable();

            DataSet                dataset = new DataSet();
            VirtuosoDataAdapter    adapter = null;
            VirtuosoCommandBuilder builder = null;

            try
            {
                adapter = new VirtuosoDataAdapter();
                adapter.SelectCommand = new VirtuosoCommand("select * from foo", connection);
                adapter.Fill(dataset, "table");

                builder             = new VirtuosoCommandBuilder();
                builder.DataAdapter = adapter;

                VirtuosoCommand delete = builder.GetDeleteCommand();
                VirtuosoCommand insert = builder.GetInsertCommand();
                VirtuosoCommand update = builder.GetUpdateCommand();

                // dummy thing to evade the delete,insert,update not used warnings
                if (delete != null || insert != null || update != null)
                {
                    adapter = null;
                }
            }
            finally
            {
                if (builder != null)
                {
                    builder.Dispose();
                    builder = null;
                }
                if (adapter != null)
                {
                    adapter.Dispose();
                    adapter = null;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Executes a Query SQL Command against the database and returns a DataTable
        /// </summary>
        /// <param name="sqlCmd">SQL Command</param>
        /// <returns>DataTable of results</returns>
        public override DataTable ExecuteQuery(string sqlCmd)
        {
            //Get Thread ID
            int thread = Thread.CurrentThread.ManagedThreadId;

            //Create the SQL Command
            VirtuosoCommand cmd = new VirtuosoCommand(sqlCmd, this._dbConnections[thread]);

            if (this._dbTrans[thread] != null)
            {
                //Add to the Transaction if required
                cmd.Transaction = this._dbTrans[thread];
            }

            //Execute the Query
            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);
            DataTable           results = new DataTable();

            adapter.Fill(results);

            return(results);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            try
            {
                VirtuosoConnection conn;
                if (args.Length > 0)
                {
                    TestPooling(args[0]);
                    if (args.Length > 1 && args[1] == "-e")
                    {
                        return;
                    }
                    conn = new VirtuosoConnection(args[0]);
                }
                else
                {
                    conn = new VirtuosoConnection();
                }
                conn.Open();

                IDbCommand drop = conn.CreateCommand();
                drop.CommandText = "drop table foo";
                try
                {
                    drop.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got an Exception.");
                    Console.WriteLine("{0}", e.Message);
                    Console.WriteLine("StackTrace:");
                    Console.WriteLine("{0}", e.StackTrace);
                }
                finally
                {
                    drop.Dispose();
                }

                IDbCommand create = conn.CreateCommand();
                create.CommandText = "create table foo (id int primary key, txt varchar(100))";
                create.ExecuteNonQuery();
                create.Dispose();

                int rc;

                IDbCommand insert_1 = conn.CreateCommand();
                insert_1.CommandText = "insert into foo foo values (1, 'lorem')";
                rc = insert_1.ExecuteNonQuery();
                insert_1.Dispose();

                Console.WriteLine("rc: {0}", rc);

                IDbCommand insert_2 = conn.CreateCommand();
                insert_2.CommandText = "insert into foo foo values (2, 'ipsum')";
                rc = insert_2.ExecuteNonQuery();
                insert_2.Dispose();

                Console.WriteLine("rc: {0}", rc);

                IDbCommand select = conn.CreateCommand();
                select.CommandText = "select * from foo";
                IDataReader reader = select.ExecuteReader();

                DataSet dataset = new DataSet();

                DataTable schemaTable = reader.GetSchemaTable();
                dataset.Tables.Add(schemaTable);

                VirtuosoDataAdapter adapter = new VirtuosoDataAdapter();
                adapter.SelectCommand = (VirtuosoCommand)select;
                adapter.Fill(dataset);

                //reader.Dispose();
                //select.Dispose();
                //conn.Dispose();

                Form[] forms = new Form[dataset.Tables.Count];
                instance_count = 0;
                foreach (DataTable t in dataset.Tables)
                {
                    forms[instance_count]         = new Test(dataset, t.TableName);
                    forms[instance_count].Closed += new EventHandler(Test_Closed);
                    forms[instance_count].Show();
                    instance_count++;
                }
                Application.Run();
            }
            catch (Exception e)
            {
                Console.WriteLine("Got an Exception.");
                Console.WriteLine("{0}", e.Message);
                Console.WriteLine("StackTrace:");
                Console.WriteLine("{0}", e.StackTrace);
            }
        }
		public void TableUpdate (TestCaseResult result)
		{
			DropTable ();
			CreateTable ();
			InsertRow (1);
			InsertRow (2);

			DataSet dataset = new DataSet ();
			VirtuosoDataAdapter adapter = null;
			VirtuosoCommandBuilder builder = null;
			try
			{
				adapter = new VirtuosoDataAdapter ();
				adapter.SelectCommand = new VirtuosoCommand ("select * from foo", connection);
				adapter.Fill (dataset, "table");

				builder = new VirtuosoCommandBuilder ();
				builder.DataAdapter = adapter;

				DataTable table = dataset.Tables["table"];
				if (table.Rows.Count > 0)
				{
					DataRow row = table.Rows[0];
					row.Delete ();
				}
				//if (table.Rows.Count > 1)
				//{
				//	DataRow row = table.Rows[1];
				//	row["j"] = 555;
				//	row["s"] = "bbb";
				//}
				DataRow newrow = table.NewRow ();
				newrow["i"] = 3;
				newrow["n"] = 333;
				table.Rows.Add (newrow);

				adapter.Update (dataset, "Table");
			}
			finally
			{
				if (builder != null)
				{
					builder.Dispose ();
					builder = null;
				}
				if (adapter != null)
				{
					adapter.Dispose ();
					adapter = null;
				}
			}
		}
		public void GetMethods (TestCaseResult result)
		{
			DropTable ();
			CreateTable ();

			DataSet dataset = new DataSet ();
			VirtuosoDataAdapter adapter = null;
			VirtuosoCommandBuilder builder = null;
			try
			{
				adapter = new VirtuosoDataAdapter ();
				adapter.SelectCommand = new VirtuosoCommand ("select * from foo", connection);
				adapter.Fill (dataset, "table");

				builder = new VirtuosoCommandBuilder ();
				builder.DataAdapter = adapter;

				VirtuosoCommand delete = builder.GetDeleteCommand ();
				VirtuosoCommand insert = builder.GetInsertCommand ();
				VirtuosoCommand update = builder.GetUpdateCommand ();

				// dummy thing to evade the delete,insert,update not used warnings
				if (delete != null || insert != null || update != null)
				  adapter = null;
			}
			finally
			{
				if (builder != null)
				{
					builder.Dispose ();
					builder = null;
				}
				if (adapter != null)
				{
					adapter.Dispose ();
					adapter = null;
				}
			}
		}
		private void CheckDataSetTable (TestCaseResult result)
		{
			VirtuosoCommand select = connection.CreateCommand ();
			select.CommandText = "select * from foo order by id";

			VirtuosoDataAdapter adapter = new VirtuosoDataAdapter ();
			adapter.SelectCommand = (VirtuosoCommand) select;

			DataSet dataset = new DataSet ();
			adapter.Fill (dataset);

			DataTable table = dataset.Tables["table"];

			result.FailIfNotEqual (checkTable.Rows.Count, table.Rows.Count);
			result.FailIfNotEqual (checkTable.Columns.Count, table.Columns.Count);
			for (int i = 0; i < table.Rows.Count; i++)
			{
				DataRow row = table.Rows[i];
				DataRow checkRow = checkTable.Rows[i];
				for (int j = 0; j < table.Columns.Count; j++)
				{
					string name = table.Columns[j].ColumnName;
					result.FailIfNotEqual (this, "Comparison failed for column " + name + ": ", checkRow[name], row[name]);
				}
			}
		}
Exemplo n.º 12
0
        /// <summary>
        /// Executes a Query SQL Command against the database and fills the supplied DataTable with the results
        /// </summary>
        /// <param name="sqlCmd">SQL Command</param>
        /// <param name="data">DataTable to fill with results</param>
        /// <remarks>Allows for queries which wish to strongly type the results for quicker reading</remarks>
        protected override void ExecuteQuery(string sqlCmd, DataTable data)
        {
            //Get Thread ID
            int thread = Thread.CurrentThread.ManagedThreadId;

            //Create the SQL Command
            VirtuosoCommand cmd = new VirtuosoCommand(sqlCmd, this._dbConnections[thread]);
            if (this._dbTrans[thread] != null)
            {
                //Add to the Transaction if required
                cmd.Transaction = this._dbTrans[thread];
            }

            //Execute the Query
            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);
            adapter.Fill(data);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Executes a Query SQL Command against the database and returns a DataTable
        /// </summary>
        /// <param name="sqlCmd">SQL Command</param>
        /// <returns>DataTable of results</returns>
        public override DataTable ExecuteQuery(string sqlCmd)
        {
            //Get Thread ID
            int thread = Thread.CurrentThread.ManagedThreadId;

            //Create the SQL Command
            VirtuosoCommand cmd = new VirtuosoCommand(sqlCmd, this._dbConnections[thread]);
            if (this._dbTrans[thread] != null)
            {
                //Add to the Transaction if required
                cmd.Transaction = this._dbTrans[thread];
            }

            //Execute the Query
            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);
            DataTable results = new DataTable();
            adapter.Fill(results);

            return results;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Executes a Query SQL Command against the database and returns a DataTable
        /// </summary>
        /// <param name="sqlCmd">SQL Command</param>
        /// <returns>DataTable of results</returns>
        public DataTable ExecuteQuery(string sqlCmd)
        {
            //Create the SQL Command
            VirtuosoCommand cmd = new VirtuosoCommand(sqlCmd, this._db);
            if (this._dbtrans != null)
            {
                //Add to the Transaction if required
                cmd.Transaction = this._dbtrans;
            }

            //Execute the Query
            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);
            DataTable results = new DataTable();
            adapter.Fill(results);

            return results;
        }
Exemplo n.º 15
0
		static void Main (string[] args)
		{
			try
			{
				VirtuosoConnection conn;
				if (args.Length > 0)
				{
					TestPooling (args[0]);
					if (args.Length > 1 && args[1] == "-e")
						return;
					conn = new VirtuosoConnection (args[0]);
				}
				else
					conn = new VirtuosoConnection ();
				conn.Open ();

				IDbCommand drop = conn.CreateCommand();
				drop.CommandText = "drop table foo";
				try
				{
					drop.ExecuteNonQuery();
				}
				catch (Exception e)
				{
					Console.WriteLine("Got an Exception.");
					Console.WriteLine("{0}", e.Message);
					Console.WriteLine("StackTrace:");
					Console.WriteLine("{0}", e.StackTrace);
				}
				finally
				{
					drop.Dispose();
				}

				IDbCommand create = conn.CreateCommand();
				create.CommandText = "create table foo (id int primary key, txt varchar(100))";
				create.ExecuteNonQuery();
				create.Dispose();

				int rc;

				IDbCommand insert_1 = conn.CreateCommand();
				insert_1.CommandText = "insert into foo foo values (1, 'lorem')";
				rc = insert_1.ExecuteNonQuery();
				insert_1.Dispose();

				Console.WriteLine("rc: {0}", rc);

				IDbCommand insert_2 = conn.CreateCommand();
				insert_2.CommandText = "insert into foo foo values (2, 'ipsum')";
				rc = insert_2.ExecuteNonQuery();
				insert_2.Dispose();

				Console.WriteLine("rc: {0}", rc);

				IDbCommand select = conn.CreateCommand();
				select.CommandText = "select * from foo";
				IDataReader reader = select.ExecuteReader();

				DataSet dataset = new DataSet();

				DataTable schemaTable = reader.GetSchemaTable ();
				dataset.Tables.Add (schemaTable);

				VirtuosoDataAdapter adapter = new VirtuosoDataAdapter();
				adapter.SelectCommand = (VirtuosoCommand)select;
				adapter.Fill(dataset);

				//reader.Dispose();
				//select.Dispose();
				//conn.Dispose();

				Form[] forms = new Form[dataset.Tables.Count];
				instance_count = 0;
				foreach (DataTable t in dataset.Tables)
				{
					forms[instance_count] = new Test (dataset, t.TableName);
					forms[instance_count].Closed += new EventHandler (Test_Closed);
					forms[instance_count].Show ();
					instance_count++;
				}
				Application.Run ();
			}
			catch (Exception e)
			{
				Console.WriteLine("Got an Exception.");
				Console.WriteLine("{0}", e.Message);
				Console.WriteLine("StackTrace:");
				Console.WriteLine("{0}", e.StackTrace);
			}
		}
Exemplo n.º 16
0
        /// <summary>
        /// Gets a Table of Triples that are in the given Graph
        /// </summary>
        /// <param name="graphUri">Graph Uri</param>
        /// <returns></returns>
        /// <remarks>
        /// Assumes that the caller has opened the Database connection
        /// </remarks>
        private DataTable LoadTriples(Uri graphUri)
        {
            DataTable dt = new DataTable();
            String getTriples;
            if (graphUri != null)
            {
                getTriples = "SPARQL define output:format '_JAVA_' SELECT * FROM <" + graphUri.ToString() + "> WHERE {?s ?p ?o}";
            }
            else
            {
                getTriples = "SPARQL define output:format '_JAVA_' SELECT * WHERE {?s ?p ?o}";
            }

            VirtuosoCommand cmd = this._db.CreateCommand();
            cmd.CommandText = getTriples;

            VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);

            dt.Columns.Add("S", typeof(System.Object));
            dt.Columns.Add("P", typeof(System.Object));
            dt.Columns.Add("O", typeof(System.Object));
            try
            {
                adapter.Fill(dt);
            }
            catch
            {
                throw;
            }

            return dt;
        }
		public void CheckTable (VirtuosoConnection connection, TestCaseResult result)
		{
			VirtuosoCommand select = connection.CreateCommand ();
			select.CommandText = "select * from foo";

			VirtuosoDataAdapter adapter = new VirtuosoDataAdapter ();
			adapter.SelectCommand = (VirtuosoCommand) select;

			DataSet dataset = new DataSet ();
			adapter.Fill (dataset);

			DataTable table = dataset.Tables["Table"];

			result.FailIfNotEqual (checkTable.Rows.Count, table.Rows.Count);
			result.FailIfNotEqual (checkTable.Columns.Count, table.Columns.Count);
			for (int i = 0; i < table.Rows.Count; i++)
			{
				DataRow row = table.Rows[i];
				DataRow checkRow = checkTable.Rows[i];
				for (int j = 0; j < table.Columns.Count; j++)
				{
					string name = table.Columns[j].ColumnName;
					result.FailIfNotEqual (checkRow[name], row[name]);
				}
			}
		}
Exemplo n.º 18
0
        /// <summary>
        /// Executes a SPARQL Query on the native Quad Store
        /// </summary>
        /// <param name="sparqlQuery">SPARQL Query to execute</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// This method will first attempt to parse the query into a <see cref="SparqlQuery">SparqlQuery</see> object.  If this succeeds then the Query Type can be used to determine how to handle the response.
        /// </para>
        /// <para>
        /// If the parsing fails then the query will be executed anyway using Virtuoso's SPASQL (SPARQL + SQL) syntax.  Parsing can fail because Virtuoso supports various SPARQL extensions which the library does not support.  These include things like aggregate functions but also SPARQL Update statements.
        /// </para>
        /// <para>
        /// If you use an aggregate query which has an Integer, Decimal or Double type result then you will receive a <see cref="SparqlResultSet">SparqlResultSet</see> containing a single <see cref="SparqlResult">SparqlResult</see> which has contains a binding for a variable named <strong>Result</strong> which contains a <see cref="LiteralNode">LiteralNode</see> typed to the appropriate datatype.
        /// </para>
        /// </remarks>
        /// <exception cref="RdfQueryException">Thrown if an error occurs in making the query</exception>
        public Object Query(String sparqlQuery)
        {
            Object finalResult = null;
            DataTable results = new DataTable();
            results.Columns.CollectionChanged += new System.ComponentModel.CollectionChangeEventHandler(Columns_CollectionChanged);

            //See if the query can be parsed into a SparqlQuery object
            //It might not since the user might use Virtuoso's extensions to Sparql in their query
            try
            {
                //We'll set the Parser to SPARQL 1.1 mode even though Virtuoso's SPARQL implementation has
                //various perculiarties in their SPARQL 1.1 implementation and we'll try and 
                //handle the potential results in the catch branch if a valid SPARQL 1.0 query
                //cannot be parsed
                //Change made in response to a bug report by Aleksandr A. Zaripov [[email protected]]
                SparqlQueryParser parser = new SparqlQueryParser();
                parser.SyntaxMode = SparqlQuerySyntax.Sparql_1_1;
                SparqlQuery query = parser.ParseFromString(sparqlQuery);

                switch (query.QueryType)
                {
                    case SparqlQueryType.Select:
                    case SparqlQueryType.SelectAll:
                    case SparqlQueryType.SelectAllDistinct:
                    case SparqlQueryType.SelectAllReduced:
                    case SparqlQueryType.SelectDistinct:
                    case SparqlQueryType.SelectReduced:
                        //Type the Tables columns as System.Object
                        foreach (SparqlVariable var in query.Variables)
                        {
                            if (var.IsResultVariable)
                            {
                                results.Columns.Add(var.Name, typeof(System.Object));
                            }
                        }
                        break;
                }

                try 
                {
                    this.Open(false);

                    //Make the Query against Virtuoso
                    VirtuosoCommand cmd = this._db.CreateCommand();
                    cmd.CommandText = "SPARQL " + sparqlQuery;
                    VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);
                    adapter.Fill(results);

                    //Decide how to process the results based on the return type
                    switch (query.QueryType)
                    {
                        case SparqlQueryType.Ask:
                            //Expect a DataTable containing a single row and column which contains a boolean

                            if (results.Rows.Count == 1 && results.Columns.Count == 1)
                            {
                                bool result;
                                int r;
                                if (Boolean.TryParse(results.Rows[0][0].ToString(), out result))
                                {
                                    finalResult = new SparqlResultSet(result);
                                }
                                else if (Int32.TryParse(results.Rows[0][0].ToString(), out r))
                                {
                                    if (r == 1)
                                    {
                                        finalResult = new SparqlResultSet(true);
                                    }
                                    else
                                    {
                                        finalResult = new SparqlResultSet(false);
                                    }
                                }
                                else
                                {
                                    throw new RdfQueryException("Expected a Boolean as the result of an ASK query but the non-boolean value '" + results.Rows[0][0].ToString() + "' was received");
                                }
                            }
                            else
                            {
                                //If we get anything else then we'll return that the result was False
                                finalResult = new SparqlResultSet(false);
                            }

                            break;
                        case SparqlQueryType.Construct:
                        case SparqlQueryType.Describe:
                        case SparqlQueryType.DescribeAll:
                            //Expect a DataTable containing a single row and column which contains a String
                            //That string will be a Turtle serialization of the Graph

                            if (results.Rows.Count == 1 && results.Columns.Count == 1)
                            {
                                try
                                {
                                    //Use StringParser to parse
                                    String data = results.Rows[0][0].ToString();
                                    TurtleParser ttlparser = new TurtleParser();
                                    Graph g = new Graph();
                                    StringParser.Parse(g, data, ttlparser);

                                    finalResult = g;
                                }
                                catch (RdfParseException parseEx)
                                {
                                    throw new RdfQueryException("Expected a valid Turtle serialization of the Graph resulting from a CONSTRUCT/DESCRIBE query but the result failed to parse", parseEx);
                                }
                            }
                            else
                            {
                                throw new RdfQueryException("Expected a single string value representing the serialization of the Graph resulting from a CONSTRUCT/DESCRIBE query but this was not received");
                            }

                            break;
                        case SparqlQueryType.Select:
                        case SparqlQueryType.SelectAll:
                        case SparqlQueryType.SelectAllDistinct:
                        case SparqlQueryType.SelectAllReduced:
                        case SparqlQueryType.SelectDistinct:
                        case SparqlQueryType.SelectReduced:
                            //Expect a DataTable containing columns for each Result Variable and a row for each solution
                            SparqlResultSet rset = new SparqlResultSet();
                            rset.SetResult(true);

                            //Get Result Variables
                            List<SparqlVariable> resultVars = query.Variables.Where(v => v.IsResultVariable).ToList();
                            foreach (SparqlVariable var in resultVars)
                            {
                                rset.AddVariable(var.Name);
                            }
                            Graph temp = new Graph();

                            //Convert each solution into a SPARQLResult
                            foreach (DataRow r in results.Rows)
                            {
                                SparqlResult result = new SparqlResult();
                                foreach (SparqlVariable var in resultVars)
                                {
                                    if (r[var.Name] != null)
                                    {
                                        result.SetValue(var.Name, this.LoadNode(temp, r[var.Name]));
                                    }
                                }
                                rset.AddResult(result);
                            }

                            finalResult = rset;

                            break;
                        default:
                            throw new RdfQueryException("Unable to process the Results of an Unknown query type");
                    }

                    this.Close(false);
                } 
                catch
                {
                    this.Close(true, true);
                    throw;
                }
            }
            catch (RdfParseException)
            {
                //Unable to parse a SPARQL 1.0 query
                //Have to attempt to detect the return type based on the DataTable that
                //the SPASQL (Sparql+SQL) query gives back

                //Make the Query against Virtuoso
                VirtuosoCommand cmd = this._db.CreateCommand();
                cmd.CommandText = "SPARQL " /*define output:format '_JAVA_' "*/ + sparqlQuery;
                VirtuosoDataAdapter adapter = new VirtuosoDataAdapter(cmd);
                adapter.Fill(results);

                //Try to detect the return type based on the DataTable configuration
                if (results.Rows.Count == 0 && results.Columns.Count > 0)
                {
                    //No Rows but some columns implies empty SELECT results
                    SparqlResultSet rset = new SparqlResultSet();
                    foreach (DataColumn col in results.Columns)
                    {
                        rset.AddVariable(col.ColumnName);
                    }

                    finalResult = rset;
                }
                else if (results.Rows.Count == 1 && results.Columns.Count == 1 && !Regex.IsMatch(sparqlQuery, "SELECT", RegexOptions.IgnoreCase))
                {
                    //Added a fix here suggested by Alexander Sidorov - not entirely happy with this fix as what happens if SELECT just happens to occur in a URI/Variable Name?

                    //Single Row and Column implies ASK/DESCRIBE/CONSTRUCT results
                    bool result;
                    int r;
                    decimal rdec;
                    double rdbl;
                    float rflt;

                    if (results.Rows[0][0].ToString().Equals(String.Empty))
                    {
                        //Empty Results
                        finalResult = new SparqlResultSet();
                    }
                    else if (Boolean.TryParse(results.Rows[0][0].ToString(), out result))
                    {
                        //Parseable Boolean so ASK Results
                        finalResult = new SparqlResultSet(result);
                    }
                    else if (Int32.TryParse(results.Rows[0][0].ToString(), out r))
                    {
                        //Parseable Integer so Aggregate SELECT Query Results
                        SparqlResultSet rset = new SparqlResultSet();
                        rset.AddVariable("Result");
                        SparqlResult res = new SparqlResult();
                        res.SetValue("Result", new LiteralNode(null, r.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
                        rset.AddResult(res);

                        finalResult = rset;
                    }
                    else if (Single.TryParse(results.Rows[0][0].ToString(), out rflt))
                    {
                        //Parseable Single so Aggregate SELECT Query Results
                        SparqlResultSet rset = new SparqlResultSet();
                        rset.AddVariable("Result");
                        SparqlResult res = new SparqlResult();
                        res.SetValue("Result", new LiteralNode(null, rflt.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)));
                        rset.AddResult(res);

                        finalResult = rset;
                    }
                    else if (Double.TryParse(results.Rows[0][0].ToString(), out rdbl))
                    {
                        //Parseable Double so Aggregate SELECT Query Results
                        SparqlResultSet rset = new SparqlResultSet();
                        rset.AddVariable("Result");
                        SparqlResult res = new SparqlResult();
                        res.SetValue("Result", new LiteralNode(null, rdbl.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
                        rset.AddResult(res);

                        finalResult = rset;
                    }
                    else if (Decimal.TryParse(results.Rows[0][0].ToString(), out rdec))
                    {
                        //Parseable Decimal so Aggregate SELECT Query Results
                        SparqlResultSet rset = new SparqlResultSet();
                        rset.AddVariable("Result");
                        SparqlResult res = new SparqlResult();
                        res.SetValue("Result", new LiteralNode(null, rdec.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDecimal)));
                        rset.AddResult(res);

                        finalResult = rset;
                    }
                    else
                    {
                        //String so try and parse as Turtle
                        try
                        {
                            //Use StringParser to parse
                            String data = results.Rows[0][0].ToString();
                            TurtleParser ttlparser = new TurtleParser();
                            Graph g = new Graph();
                            StringParser.Parse(g, data, ttlparser);

                            finalResult = g;
                        }
                        catch (RdfParseException)
                        {
                            //If it failed to parse then it might be the result of one of the aggregate
                            //functions that Virtuoso extends Sparql with
                            Graph temp = new Graph();
                            SparqlResultSet rset = new SparqlResultSet();
                            rset.AddVariable(results.Columns[0].ColumnName);
                            SparqlResult res = new SparqlResult();
                            res.SetValue(results.Columns[0].ColumnName, this.LoadNode(temp, results.Rows[0][0]));
                            //Nothing was returned here previously - fix submitted by Aleksandr A. Zaripov [[email protected]]
                            rset.AddResult(res);
                            finalResult = rset;
                        }
                    }
                }
                else
                {
                    //Any other number of rows/columns we have to assume that it's normal SELECT results
                    //Changed in response to bug report by Aleksandr A. Zaripov [[email protected]]

                    //SELECT Query Results
                    SparqlResultSet rset = new SparqlResultSet();
                    rset.SetResult(true);

                    //Get Result Variables
                    foreach (DataColumn col in results.Columns)
                    {
                        rset.AddVariable(col.ColumnName);
                    }
                    Graph temp = new Graph();

                    //Convert each solution into a SPARQLResult
                    foreach (DataRow r in results.Rows)
                    {
                        SparqlResult result = new SparqlResult();
                        foreach (String var in rset.Variables)
                        {
                            if (r[var] != null)
                            {
                                result.SetValue(var, this.LoadNode(temp, r[var]));
                            }
                        }
                        rset.AddResult(result);
                    }

                    finalResult = rset;
                }
            }

            return finalResult;
        }