Ejemplo n.º 1
0
        public void TestCommonBulkCopy()
        {
            var sql = new SqlStatement("SELECT [Id],[Name] FROM [Books] ORDER BY [Id]");
            var rcs = new List <long>();

            DbEntry.Provider.ExecuteDataReader(sql, delegate(IDataReader dr)
            {
                DbEntry.NewConnection(delegate
                {
                    IDbBulkCopy c          = _sqlite.GetDbBulkCopy(false);
                    c.BatchSize            = 2;
                    c.DestinationTableName = "test";
                    c.NotifyAfter          = 3;
                    c.SqlRowsCopied       += ((sender, e) => rcs.Add(e.RowsCopied));
                    c.WriteToServer(dr);
                });
            });
            Assert.AreEqual(1, rcs.Count);
            Assert.AreEqual(3, rcs[0]);

            Assert.AreEqual(5, StaticRecorder.Messages.Count);

            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=1:Int64,@Name_1=Diablo:String)", StaticRecorder.Messages[0]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=2:Int64,@Name_1=Beijing:String)", StaticRecorder.Messages[1]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=3:Int64,@Name_1=Shanghai:String)", StaticRecorder.Messages[2]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=4:Int64,@Name_1=Pal95:String)", StaticRecorder.Messages[3]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=5:Int64,@Name_1=Wow:String)", StaticRecorder.Messages[4]);
        }
Ejemplo n.º 2
0
        public void TestCommonBulkCopyAbort()
        {
            var sql = new SqlStatement("SELECT [Id],[Name] FROM [Books] ORDER BY [Id]");

            DbEntry.Provider.ExecuteDataReader(sql, delegate(IDataReader dr)
            {
                DbEntry.NewConnection(delegate
                {
                    IDbBulkCopy c          = _sqlite.GetDbBulkCopy(false);
                    c.BatchSize            = 2;
                    c.DestinationTableName = "test";
                    c.NotifyAfter          = 3;
                    c.SqlRowsCopied       += delegate(object sender, SqlRowsCopiedEventArgs e)
                    {
                        e.Abort = true;
                    };
                    c.WriteToServer(dr);
                });
            });
            Assert.AreEqual(3, StaticRecorder.Messages.Count);

            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=1:Int64,@Name_1=Diablo:String)", StaticRecorder.Messages[0]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=2:Int64,@Name_1=Beijing:String)", StaticRecorder.Messages[1]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name]) VALUES (@Id_0,@Name_1);\n<Text><30>(@Id_0=3:Int64,@Name_1=Shanghai:String)", StaticRecorder.Messages[2]);
        }
Ejemplo n.º 3
0
 protected void BulkCopy(string sql, bool identityInsert)
 {
     Src.ExecuteDataReader(new SqlStatement(sql), dr =>
     {
         DbEntry.NewConnection(delegate
         {
             IDbBulkCopy c          = Dest.GetDbBulkCopy(identityInsert);
             c.BatchSize            = _batchSize;
             c.DestinationTableName = DestinationTableName;
             c.NotifyAfter          = _notifyAfter;
             c.SqlRowsCopied       += (sender, e) => Console.WriteLine("{0}: {1}", DestinationTableName, e.RowsCopied);
             c.WriteToServer(dr);
         });
     });
     Console.WriteLine("{0} ({1}) copied!", DestinationTableName, _times++);
 }
Ejemplo n.º 4
0
        public void TestBulkCopyWithNullValue()
        {
            var sql = new SqlStatement("SELECT [Id],[Name],[MyInt],[MyBool] FROM [NullTest] ORDER BY [Id]");

            DbEntry.Provider.ExecuteDataReader(sql, delegate(IDataReader dr)
            {
                DbEntry.NewConnection(delegate
                {
                    IDbBulkCopy c          = _sqlite.GetDbBulkCopy(false);
                    c.BatchSize            = 2;
                    c.DestinationTableName = "test";
                    c.NotifyAfter          = 3;
                    c.WriteToServer(dr);
                });
            });
            Assert.AreEqual(4, StaticRecorder.Messages.Count);

            // TODO: why null value is single type ?
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name],[MyInt],[MyBool]) VALUES (@Id_0,@Name_1,@MyInt_2,@MyBool_3);\n<Text><30>(@Id_0=1:Int64,@Name_1=tom:String,@MyInt_2=<NULL>:Single,@MyBool_3=True:Boolean)", StaticRecorder.Messages[0]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name],[MyInt],[MyBool]) VALUES (@Id_0,@Name_1,@MyInt_2,@MyBool_3);\n<Text><30>(@Id_0=2:Int64,@Name_1=<NULL>:Single,@MyInt_2=1:Int32,@MyBool_3=False:Boolean)", StaticRecorder.Messages[1]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name],[MyInt],[MyBool]) VALUES (@Id_0,@Name_1,@MyInt_2,@MyBool_3);\n<Text><30>(@Id_0=3:Int64,@Name_1=<NULL>:Single,@MyInt_2=<NULL>:Single,@MyBool_3=<NULL>:Single)", StaticRecorder.Messages[2]);
            Assert.AreEqual("INSERT INTO [test] ([Id],[Name],[MyInt],[MyBool]) VALUES (@Id_0,@Name_1,@MyInt_2,@MyBool_3);\n<Text><30>(@Id_0=4:Int64,@Name_1=tom:String,@MyInt_2=1:Int32,@MyBool_3=True:Boolean)", StaticRecorder.Messages[3]);
        }