Exemplo n.º 1
0
        public void TestBatchLoad()
        {
            EsgynDBConnection conn = new EsgynDBConnection();

            conn.ConnectionString = ConnectionString;
            conn.Open();

            EsgynDBCommand cmd = conn.CreateCommand();

            prepareTable(cmd);

            //start loading...
            log.Info("Start loading...");
            cmd.CommandText = "upsert using load into t0 values(?,?)";
            cmd.Parameters.Add(new EsgynDBParameter("c0", EsgynDBType.Varchar));
            cmd.Parameters.Add(new EsgynDBParameter("c1", EsgynDBType.Varchar));

            log.Info("Prepare the insertion sql");
            cmd.Prepare();

            log.Info("Put rows into batch");
            for (int i = 0; i < 10; i++)
            {
                cmd.Parameters[0].Value = "test col-" + i;
                cmd.Parameters[1].Value = "test col " + (i * 2 + 1);
                cmd.AddBatch();
            }

            log.Info("Execute batch");
            cmd.ExecuteNonQuery();

            //Check all inserted data
            log.Info("Check all inserted data");
            cmd.Parameters.Clear();
            cmd.CommandText = "select * from t0";
            EsgynDBDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                for (int i = 0; i < dr.FieldCount; i++)
                {
                    log.Info(dr.GetValue(i) + " " + dr.GetDataTypeName(i));
                }
            }
        }
Exemplo n.º 2
0
        public void setCQDs()
        {
            using (EsgynDBConnection conn = new EsgynDBConnection())
            {
                conn.ConnectionString = ConnectionString;
                conn.Open();
                EsgynDBCommand cmd = conn.CreateCommand();
                log.Info("ESP_INACTIVE_TIMEOUT '66666'");
                cmd.CommandText = "SET SESSION DEFAULT ESP_INACTIVE_TIMEOUT '666666'";
                cmd.ExecuteNonQuery();
                log.Info("ESP_IDLE_TIMEOUT '77777'");
                cmd.CommandText = "SET SESSION DEFAULT ESP_IDLE_TIMEOUT '666666'";
                cmd.ExecuteNonQuery();
                log.Info("SHOWCONTROL_SHOW_ALL 'on'!");
                cmd.CommandText = "CONTROL QUERY DEFAULT SHOWCONTROL_SHOW_ALL 'on'";
                cmd.ExecuteNonQuery();

                log.Info("SHOWCONTROL ALL!");
                cmd.CommandText = "SHOWCONTROL ALL";
                EsgynDBDataReader ca = cmd.ExecuteReader();
                bool flag            = false;
                while (ca.Read())
                {
                    if (!flag)
                    {
                        flag = true;
                    }
                    log.Info(ca.GetValue(0) + "");
                }
                log.Info("Done!");

                /*
                 *
                 * Continue to do whatever you want...
                 *
                 */

                Assert.IsTrue(flag, "No data in query 'SHOWCONTROL ALL'");
            }
        }
Exemplo n.º 3
0
        public void TestBatch()
        {
            try
            {
                using (EsgynDBConnection conn = new EsgynDBConnection())
                {
                    conn.ConnectionString = ConnectionString;
                    conn.Open();

                    using (EsgynDBCommand cmd = conn.CreateCommand())
                    {
                        try
                        {
                            cmd.CommandText = "drop table t0";
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            log.Warn(e.Message);
                        }

                        cmd.CommandText = "create table t0 (c1 varchar(20), c2 nchar(20)) no partition";
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = "insert into t0 values(?,?)";
                        cmd.Parameters.Add(new EsgynDBParameter("c0", EsgynDBType.Varchar));
                        cmd.Parameters.Add(new EsgynDBParameter("c1", EsgynDBType.Varchar));

                        cmd.Prepare();

                        for (int i = 0; i < 10; i++)
                        {
                            if (i == 2)
                            {
                                cmd.Parameters[0].Value = "test col1";
                            }
                            else
                            {
                                cmd.Parameters[0].Value = "test col1rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr";
                            }
                            cmd.Parameters[1].Value = "test col2";
                            cmd.AddBatch();
                            log.Info(cmd.Parameters[0].Value);
                        }

                        //cmd.ExecuteNonQuery();
                        //Console.Read();

                        cmd.ExecuteNonQuery();

                        log.Info("start to select ....");
                        cmd.Parameters.Clear();
                        cmd.CommandText = "select * from t0";
                        using (EsgynDBDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                for (int i = 0; i < dr.FieldCount; i++)
                                {
                                    log.Info(dr.GetValue(i) + " " + dr.GetDataTypeName(i));
                                }
                            }
                        }
                    }
                }
            }
            catch (EsgynDBException e)
            {
                log.Info(e.ToString());
                for (int i = 0; i < e.Errors.Count; i++)
                {
                    log.Info(e.Errors[i]);
                }
            }
        }