Пример #1
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);
        }
Пример #2
0
        public void DelayLessThanTimeout(TestCaseResult result)
        {
            VirtuosoCommand command = connection.CreateCommand();

            try
            {
                command.CommandTimeout = 50;
                command.CommandText    = "delay(5)";
                command.ExecuteNonQuery();
            }
            finally
            {
                command.Dispose();
            }
        }
Пример #3
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]);
                }
            }
        }
Пример #4
0
        public void DeriveParamters(TestCaseResult result)
        {
            DropProcedure();
            ExecuteNonQuery(
                "create function BAR (in X integer, out Y integer, inout Z integer, in V varchar(20), in W nvarchar(20), in D numeric(20, 5)) returns real\n" +
                "{\n" +
                "  return 0.0;\n" +
                "}\n"
                );

            VirtuosoCommand command = connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "BAR";

            try
            {
                VirtuosoCommandBuilder.DeriveParameters(command);
                result.FailIfNotEqual("Parameter Count", 7, command.Parameters.Count);
                CheckParameter(result, command.Parameters[0],
                               "ReturnValue", ParameterDirection.ReturnValue, VirtDbType.Real, DbType.Single,
                               4, 0, 0);          // FIXME: The precision should be 7.
                CheckParameter(result, command.Parameters[1],
                               "X", ParameterDirection.Input, VirtDbType.Integer, DbType.Int32,
                               4, 10, 0);
                CheckParameter(result, command.Parameters[2],
                               "Y", ParameterDirection.Output, VirtDbType.Integer, DbType.Int32,
                               4, 10, 0);
                CheckParameter(result, command.Parameters[3],
                               "Z", ParameterDirection.InputOutput, VirtDbType.Integer, DbType.Int32,
                               4, 10, 0);
                CheckParameter(result, command.Parameters[4],
                               "V", ParameterDirection.Input, VirtDbType.VarChar, DbType.AnsiString,
                               20, 0, 0);
                CheckParameter(result, command.Parameters[5],
                               "W", ParameterDirection.Input, VirtDbType.NVarChar, DbType.String,
                               20, 0, 0);
                CheckParameter(result, command.Parameters[6],
                               "D", ParameterDirection.Input, VirtDbType.Decimal, DbType.Decimal,
                               19, 20, 5);
            }
            finally
            {
                command.Dispose();
            }
        }
Пример #5
0
        private void DropTable()
        {
            VirtuosoCommand drop = connection.CreateCommand();

            drop.CommandText = "drop table foo";
            try
            {
                drop.ExecuteNonQuery();
            }
            catch (Exception)
            {
            }
            finally
            {
                drop.Dispose();
            }
        }
Пример #6
0
        public int Execute(string sparql)
        {
            if (connection.State == System.Data.ConnectionState.Open)
            {
                connection.Close();
            }
            connection.Open();
            var command = connection.CreateCommand();

            //var db = connection.Database;
            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = sparql;
            int val = command.ExecuteNonQuery();

            connection.Close();
            return(val);
        }
Пример #7
0
        public void TestGetString(TestCaseResult result)
        {
            InsertRowText();

            VirtuosoCommand cmd = connection.CreateCommand();

            cmd.CommandText = "select data from xmlt";

            VirtuosoDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            String x = rdr.GetString(0);

            FailIfXmlNotEqual(result, x, TheXml);
        }
Пример #8
0
        public void CreateTable(VirtuosoConnection connection)
        {
            VirtuosoCommand create = connection.CreateCommand();

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

            checkTable = new DataTable();
            checkTable.Columns.Add("id", typeof(int));
            checkTable.Columns.Add("txt", typeof(string));

            InsertRow(connection, 1);
            InsertRow(connection, 2);
        }
Пример #9
0
        public void InsertRow(VirtuosoConnection connection, int i)
        {
            string s = new string (new char[3] {
                (char)('a' + i), (char)('b' + i), (char)('c' + i)
            });

            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText = "insert into foo values (" + i + ", '" + s + "')";
            insert.ExecuteNonQuery();
            insert.Dispose();

            DataRow row = checkTable.NewRow();

            row["id"]  = i;
            row["txt"] = s;
            checkTable.Rows.Add(row);
        }
Пример #10
0
        public void DisposeNewCommand(TestCaseResult result)
        {
            VirtuosoCommand command = connection.CreateCommand();

            command.Dispose();
        }
Пример #11
0
        private void InsertRow(int id)
        {
            object c, nc, b;

            if (id == 0)
            {
                c = nc = b = DBNull.Value;
            }
            else
            {
                int    length = 1 << (id - 1);
                char[] chars  = new char[length];
                byte[] bytes  = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    chars[i] = (char)(' ' + i % (127 - ' '));
                    bytes[i] = (byte)(i % 256);
                }
                c = nc = new String(chars);
                b = bytes;
            }

            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText =
                "insert into foo "
                + "(id, c, nc, b) "
                + "values "
                + "(?,  ?,  ?, ?)";

            VirtuosoParameterCollection parameters = insert.Parameters;

            VirtuosoParameter idParam = insert.CreateParameter();

            idParam.ParameterName = "id";
            idParam.DbType        = DbType.Int32;
            idParam.Value         = id;
            parameters.Add(idParam);

            VirtuosoParameter cParam = insert.CreateParameter();

            cParam.ParameterName = "c";
            cParam.DbType        = DbType.AnsiString;
            cParam.Value         = c;
            parameters.Add(cParam);

            VirtuosoParameter ncParam = insert.CreateParameter();

            ncParam.ParameterName = "nc";
            ncParam.DbType        = DbType.String;
            ncParam.Value         = nc;
            parameters.Add(ncParam);

            VirtuosoParameter bParam = insert.CreateParameter();

            bParam.ParameterName = "b";
            bParam.DbType        = DbType.Binary;
            bParam.Value         = b;
            parameters.Add(bParam);

            try
            {
                insert.ExecuteNonQuery();
            }
            finally
            {
                insert.Dispose();
                insert = null;
            }

            DataRow row = checkTable.NewRow();

            row["id"] = id;
            row["c"]  = c;
            row["nc"] = nc;
            row["b"]  = b;
            checkTable.Rows.Add(row);
        }