Ejemplo n.º 1
0
        public void FromSameConnectionSequentially()
        {
            IEnumerable <Tuple <DataTable, Func <string, string> > > tuples = new List <Tuple <DataTable, Func <string, string> > >
            {
                new Tuple <DataTable, Func <string, string> >(new DataTable(), schemaName => String.Format("select * from {0}.{1};", schemaName, TestConfig.Table1)),
                new Tuple <DataTable, Func <string, string> >(new DataTable(), schemaName => String.Format("select * from {0}.{1};", schemaName, TestConfig.Table2)),
            };

            using (var conn = new VerticaConnection(TestConfig.ConnectionString))
            {
                conn.Open();
                using (var tx = conn.BeginTransaction())
                {
                    foreach (var tuple in tuples)
                    {
                        using (var command = conn.CreateCommand())
                        {
                            command.CommandText = tuple.Item2(TestConfig.SchemaName);
                            var verticaDataReader = command.ExecuteReader();
                            tuple.Item1.Load(verticaDataReader);
                        }
                    }
                    tx.Commit();
                }
            }

            Assert.True(tuples.All(t => t.Item1.Rows.Count > 0), "Data should be loaded from all rows");
        }
Ejemplo n.º 2
0
        public void PrepareWriteData(int v)
        {
            if (v > variables)
            {
                checkcom = null;
            }
            variables = v;
            coms.Clear();
            System.Random r   = new Random();
            StringBuilder con = new StringBuilder();

            con.Append("insert /*+ AUTO */ into mydata\n\t");
            VerticaCommand command;

            for (int i = 1; i <= variables; i++)
            {
                if (i >= 1000 && (i % 1000 == 0))
                {
                    command             = client.CreateCommand();
                    command.CommandText = con.ToString();
                    coms.Add(command);
                    con.Clear();
                    con.Append("insert /*+ AUTO */ into mydata\n\t");
                }
                DateTime ts    = DateTime.UtcNow;
                int      upVal = r.Next(1, 1000000);
                if (i == max_var)
                {
                    ts_max = ts;
                }
                con.Append(" select 'testinstance_" + i + "','OK', TIMESTAMP '" + ts.ToString("yyyy-MM-dd hh:mm:ss.ffffff", dtfi) + "', " + upVal.ToString());
                if (i != variables && ((i + 1) % 1000 != 0))
                {
                    con.Append(" UNION ");
                }
            }
            command             = client.CreateCommand();
            command.CommandText = con.ToString();
            command.Prepare();
            coms.Add(command);
        }
Ejemplo n.º 3
0
        public void ResultLargerThanBufferWhenReadShouldFail()
        {
            var result = new DataTable();

            using (var conn = new VerticaConnection(TestConfig.ConnectionString))
            {
                conn.Open();
                using (var tx = conn.BeginTransaction())
                    using (var command = conn.CreateCommand())
                    {
                        command.CommandText = String.Format("Select * from {0}.{1} limit 2000;",
                                                            TestConfig.SchemaName, TestConfig.LargeTable);

                        var verticaDataReader = command.ExecuteReader();
                        result.Load(verticaDataReader);
                        tx.Commit();
                    }
            }

            Assert.That(result.Rows.Count, Is.EqualTo(2000));
        }
Ejemplo n.º 4
0
        public static DataTable Get(int id)
        {
            var dataTable = new DataTable();

            try
            {
                Console.WriteLine("[ID:{0}] using connection string :{1}", id, TestConfig.ConnectionString);
                using (var conn = new VerticaConnection(TestConfig.ConnectionString))
                {
                    conn.Open();
                    using (var tx = conn.BeginTransaction())
                        using (var command = conn.CreateCommand())
                        {
                            Console.WriteLine("[ID:{0}] thread id is :{1}", id,
                                              Thread.CurrentThread.ManagedThreadId);

                            command.Transaction = tx;
                            command.CommandText = String.Format("Select * from dual;");
                            var reader = command.ExecuteReader();
                            Console.WriteLine("[ID:{0}] Start reading ", id);
                            dataTable.Load(reader);
                            Console.WriteLine("[ID:{0}] Finished reading", id);
                            if (id % 2 == 0)
                            {
                                Console.WriteLine("[ID:{0}] going to sleep", id);
                                Thread.Sleep(1000 * 10);
                                Console.WriteLine("[ID:{0}] Waking Up", id);
                            }
                            Console.WriteLine("[ID:{0}] Finished executing", id);
                            tx.Commit();
                        }
                }
                return(dataTable);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                throw;
            }
        }