예제 #1
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);

            try
            {
                var res = db.Table <SomeData>()
                          .Select(f => new
                {
                    PeriodId = f.PeriodId + 1
                });
                throw new Exception("Assert failure");
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("Linqdb: Select must not have any expressions"))
                {
                    throw new Exception("Assert failure");
                }
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #2
0
        public void Do(Db db)
        {
            if (db == null)
            {
                db = new Db("DATA");
            }
#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
            //db.Table<SomeData>().Delete(new HashSet<int>(db.Table<SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            var res = db.Table <SomeData>().SelectEntity();
            if (res.Any(f => f.Id < 0))
            {
                var a = res.Where(f => f.Id <= 0).ToList();
            }
            db.Table <SomeData>().CreatePropertyMemoryIndex(f => f.PeriodId);
            db.Table <SomeData>().CreatePropertyMemoryIndex(f => f.Id);
            //db.Table<SomeData>().CreatePropertyMemoryIndex(f => f.Normalized);
            //db.Table<SomeData>().CreatePropertyMemoryIndex(f => f.ObjectId);
            db.Table <SomeData>().CreatePropertyMemoryIndex(f => f.Value);
            //db.Table<SomeData>().CreatePropertyMemoryIndex(f => f.Date);
            //db.Table<SomeData>().CreateGroupByMemoryIndex(f => f.GroupBy, z => z.Normalized);
        }
예제 #3
0
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }
            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new SomeData()
            {
                Id         = 1,
                Normalized = -1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 2,
                Normalized = -0.9,
                PeriodId   = 7
            };
            db.Table <SomeData>().Save(d);
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            var count = db.Table <Testing.tables4.SomeData>().Count();

            var dic = new Dictionary <int, double>()
            {
                { 1, 0 }, { 2, 0 }
            };
            db.Table <Testing.tables4.SomeData>().Update(f => f.SomeDouble, dic);

            var res = db.Table <Testing.tables4.SomeData>().SelectEntity();
            if (res.Count() != 2 || res[0].Value != 0 || res[1].Value != 0)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
예제 #4
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <Counter>().Delete(new HashSet <int>(db.Table <Counter>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var n = new Counter()
            {
                Name  = "test",
                Value = Int32.MaxValue
            };
            db.Table <Counter>()
            .Where(f => f.Name == "test")
            .AtomicIncrement(f => f.Value, 0, n, null);

            db.Table <Counter>()
            .Where(f => f.Name == "test")
            .AtomicIncrement(f => f.Value, 1, n, null);

            n.Value++;
            var c = db.Table <Counter>().Where(f => f.Name == "test").SelectEntity().Single();
            if (n.Value != c.Value)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #5
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <Question>().Delete(new HashSet <int>(db.Table <Question>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var count = db.Table <Question>().Count();
            var q     = new Question();
            db.Table <Question>().Save(q);
            var count2 = db.Table <Question>().Count();
            if (count + 1 != count2)
            {
                throw new Exception("Assert failure");
            }

            var ls     = db.Table <Question>().LastStep();
            var max_id = db.Table <Question>().OrderByDescending(f => f.Id).Take(1).Select(f => new { f.Id }).First().Id;

            if (ls != max_id / 1000)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif


#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #6
0
파일: NewIdTooBig.cs 프로젝트: ren85/linqdb
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            try
            {
                var d = new SomeData()
                {
                    Id       = (Int32.MaxValue / 2) + 1,
                    PeriodId = 5
                };
                db.Table <SomeData>().Save(d);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("max Id value of new item is"))
                {
                    throw new Exception("Assert failure");
                }
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #7
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5,
                Date       = Convert.ToDateTime("2000-01-01"),
                PersonId   = 20,
                Value      = 15.5
            };
            db.Table <SomeData>().Save(d);;


            var res = db.Table <SomeData>()
                      .SelectEntity();
            if (res.Count() != 1 || res[0].Normalized != 1.2 || res[0].Id != 1 || res[0].PeriodId != 5 || res[0].Date != Convert.ToDateTime("2000-01-01") || res[0].ObjectId != null || res[0].PeriodId != 5 || res[0].Value != 15.5)
            {
                throw new Exception(string.Format("Assert failure: {0} != 2.1", res[0].Normalized));
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #8
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif


            using (var transaction = new LinqdbTransaction())
            {
                db.Table <SomeData>(transaction).Delete(new HashSet <int>());
                transaction.Commit();
            }

            using (var transaction = new LinqdbTransaction())
            {
                db.Table <SomeData>(transaction).SaveBatch(new List <SomeData>());
                transaction.Commit();
            }

            using (var transaction = new LinqdbTransaction())
            {
                db.Table <SomeData>(transaction).Update(f => f.Normalized, new Dictionary <int, double?>());
                transaction.Commit();
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #9
0
파일: NewField.cs 프로젝트: ren85/linqdb
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }

            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new Testing.tables4.SomeType()
            {
                Id    = 1,
                Value = 1,
                Name  = "1"
            };
            db.Table <Testing.tables4.SomeType>().Save(d);
            var d2 = new Testing.tables.SomeType()
            {
                Id       = 2,
                Value    = 2,
                PeriodId = 2,
                Name     = "2"
            };
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables.SomeType>().Save(d2);
            var res = db.Table <Testing.tables.SomeType>().Where(f => f.Id == 1).Select(f => new { f.PeriodId });
            if (res.Count() != 1 || res[0].PeriodId != 0)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
예제 #10
0
파일: NoId.cs 프로젝트: ren85/linqdb
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
            var d = new NoIdType()
            {
                A = 5
            };

            string ex_msg = "";
            try
            {
                db.Table <NoIdType>().Save(d);;
            }
            catch (Exception ex)
            {
                ex_msg = ex.Message;
            }

            if (!ex_msg.Contains("Linqdb: type must have integer Id property"))
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #11
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);

            var w = new WhereJob();
            w.db = db;
            w.id = 1;
            w.Do(db);


#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #12
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <Counter>().Delete(new HashSet <int>(db.Table <Counter>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new Counter()
            {
                Id    = 1,
                Name  = "a",
                Value = 5
            };
            db.Table <Counter>().Save(d);

            var res = db.GetTableDefinition("Counter");
            if (res != "public class Counter { public int Id { get; set; } public int? Value { get; set; } public string Name { get; set; }  } " &&
                res != "public class Counter { public int Id { get; set; } public string Name { get; set; } public int? Value { get; set; }  } ")
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #13
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var res = db.Table <SomeData>()
                      .Select(f => new
            {
                PeriodId = f.PeriodId
            });

            if (res.Count() != 0)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #14
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
            db.Queue <QueueA>().GetAllFromQueue();

            var a = new QueueA()
            {
                SomeString = "test123",
                SomeArray  = new List <int>()
                {
                    1, 2, 3
                }
            };

            db.Queue <QueueA>().PutToQueue(a);
            var res = db.Queue <QueueA>().GetAllFromQueue();

            if (res.Count() != 1 || res.Single().SomeString != "test123" || res.Single().SomeArray.Count() != 3 || res.Single().SomeArray[0] != 1)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
        }
예제 #15
0
        public void Do(Db db_)
        {
            bool dispose = true;

            var db = new Db("DATA2", "reader_user", "re@der123");

            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
            var status = db.GetServerStatus(5000);

            if (status.ServerName != "5.5.5.5:2055" || !status.IsUp)
            {
                throw new Exception("Assert failure");
            }

            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA2");
            }
        }
예제 #16
0
파일: GenericType.cs 프로젝트: ren85/linqdb
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            TestGenerics <SomeData>(db, new SomeData());

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #17
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                ObjectId   = 2,
                Normalized = 1
            };
            db.Table <SomeData>().Save(d);

            var res = db.Table <SomeData>()
                      .Where(f => f.ObjectId != null)
                      .Select(f => new
            {
                Id       = f.Id,
                ObjectId = f.ObjectId
            });
            if (res.Count() != 1 || res[0].ObjectId != 2)
            {
                throw new Exception("Assert failure");
            }

            db.Table <SomeData>().Update(f => f.ObjectId, new Dictionary <int, int?>()
            {
                { 1, null }
            });

            res = db.Table <SomeData>()
                  .Where(f => f.ObjectId == null)
                  .Select(f => new
            {
                Id       = f.Id,
                ObjectId = f.ObjectId
            });
            if (res.Count() != 1 || res[0].Id != 1)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #18
0
        public void Do2(Db db)
        {
            bool dispose = false;

            if (db == null)
            {
                dispose = true;
                db      = new Db("DATA");
#if (SERVER)
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
                DoInit = true;
            }
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <Answer>().Delete(new HashSet <int>(db.Table <Answer>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <KaggleClass>().Delete(new HashSet <int>(db.Table <KaggleClass>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            this.db = db;

            int total_answers = 20000;
            var a_list        = new List <Answer>();
            var a_ids         = new List <int>();
            for (int i = 1; i <= total_answers; i++)
            {
                a_ids.Add(i);
                a_list.Add(new Answer()
                {
                    Id          = i,
                    Anwser      = "4 5 6",
                    TitleSearch = "7 8 9"
                });
            }
            db.Table <Answer>().SaveBatch(a_list);

            JobBatch.errors = 0;
            int total = 15000;
            var jobs  = new List <JobBatch>();
            for (int i = 0; i < total; i++)
            {
                jobs.Add(new JobBatch());
            }

            var list = new List <Task>();

            foreach (var job in jobs)
            {
                var t = Task.Run(() => JobBatch.Do(db, a_ids));
                list.Add(t);
            }
            list.ForEach(f => f.Wait());

            if (JobBatch.errors > 0)
            {
                throw new Exception("Assert failure");
            }

            if (db.Table <Answer>().Count() != total_answers - total)
            {
                throw new Exception("Assert failure");
            }

            if (db.Table <KaggleClass>().Count() != total)
            {
                throw new Exception("Assert failure");
            }

            if (DoInit)
            {
#if (SERVER || SOCKETS)
                if (dispose)
                {
                    Logic.Dispose();
                }
#else
                if (dispose)
                {
                    db.Dispose();
                }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
                if (dispose)
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
#endif
            }
        }
예제 #19
0
파일: ChangeType3.cs 프로젝트: ren85/linqdb
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }
            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new Testing.tables5.SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <Testing.tables5.SomeData>().Save(d);
            d = new Testing.tables5.SomeData()
            {
                Id         = 2,
                Normalized = 1.3,
                PeriodId   = 5
            };
            db.Table <Testing.tables5.SomeData>().Save(d);
            d = new Testing.tables5.SomeData()
            {
                Id         = 3,
                Normalized = 1.4,
                PeriodId   = 5
            };
            db.Table <Testing.tables5.SomeData>().Save(d);

#if (SERVER)
            db.Table <Testing.tables5.SomeData>()._internal._db._InternalClearCache();
#endif

            var dic = new Dictionary <int, int>()
            {
                { 2, 1 }
            };
            db.Table <Testing.tables.SomeData>().Update(f => f.GroupBy, dic);

            var res = db.Table <Testing.tables.SomeData>()
                      .Where(f => f.Normalized > 1.1 && f.Normalized < 1.35)
                      .Select(f => new
            {
                f.Id,
                f.GroupBy
            });
            if (res.Count() != 2 || res[0].GroupBy != 0 || res[1].GroupBy != 1)
            {
                throw new Exception("Assert failure");
            }


#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
예제 #20
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <BinaryData2>().Delete(new HashSet <int>(db.Table <BinaryData2>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            int number = 0;
            if (!Environment.Is64BitProcess) //32-bit
            {
                number = 1800;
            }
            else
            {
                number = 3600;
            }
            var list  = new List <BinaryData2>();
            int total = 100000;
            for (int i = 1; i <= total; i++)
            {
                var d = new BinaryData2()
                {
                    Id    = i,
                    Data1 = Enumerable.Range(1, number / 2).Select(f => (byte)1).ToArray(),
                    Data2 = Enumerable.Range(1, number / 2).Select(f => (byte)1).ToArray(),
                };
                list.Add(d);
            }



            for (int i = 0; i <= 100000; i += 1000)
            {
                db.Table <BinaryData2>().SaveBatch(list.Skip(i).Take(1000).ToList());
            }

            var count = db.Table <BinaryData2>().Count();

            try
            {
                try
                {
                    var res = db.Table <BinaryData2>().Select(f => new { f.Id, f.Data1, f.Data2 });
                    throw new Exception("Assert failure");
                }
                catch (Exception ex)
                {
                    if (!ex.Message.Contains("the query resulted in set larger than"))
                    {
                        throw new Exception("Assert failure");
                    }
                }

                try
                {
                    var res = db.Table <BinaryData2>().SelectNonAtomically(f => new { f.Id, f.Data1, f.Data2 });
                    if (res.Count() != total)
                    {
                        throw new Exception("Assert failure");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Assert failure");
                }

                try
                {
                    var res = db.Table <BinaryData2>().SelectEntity();
                    throw new Exception("Assert failure");
                }
                catch (Exception ex)
                {
                    if (!ex.Message.Contains("the query resulted in set larger than"))
                    {
                        throw new Exception("Assert failure");
                    }
                }

                try
                {
                    var res = db.Table <BinaryData2>().SelectEntityNonAtomically();
                    if (res.Count() != total)
                    {
                        throw new Exception("Assert failure");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Assert failure");
                }
            }
            finally
            {
                db.Table <BinaryData2>().Delete(new HashSet <int>(Enumerable.Range(1, 100000).ToList()));
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #21
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 0.9,
                PeriodId   = 7
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 3,
                Normalized = 0.5,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 4,
                Normalized = 4.5,
                PeriodId   = 15
            };
            db.Table <SomeData>().Save(d);;

            var res = db.Table <SomeData>()
                      .Between(f => f.Normalized, 0.1, 0.9)
                      .OrderBy(f => f.PeriodId)
                      .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 2 || res[0].PeriodId != 7 || res[1].PeriodId != 10)
            {
                throw new Exception("Assert failure");
            }

            var dic = new Dictionary <int, int?>();
            dic[2] = 8;
            dic[3] = 11;
            db.Table <SomeData>().Update(f => f.PeriodId, dic);

            res = db.Table <SomeData>()
                  .Between(f => f.Normalized, 0.1, 0.9)
                  .OrderBy(f => f.PeriodId)
                  .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 2 || res[0].PeriodId != 8 || res[1].PeriodId != 11)
            {
                throw new Exception("Assert failure");
            }

            res = db.Table <SomeData>()
                  .Select(f => new
            {
                PeriodId = f.PeriodId
            });

            if (res.Sum(f => f.PeriodId) != 39)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #22
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 2.3,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 3,
                Normalized = 4.5,
                PeriodId   = 15
            };
            db.Table <SomeData>().Save(d);


            try
            {
                var res = db.Table <SomeData>()
                          .Where(f => f.PeriodId == WhereData.A)
                          .Select(f => new
                {
                    PeriodId = f.PeriodId
                });
            }
            catch (Exception ex)
            {
                throw new Exception("Assert failure");
            }


            try
            {
                var wd  = new WhereData();
                var res = db.Table <SomeData>()
                          .Where(f => f.PeriodId == wd.B)
                          .Select(f => new
                {
                    PeriodId = f.PeriodId
                });
            }
            catch (Exception ex)
            {
                throw new Exception("Assert failure");
            }


#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #23
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif

            db.Queue <QueueA>().GetAllFromQueue();

            int    total      = 30000;
            int    read       = 0;
            object _read_lock = new object();
            Parallel.ForEach(Enumerable.Range(0, 15).ToList(), f => {
                Task.Run(() =>
                {
                    while (read < total)
                    {
                        try
                        {
                            var res = db.Queue <QueueA>().GetAllFromQueue();
                            if (res.Any() && res.First().SomeArray.Count() != 3)
                            {
                                throw new Exception("not match");
                            }
                            lock (_read_lock)
                            {
                                read += res.Count();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("A " + ex.Message);
                        }
                    }
                });
            });
            Parallel.ForEach(Enumerable.Range(0, total).ToList(), new ParallelOptions()
            {
                MaxDegreeOfParallelism = 5
            }, f =>
            {
                try
                {
                    var a = new QueueA()
                    {
                        SomeString = "test123",
                        SomeArray  = new List <int>()
                        {
                            1, 2, 3
                        }
                    };

                    db.Queue <QueueA>().PutToQueue(a);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });


            Thread.Sleep(5000);


            if (read != total)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
        }
예제 #24
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            for (int i = 1; i < 3100; i++)
            {
                var d = new SomeData()
                {
                    Id         = i,
                    Normalized = i,
                    PeriodId   = i,
                    NameSearch = "test " + i + " abc"
                };
                db.Table <SomeData>().Save(d);
            }


            var res = db.Table <SomeData>()
                      .Search(f => f.NameSearch, "test")
                      .OrderBy(f => f.Id)
                      .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != db.Table <SomeData>().Count())
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .Search(f => f.NameSearch, "test", 0, 1)
                  .OrderBy(f => f.Id)
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 999 && res.Any(f => f.Id >= 1000))
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .Search(f => f.NameSearch, "test", 1, 1)
                  .OrderBy(f => f.Id)
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1000 && res.Any(f => f.Id < 1000 || f.Id >= 2000))
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #25
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "Žtest123"
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 0.9,
                PeriodId   = 7,
                NameSearch = "Ūtest123"
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 3,
                Normalized = 0.5,
                PeriodId   = 10,
                NameSearch = "Ątest123"
            };
            db.Table <SomeData>().Save(d);;


            var res = db.Table <SomeData>()
                      .OrderBy(f => f.NameSearch)
                      .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 3 || res[0].PeriodId != 10 || res[1].PeriodId != 7 || res[2].PeriodId != 5)
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .OrderByDescending(f => f.NameSearch)
                  .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 3 || res[0].PeriodId != 5 || res[1].PeriodId != 7 || res[2].PeriodId != 10)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #26
0
        public void Do(Db db_)
        {
            bool dispose = true;

            //no such user
            try
            {
                var db = new Db("DATA", "reader_user_123", "re@der123");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                var res = db.Table <Testing.tables3.KaggleClass>().SelectEntity();
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("user doesn't exist"))
                {
                    throw new Exception("Assert failure");
                }
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }


            //bad password
            try
            {
                var db = new Db("DATA", "admin", "admina");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                var d = new SomeData()
                {
                    Id         = 1,
                    Normalized = 1.2,
                    PeriodId   = 5
                };
                db.Table <SomeData>().Save(d);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("insufficient permissions"))
                {
                    throw new Exception("Assert failure");
                }
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }


            //reader wants to write
            try
            {
                var db = new Db("DATA", "reader_user", "re@der123");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                var d = new SomeData()
                {
                    Id         = 1,
                    Normalized = 1.2,
                    PeriodId   = 5
                };
                db.Table <SomeData>().Save(d);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("insufficient permissions"))
                {
                    throw new Exception("Assert failure");
                }
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }

            //writer wants to write
            try
            {
                var db = new Db("DATA", "writer_user", "wr1ter123");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                var d = new SomeData()
                {
                    Id         = 1,
                    Normalized = 1.2,
                    PeriodId   = 5
                };
                db.Table <SomeData>().Save(d);
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }

            //reader wants to read
            try
            {
                var db = new Db("DATA", "reader_user", "re@der123");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                var count = db.Table <SomeData>().Count();
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }

            //writer wants to replicate
            try
            {
                var db = new Db("DATA", "writer_user", "wr1ter123");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                db.Replicate("DATA2");
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("insufficient permissions"))
                {
                    throw new Exception("Assert failure");
                }
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }


            //admin wants to replicate
            try
            {
                var db = new Db("DATA", "admin_user", "@admin123");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                if (Directory.Exists("DATA2"))
                {
                    Directory.Delete("DATA2", true);
                }
                db.Replicate("DATA2");
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }
            //admin wants to write
            try
            {
                var db = new Db("DATA", "admin_user", "@admin123");
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
                var d = new SomeData()
                {
                    Id         = 1,
                    Normalized = 1.2,
                    PeriodId   = 5
                };
                db.Table <SomeData>().Save(d);
            }
            finally
            {
                if (dispose)
                {
                    Logic.Dispose();
                }
            }


            //reader wants to modify table
            //try
            //{
            //    var db = new Db("DATA", "reader_user", "re@der123");
            //    db._db_internal.CallServer = (byte[] f) => { return SocketTesting.CallServer(f); };
            //    var res = db.Table<Testing.tables3.SomeData>().SelectEntity();
            //    throw new Exception("Assert failure");
            //}
            //catch (Exception ex)
            //{
            //    if (!ex.Message.Contains("insufficient permissions"))
            //    {
            //        throw new Exception("Assert failure");
            //    }
            //}
            //finally
            //{
            //    if(dispose) { Logic.Dispose(); }
            //}

            //reader wants to create new type
            //try
            //{
            //    var db = new Db("DATA", "reader_user", "re@der123");
            //    db._db_internal.CallServer = (byte[] f) => { return SocketTesting.CallServer(f); };
            //    var res = db.Table<Testing.tables3.KaggleClass>().SelectEntity();
            //    throw new Exception("Assert failure");
            //}
            //catch (Exception ex)
            //{
            //    if (!ex.Message.Contains("insufficient permissions"))
            //    {
            //        throw new Exception("Assert failure");
            //    }
            //}
            //finally
            //{
            //    if(dispose) { Logic.Dispose(); }
            //}

            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
            Directory.Delete("DATA2", true);
        }
예제 #27
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <LogEntry>().Delete(new HashSet <int>(db.Table <LogEntry>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var d = new LogEntry()
            {
                Id         = 1,
                DataSearch = @"var list ="
            };
            db.Table <LogEntry>().Save(d);

            var list = new List <LogEntry>();
            var le1  = new LogEntry()
            {
                Id         = 1,
                DataSearch = @"template >"
            };
            list.Add(le1);
            var le2 = new LogEntry()
            {
                Id         = 2,
                DataSearch = @"var list ="
            };
            list.Add(le2);
            db.Table <LogEntry>().SaveBatch(list);

            var res = db.Table <LogEntry>()
                      .Search(f => f.DataSearch, "var list =")
                      .Select(f => new
            {
                f.Id,
                f.DataSearch
            });
            if (res.Count() != 1)
            {
                throw new Exception("Assert failure");
            }



#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #28
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            using (var trans = new LinqdbTransaction())
            {
                db.Table <BinaryData>(trans).Delete(new HashSet <int>(db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
                db.Table <SomeData>(trans).Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
                trans.Commit();
            }
#endif
            var job1 = new TransParallelWorkload();
            var job2 = new TransParallelWorkload2();



            var t1 = Task.Run(() =>
            {
                try
                {
                    job1.Do2(db);
                }
                catch (Exception e)
                {
                    TransParallelWorkload3.errors++;
                }
            });

            var t2 = Task.Run(() =>
            {
                try
                {
                    job2.Do2(db);
                }
                catch (Exception e)
                {
                    TransParallelWorkload3.errors++;
                }
            });


            t1.Wait();
            t2.Wait();


            if (TransParallelWorkload3.errors > 0)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #29
0
파일: GroupWhere.cs 프로젝트: ren85/linqdb
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                GroupBy    = 5,
                NameSearch = "a"
            };
            db.Table <SomeData>().Save(d);

            d = new SomeData()
            {
                Id         = 2,
                Normalized = 7,
                GroupBy    = 3,
                NameSearch = "a"
            };
            db.Table <SomeData>().Save(d);

            db.Table <SomeData>().CreateGroupByMemoryIndex(f => f.GroupBy, z => z.Normalized);

            d = new SomeData()
            {
                Id         = 3,
                Normalized = 2.3,
                GroupBy    = 10,
                NameSearch = "a"
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 4,
                Normalized = 4.5,
                GroupBy    = 10,
                NameSearch = "b"
            };
            db.Table <SomeData>().Save(d);


            var res = db.Table <SomeData>()
                      .Where(f => f.Normalized > 3)
                      .GroupBy(f => f.GroupBy)
                      .Select(f => new
            {
                Key   = f.Key,
                Sum   = f.Sum(z => z.Normalized),
                Total = f.Count()
            })
                      .ToList();

            if (res.Count() != 2 || res.Where(f => f.Key == 3).First().Total != 1 || res.Where(f => f.Key == 10).First().Total != 1 ||
                res.Where(f => f.Key == 3).First().Sum != 7 || res.Where(f => f.Key == 10).First().Sum != 4.5)
            {
                throw new Exception("Assert failure");
            }

            db.Table <SomeData>().RemoveGroupByMemoryIndex(f => f.GroupBy, z => z.Normalized);

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
예제 #30
0
파일: Or2.cs 프로젝트: ren85/linqdb
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <UsersItem>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new UsersItem()
            {
                Id            = 1,
                TitleSearch   = "read web",
                CodeSearch    = "read web",
                RegexSearch   = "read web",
                ReplaceSearch = "read web",
                UserId        = 20
            };
            db.Table <UsersItem>().Save(d);
            d = new UsersItem()
            {
                Id            = 2,
                TitleSearch   = "read web",
                CodeSearch    = "read web",
                RegexSearch   = "read web",
                ReplaceSearch = "read web",
                UserId        = 4975
            };
            db.Table <UsersItem>().Save(d);


            var res = db.Table <UsersItem>().Where(f => f.UserId == 20)
                      .Search(f => f.TitleSearch, "read").Or().Search(f => f.CodeSearch, "read").Or().Search(f => f.RegexSearch, "read").Or().Search(f => f.ReplaceSearch, "read")
                      .Search(f => f.TitleSearch, "web").Or().Search(f => f.CodeSearch, "web").Or().Search(f => f.RegexSearch, "web").Or().Search(f => f.ReplaceSearch, "web")
                      .SelectEntity();
            if (res.Count() != 1 || res[0].Id != 1)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }