Ejemplo n.º 1
0
        private void CreateTable()
        {
            VirtuosoCommand cmd = new VirtuosoCommand();

            cmd.Connection = connection;

            try
            {
                cmd.CommandText = "drop table foo";
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
            }

            cmd.CommandText = "create table foo (id int primary key, c long varchar, nc long nvarchar, b long varbinary)";
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            checkTable = new DataTable();
            checkTable.Columns.Add("id", typeof(int));
            checkTable.Columns.Add("c", typeof(string));
            checkTable.Columns.Add("nc", typeof(string));
            checkTable.Columns.Add("b", typeof(byte[]));
        }
Ejemplo n.º 2
0
        public static int add_data(int nrows)
        {
            Object port = AppDomain.CurrentDomain.GetData("OpenLink.Virtuoso.InProcessPort");

            if (port == null)
            {
                throw new Exception("not running as a hosted module");
            }

            VirtuosoConnection c = new VirtuosoConnection("HOST=:in-process:" + port.ToString()
                                                          + ";UID=dummy;PWD=dummy");
            int i;

            c.Open();
            new VirtuosoCommand("exec_result_names (vector ('x'))", c).ExecuteNonQuery();

            VirtuosoCommand cmd = new VirtuosoCommand("result (?)", c);

            cmd.Parameters.Add(":1", SqlDbType.Int);

            for (i = 0; i < nrows; i++)
            {
                cmd.Parameters[":1"].Value = i;
                cmd.ExecuteNonQuery();
            }
            cmd = null;
            c.Close();
            return(0);
        }
Ejemplo n.º 3
0
      public static int add_data (int nrows)
	{
	  Object port = AppDomain.CurrentDomain.GetData("OpenLink.Virtuoso.InProcessPort");

	  if (port == null)
	    throw new Exception ("not running as a hosted module");

	  VirtuosoConnection c = new VirtuosoConnection ("HOST=:in-process:" + port.ToString()
	      + ";UID=dummy;PWD=dummy");
	  int i;

	  c.Open();
          new VirtuosoCommand ("exec_result_names (vector ('x'))", c).ExecuteNonQuery ();
	  
	  VirtuosoCommand cmd = new VirtuosoCommand ("result (?)", c);
	  cmd.Parameters.Add (":1", SqlDbType.Int);

	  for (i = 0; i < nrows; i++)
	    {
	      cmd.Parameters[":1"].Value = i;
	      cmd.ExecuteNonQuery ();
	    }
	  cmd = null;
	  c.Close();
	  return 0;
	}
Ejemplo n.º 4
0
        public void InitBuffer()
        {
            // размер буфера
            int bufferportion = 1000;
            // размер порции для внедрения данных
            int portion = 40;

            b_entities = new BufferredProcessing <string>(bufferportion, flow =>
            {
                var query = flow.Select((ent, i) => new { e = ent, i = i }).GroupBy(ei => ei.i / portion, ei => ei);

                VirtuosoCommand trcommand = engine.RunStart();
                foreach (var q in query)
                {
                    string data = q.Select(ei => ei.e + " . ")
                                  .Aggregate((sum, s) => sum + " " + s);
                    //bool found = q.Any(ei => ei.e.s == "Gury_Marchuk");
                    trcommand.CommandText = "SPARQL INSERT INTO GRAPH <" + graph + "> {" + data + "}\n";
                    try
                    {
                        trcommand.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                    }
                }
                engine.RunStop(trcommand);
            });
        }
Ejemplo n.º 5
0
        public void OutputParameters(TestCaseResult result)
        {
            DropProcedure();
            ExecuteNonQuery(
                "create procedure bar (in x integer, out y integer, inout z integer)\n" +
                "{\n" +
                "  y := x * 2;\n" +
                "  z := z * 2;\n" +
                "  return y + z;\n" +
                "}\n"
                );

            VirtuosoCommand command = connection.CreateCommand();

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

            VirtuosoParameter returnValue = command.CreateParameter();

            returnValue.ParameterName = "ReturnValue";
            returnValue.Direction     = ParameterDirection.ReturnValue;
            returnValue.VirtDbType    = VirtDbType.Integer;
            command.Parameters.Add(returnValue);

            VirtuosoParameter x = command.CreateParameter();

            x.ParameterName = "x";
            x.Direction     = ParameterDirection.Input;
            x.VirtDbType    = VirtDbType.Integer;
            x.Value         = 2;
            command.Parameters.Add(x);

            VirtuosoParameter y = command.CreateParameter();

            y.ParameterName = "y";
            y.Direction     = ParameterDirection.Output;
            y.VirtDbType    = VirtDbType.Integer;
            command.Parameters.Add(y);

            VirtuosoParameter z = command.CreateParameter();

            z.ParameterName = "z";
            z.Direction     = ParameterDirection.InputOutput;
            z.VirtDbType    = VirtDbType.Integer;
            z.Value         = 3;
            command.Parameters.Add(z);

            try
            {
                command.ExecuteNonQuery();
                result.FailIfNotEqual(this, "Return Value", 10, returnValue.Value);
                result.FailIfNotEqual(this, "Out Parameter", 4, y.Value);
                result.FailIfNotEqual(this, "InOut Parameter", 6, z.Value);
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 6
0
        private void CreateTable()
        {
            VirtuosoCommand create = connection.CreateCommand();

            create.CommandText = "create table xmlt (id int primary key, data long xml)";
            create.ExecuteNonQuery();
            create.Dispose();
        }
Ejemplo n.º 7
0
        private void InsertRowText()
        {
            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText = "insert into xmlt (id, data) values (1, ?)";
            insert.Parameters.Add(new VirtuosoParameter(":0", TheXml));
            insert.ExecuteNonQuery();
            insert.Dispose();
        }
Ejemplo n.º 8
0
        private void ExecuteNonQuery(string text)
        {
            VirtuosoCommand command = connection.CreateCommand();

            command.CommandText = text;
            try
            {
                command.ExecuteNonQuery();
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 9
0
        public void DelayLessThanTimeout(TestCaseResult result)
        {
            VirtuosoCommand command = connection.CreateCommand();

            try
            {
                command.CommandTimeout = 50;
                command.CommandText    = "delay(5)";
                command.ExecuteNonQuery();
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 10
0
 internal void Sleep()
 {
     command.CommandText    = "delay(" + delay + ")";
     command.CommandTimeout = timeout;
     Console.WriteLine(name + ": started (" + command.CommandText + ").");
     try
     {
         command.ExecuteNonQuery();
     }
     catch (SystemException e)
     {
         Console.WriteLine(name + ":" + e);
     }
     Console.WriteLine(name + ": finished.");
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Executes a Non-Query SQL Command against the database
        /// </summary>
        /// <param name="sqlCmd">SQL Command</param>
        public override void ExecuteNonQuery(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
            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 13
0
        protected void ExecuteDirectQuery(string queryString, ITransaction transaction = null)
        {
            VirtuosoCommand command = null;

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

                Log?.Invoke(queryString);

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

                command.ExecuteNonQuery();
            }
            catch (InvalidOperationException)
            {
                Debug.WriteLine("Caught InvalidOperationExcetion.");
            }
            catch (VirtuosoException e)
            {
                if (e.Errors.Count > 0)
                {
                    var er = e.Errors[0];

                    if (er.SQLState == "40001")
                    {
                        throw new ResourceLockedException(e);
                    }
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }
            }
        }
Ejemplo n.º 14
0
        private void ExecuteDropCommand(string text)
        {
            VirtuosoCommand command = connection.CreateCommand();;

            command.CommandText = text;
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception)
            {
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 15
0
        private void DropTable()
        {
            VirtuosoCommand drop = connection.CreateCommand();

            drop.CommandText = "drop table xmlt";
            try
            {
                drop.ExecuteNonQuery();
            }
            catch (Exception)
            {
            }
            finally
            {
                drop.Dispose();
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        public void TestInsertSqlXml(TestCaseResult result)
        {
            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText = "insert into xmlt (id, data) values (1, ?)";
            insert.Parameters.Add(new VirtuosoParameter(":0", new SqlXml(TheXml)));
            insert.ExecuteNonQuery();
            insert.Dispose();

            VirtuosoCommand cmd = connection.CreateCommand();

            cmd.CommandText = "select data from xmlt";

            VirtuosoDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            SqlXml x = rdr.GetSqlXml(0);

            FailIfXmlNotEqual(result, x.ToString(), TheXml);
        }
Ejemplo n.º 18
0
        public void DelayMoreThanTimeout(TestCaseResult result)
        {
            VirtuosoCommand command = connection.CreateCommand();
            bool            thrown  = false;

            try
            {
                command.CommandTimeout = 5;
                command.CommandText    = "delay(50)";
                command.ExecuteNonQuery();
            }
            catch (SystemException)
            {
                thrown = true;
            }
            finally
            {
                command.Dispose();
            }
            result.FailIfNot("No timeout exception is thrown", thrown);
        }
Ejemplo n.º 19
0
        private void InsertRow(int id)
        {
            object i, si, d, r, n, year, month, day, dt, tm, dtm, str, bin;

            if (id == 0)
            {
                i = si = d = r = n = year = month = day = dt = tm = dtm = str = bin = DBNull.Value;
            }
            else
            {
                i     = id + 1000;
                si    = (short)(id + 2000);
                d     = id * 1000.0001;
                r     = (float)(id * 100.001);
                n     = (decimal)id * 10000001;
                year  = 1990 + id;
                month = (id - 1) % 12 + 1;
                day   = (id - 1) % DateTime.DaysInMonth((int)year, (int)month) + 1;
                dt    = new DateTime((int)year, (int)month, (int)day);
                tm    = new TimeSpan(id % 24, id % 60, id % 60);
                dtm   = new DateTime((int)year, (int)month, (int)day, id % 24, id % 60, id % 60);

                int    length = id % 128;
                char[] chars  = new char[length];
                byte[] bytes  = new byte[length];
                for (int count = 0; count < length; count++)
                {
                    chars[count] = (char)('a' + (id + count) % 26 - 1);
                    bytes[count] = (byte)(id + count);
                }
                str = new String(chars);
                bin = bytes;
            }

            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText =
                "insert into foo "
                + "(id, i, si, d, r, n, dt, tm, dtm, c, vc, lvc, nc, nvc, lnvc, b, vb, lvb) "
                + "values "
                + "(?,  ?,  ?, ?, ?, ?,  ?,  ?,   ?, ?,  ?,   ?,  ?,   ?,    ?, ?,  ?,   ?)";

            VirtuosoParameterCollection parameters = insert.Parameters;

            VirtuosoParameter idParam = insert.CreateParameter();

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

            VirtuosoParameter iParam = insert.CreateParameter();

            iParam.ParameterName = "i";
            iParam.DbType        = DbType.Int32;
            iParam.Value         = i;
            parameters.Add(iParam);

            VirtuosoParameter siParam = insert.CreateParameter();

            siParam.ParameterName = "si";
            siParam.DbType        = DbType.Int16;
            siParam.Value         = si;
            parameters.Add(siParam);

            VirtuosoParameter dParam = insert.CreateParameter();

            dParam.ParameterName = "d";
            dParam.DbType        = DbType.Double;
            dParam.Value         = d;
            parameters.Add(dParam);

            VirtuosoParameter rParam = insert.CreateParameter();

            rParam.ParameterName = "r";
            rParam.DbType        = DbType.Single;
            rParam.Value         = r;
            parameters.Add(rParam);

            VirtuosoParameter nParam = insert.CreateParameter();

            nParam.ParameterName = "n";
            nParam.DbType        = DbType.Decimal;
            nParam.Value         = n;
            parameters.Add(nParam);

            VirtuosoParameter dtParam = insert.CreateParameter();

            dtParam.ParameterName = "dt";
            dtParam.DbType        = DbType.Date;
            dtParam.Value         = dt;
            parameters.Add(dtParam);

            VirtuosoParameter tmParam = insert.CreateParameter();

            tmParam.ParameterName = "tm";
            tmParam.DbType        = DbType.Time;
            tmParam.Value         = tm;
            parameters.Add(tmParam);

            VirtuosoParameter dtmParam = insert.CreateParameter();

            dtmParam.ParameterName = "dtm";
            dtmParam.DbType        = DbType.DateTime;
            dtmParam.Value         = dtm;
            parameters.Add(dtmParam);

            VirtuosoParameter cParam = insert.CreateParameter();

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

            VirtuosoParameter vcParam = insert.CreateParameter();

            vcParam.ParameterName = "vc";
            vcParam.DbType        = DbType.AnsiString;
            vcParam.Value         = str;
            parameters.Add(vcParam);

            VirtuosoParameter lvcParam = insert.CreateParameter();

            lvcParam.ParameterName = "lvc";
            lvcParam.DbType        = DbType.AnsiString;
            lvcParam.Value         = str;
            parameters.Add(lvcParam);

            VirtuosoParameter ncParam = insert.CreateParameter();

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

            VirtuosoParameter nvcParam = insert.CreateParameter();

            nvcParam.ParameterName = "nvc";
            nvcParam.DbType        = DbType.String;
            nvcParam.Value         = str;
            parameters.Add(nvcParam);

            VirtuosoParameter lnvcParam = insert.CreateParameter();

            lnvcParam.ParameterName = "lnvc";
            lnvcParam.DbType        = DbType.String;
            lnvcParam.Value         = str;
            parameters.Add(lnvcParam);

            VirtuosoParameter bParam = insert.CreateParameter();

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

            VirtuosoParameter vbParam = insert.CreateParameter();

            vbParam.ParameterName = "vb";
            vbParam.DbType        = DbType.Binary;
            vbParam.Value         = bin;
            parameters.Add(vbParam);

            VirtuosoParameter lvbParam = insert.CreateParameter();

            lvbParam.ParameterName = "lvb";
            lvbParam.DbType        = DbType.Binary;
            lvbParam.Value         = bin;
            parameters.Add(lvbParam);

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

            DataRow row = checkTable.NewRow();

            row["id"]   = id;
            row["i"]    = i;
            row["si"]   = si;
            row["d"]    = d;
            row["r"]    = r;
            row["n"]    = n;
            row["dt"]   = dt;
            row["tm"]   = tm;
            row["dtm"]  = dtm;
            row["c"]    = str;
            row["vc"]   = str;
            row["lvc"]  = str;
            row["nc"]   = str;
            row["nvc"]  = str;
            row["lnvc"] = str;
            row["b"]    = bin;
            row["vb"]   = bin;
            row["lvb"]  = bin;
            checkTable.Rows.Add(row);
        }
Ejemplo n.º 20
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);
        }